From b25ab722a3bdb63334ab60d251a28b679b136003 Mon Sep 17 00:00:00 2001 From: Martin <901824+martinstark@users.noreply.github.com> Date: Mon, 15 Apr 2024 10:56:07 +0200 Subject: [PATCH] feat: update api response types --- src/api/api.ts | 29 ++++++++++--------- .../landing-page/productions-list.tsx | 11 ++----- src/components/production-line/types.ts | 5 +++- 3 files changed, 22 insertions(+), 23 deletions(-) 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/components/landing-page/productions-list.tsx b/src/components/landing-page/productions-list.tsx index 24e704db..03c4d7fa 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(); const [doInitialLoad, setDoInitialLoad] = useState(true); @@ -59,13 +59,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[]; };