diff --git a/src/api/api.ts b/src/api/api.ts index e468dd4b..1c84ab21 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -7,24 +7,29 @@ type TCreateProductionOptions = { lines: { name: string }[]; }; -type TCreateProductionResponse = { - productionid: string; +type TParticipant = { + name: string; + sessionid: string; + isActive: boolean; }; type TLine = { name: string; id: string; - smbid: string; - participants: { name: string; sessionid: string }[]; + smbconferenceid: string; + participants: TParticipant[]; }; -type TFetchProductionResponse = { +type TBasicProductionResponse = { name: string; productionid: string; +}; + +type TFetchProductionResponse = TBasicProductionResponse & { lines: TLine[]; }; -type TListProductionsResponse = TFetchProductionResponse[]; +type TListProductionsResponse = TBasicProductionResponse[]; type TOfferAudioSessionOptions = { productionId: number; @@ -44,10 +49,7 @@ type TPatchAudioSessionOptions = { sdpAnswer: string; }; -type TPatchAudioSessionResponse = { - sdp: string; - sessionid: string; -}; +type TPatchAudioSessionResponse = null; type TDeleteAudioSessionOptions = { productionId: number; @@ -57,7 +59,7 @@ type TDeleteAudioSessionOptions = { export const API = { createProduction: async ({ name, lines }: TCreateProductionOptions) => - handleFetchRequest( + handleFetchRequest( fetch(`${API_URL}production/`, { method: "POST", headers: { @@ -77,13 +79,14 @@ export const API = { handleFetchRequest( fetch(`${API_URL}productions/${id}`, { method: "GET" }) ), + // TODO apply handleFetchRequest deleteProduction: (id: number) => fetch(`${API_URL}productions/${id}`, { method: "DELETE" }).then( (response) => response.json() ), listProductionLines: (id: number) => - fetch(`${API_URL}productions/${id}/lines`, { method: "GET" }).then( - (response) => response.json() + handleFetchRequest( + fetch(`${API_URL}productions/${id}/lines`, { method: "GET" }) ), fetchProductionLine: (productionId: number, lineId: number): Promise => handleFetchRequest( diff --git a/src/api/handle-fetch-request.ts b/src/api/handle-fetch-request.ts index 986d830b..a9df575a 100644 --- a/src/api/handle-fetch-request.ts +++ b/src/api/handle-fetch-request.ts @@ -31,7 +31,9 @@ export const handleFetchRequest = async ( ); } - console.log("Request response:", text || json); + if (text || json) { + console.log("Request response:", text || json); + } return text || json; }; diff --git a/src/components/landing-page/productions-list.tsx b/src/components/landing-page/productions-list.tsx index 318076d4..024ae703 100644 --- a/src/components/landing-page/productions-list.tsx +++ b/src/components/landing-page/productions-list.tsx @@ -1,7 +1,7 @@ import styled from "@emotion/styled"; import { useEffect, useState } from "react"; import { API } from "../../api/api.ts"; -import { TProduction } from "../production-line/types.ts"; +import { TBasicProduction } from "../production-line/types.ts"; import { useGlobalState } from "../../global-state/context-provider.tsx"; import { LoaderDots } from "../loader/loader.tsx"; import { useRefreshAnimation } from "./use-refresh-animation.ts"; @@ -34,7 +34,7 @@ const ProductionId = styled.div` `; export const ProductionsList = () => { - const [productions, setProductions] = useState([]); + const [productions, setProductions] = useState([]); const [intervalLoad, setIntervalLoad] = useState(false); const [{ reloadProductionList }, dispatch] = useGlobalState(); @@ -57,13 +57,6 @@ export const ProductionsList = () => { return { name: prod.name, id: parseInt(prod.productionid, 10), - lines: prod.lines.map((l) => ({ - name: l.name, - id: parseInt(l.id, 10), - connected: false, - connectionId: "1", - participants: [], - })), }; }) ); diff --git a/src/components/production-line/types.ts b/src/components/production-line/types.ts index c0c0290e..ddbde4a2 100644 --- a/src/components/production-line/types.ts +++ b/src/components/production-line/types.ts @@ -20,8 +20,11 @@ export type TLine = { participants: TParticipant[]; }; -export type TProduction = { +export type TBasicProduction = { name: string; id: number; +}; + +export type TProduction = TBasicProduction & { lines: TLine[]; };