Redone UI, add leave and delete logic

This commit is contained in:
Ayushya Amitabh
2020-04-16 01:28:29 -04:00
parent 24b2c6a4e0
commit 1acbca3bf0
15 changed files with 1197 additions and 1968 deletions
+64
View File
@@ -0,0 +1,64 @@
import firebase from 'firebase/app';
import 'firebase/auth';
const API_HOST = window.location.href.startsWith('http://localhost')
? 'http://localhost:5001/watch-party-crx/us-central1/widgets'
: 'https://us-central1-watch-party-crx.cloudfunctions.net/widgets';
export const isAuthed = () => true && firebase.auth().currentUser;
export const doAuth = () => firebase.auth().signInAnonymously();
export const fetcher = async ({ ENDPOINT, METHOD, ...args }) => {
const idToken = await firebase.auth().currentUser.getIdToken();
return fetch(`${API_HOST}/${ENDPOINT}`, {
method: METHOD,
headers: {
Authorization: `Token ${idToken}:${firebase.auth().currentUser.uid}`,
},
...args,
});
};
export const CreateRoomApi = async (data) => {
if (!isAuthed()) await doAuth();
return fetcher({
ENDPOINT: 'create',
METHOD: 'POST',
body: JSON.stringify(data),
});
};
export const JoinRoomApi = async (data) => {
if (!isAuthed()) await doAuth();
return fetcher({
ENDPOINT: 'join',
METHOD: 'POST',
body: JSON.stringify(data),
});
};
export const SendMessageApi = async (data) => {
if (!isAuthed()) await doAuth();
return fetcher({
ENDPOINT: 'message',
METHOD: 'post',
body: JSON.stringify(data),
});
};
export const LeaveRoomApi = async (data) => {
if (!isAuthed()) await doAuth();
return fetcher({
ENDPOINT: `leave/${data.roomId}/users/${data.uid}`,
METHOD: 'DELETE',
});
};
export const DeleteRoomApi = async (data) => {
if (!isAuthed()) await doAuth();
return fetcher({
ENDPOINT: `delete/${data.roomId}`,
METHOD: 'DELETE',
});
};