Handle centralized app state and registration + chat history

This commit is contained in:
Gabe Kangas
2022-05-02 17:45:22 -07:00
parent b590e4f765
commit a0354d6d49
11 changed files with 257 additions and 45 deletions

View File

@@ -1,4 +1,5 @@
import { ChatMessage } from '../interfaces/chat-message.model';
import { getUnauthedData } from '../utils/apis';
const ENDPOINT = `http://localhost:8080/api/chat`;
const URL_CHAT_REGISTRATION = `http://localhost:8080/api/chat/register`;
@@ -10,9 +11,8 @@ interface UserRegistrationResponse {
class ChatService {
public static async getChatHistory(accessToken: string): Promise<ChatMessage[]> {
const response = await fetch(`${ENDPOINT}?accessToken=${accessToken}`);
const status = await response.json();
return status;
const response = await getUnauthedData(`${ENDPOINT}?accessToken=${accessToken}`);
return response;
}
public static async registerUser(username: string): Promise<UserRegistrationResponse> {
@@ -24,15 +24,8 @@ class ChatService {
body: JSON.stringify({ displayName: username }),
};
try {
const response = await fetch(URL_CHAT_REGISTRATION, options);
const result = await response.json();
return result;
} catch (e) {
console.error(e);
}
return null;
const response = await getUnauthedData(URL_CHAT_REGISTRATION, options);
return response;
}
}