- Implement user state tracking and broadcasting on connect/disconnect and phase changes - Add bid start and place rejection handling with error messages to frontend and backend - Enhance movie serializer with TMDB integration and update relevant frontend components
65 lines
1.6 KiB
JavaScript
65 lines
1.6 KiB
JavaScript
import { DraftMessage } from "./constants";
|
|
|
|
export async function fetchDraftDetails(draftSessionId) {
|
|
return fetch(`/api/draft/${draftSessionId}/`)
|
|
.then((response) => {
|
|
if (response.ok) {
|
|
return response.json();
|
|
} else {
|
|
throw new Error();
|
|
}
|
|
})
|
|
.catch((err) => {
|
|
console.error("Error fetching draft details", err);
|
|
});
|
|
}
|
|
|
|
export async function fetchMovieDetails(draftSessionId) {
|
|
return fetch(`/api/draft/${draftSessionId}/movie/`)
|
|
.then((response) => {
|
|
if (response.ok) {
|
|
return response.json();
|
|
} else {
|
|
throw new Error();
|
|
}
|
|
})
|
|
.catch((err) => {
|
|
console.error("Error fetching draft details", err);
|
|
});
|
|
}
|
|
|
|
export function isEmptyObject(obj) {
|
|
return (
|
|
obj == null || (Object.keys(obj).length === 0 && obj.constructor === Object)
|
|
);
|
|
}
|
|
|
|
export const handleDraftStatusMessages = (event, setDraftState) => {
|
|
const message = JSON.parse(event.data);
|
|
const { type, payload } = message;
|
|
|
|
if (!payload) return;
|
|
|
|
if (type == DraftMessage.DRAFT_STATUS_INFORM) {
|
|
setDraftState(payload);
|
|
}
|
|
};
|
|
|
|
export const handleUserIdentifyMessages = (event, setUser) => {
|
|
const message = JSON.parse(event.data);
|
|
const { type, payload } = message;
|
|
|
|
if (type == DraftMessage.USER_IDENTIFICATION_INFORM) {
|
|
const { user } = payload;
|
|
setUser(user);
|
|
}
|
|
};
|
|
|
|
export const handleUserStatusMessages = (event, setUserStatus) => {
|
|
const message = JSON.parse(event.data);
|
|
const { type, payload } = message;
|
|
|
|
if (type == DraftMessage.USER_STATE_INFORM) {
|
|
setUserStatus(payload);
|
|
}
|
|
}; |