Skip to content

Commit

Permalink
feat: update api response types
Browse files Browse the repository at this point in the history
  • Loading branch information
martinstark committed Apr 15, 2024
1 parent b0c5dbd commit 31df785
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
29 changes: 16 additions & 13 deletions src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,10 +49,7 @@ type TPatchAudioSessionOptions = {
sdpAnswer: string;
};

type TPatchAudioSessionResponse = {
sdp: string;
sessionid: string;
};
type TPatchAudioSessionResponse = null;

type TDeleteAudioSessionOptions = {
productionId: number;
Expand All @@ -57,7 +59,7 @@ type TDeleteAudioSessionOptions = {

export const API = {
createProduction: async ({ name, lines }: TCreateProductionOptions) =>
handleFetchRequest<TCreateProductionResponse>(
handleFetchRequest<TBasicProductionResponse>(
fetch(`${API_URL}production/`, {
method: "POST",
headers: {
Expand All @@ -77,13 +79,14 @@ export const API = {
handleFetchRequest<TFetchProductionResponse>(
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<TLine[]>(
fetch(`${API_URL}productions/${id}/lines`, { method: "GET" })
),
fetchProductionLine: (productionId: number, lineId: number): Promise<TLine> =>
handleFetchRequest<TLine>(
Expand Down
11 changes: 2 additions & 9 deletions src/components/landing-page/productions-list.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -34,7 +34,7 @@ const ProductionId = styled.div`
`;

export const ProductionsList = () => {
const [productions, setProductions] = useState<TProduction[]>([]);
const [productions, setProductions] = useState<TBasicProduction[]>([]);
const [intervalLoad, setIntervalLoad] = useState<boolean>(false);
const [{ reloadProductionList }, dispatch] = useGlobalState();

Expand All @@ -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: [],
})),
};
})
);
Expand Down
5 changes: 4 additions & 1 deletion src/components/production-line/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
};

0 comments on commit 31df785

Please sign in to comment.