Skip to content

Commit ed7b0ee

Browse files
authored
Merge pull request #293 from boostcampwm-2024/dev-fe
[MERGE] dev-fe to dev
2 parents da5f390 + 9b4971f commit ed7b0ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1441
-610
lines changed

frontend/src/App.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
22
import { ThemeProvider } from 'styled-components';
33
import { theme } from './styles/theme';
4-
import { MainPage, ClientPage, HostPage } from './pages';
4+
import { ClientPage, ErrorPage, HostPage, MainPage, ReplayPage } from './pages';
55
import { QueryClientProvider } from '@tanstack/react-query';
66
import { queryClient } from '@apis/index';
77
import withUserId from '@hocs/withUserId';
8-
import ReplayPage from '@pages/ReplayPage';
98

109
function AppComponent() {
1110
return (
@@ -19,12 +18,10 @@ function AppComponent() {
1918
>
2019
<Routes>
2120
<Route path="/" element={<MainPage />} />
22-
<Route path="/live" element={<ClientPage />} />
2321
<Route path="/live/:id" element={<ClientPage />} />
24-
<Route path="/replay" element={<ReplayPage />} />
2522
<Route path="/replay/:id" element={<ReplayPage />} />
2623
<Route path="/host" element={<HostPage />} />
27-
<Route path="/host/:id" element={<HostPage />} />
24+
<Route path="*" element={<ErrorPage />} />
2825
</Routes>
2926
</Router>
3027
</ThemeProvider>

frontend/src/apis/checkLiveExist.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { AxiosResponse } from 'axios';
2+
import { fetchInstance } from '.';
3+
import { LiveExistenceResponse } from '@type/live';
4+
5+
export const checkLiveExist = async ({ liveId }: { liveId: string }): Promise<LiveExistenceResponse> => {
6+
const response: AxiosResponse<LiveExistenceResponse> = await fetchInstance().get('/streams/existence', {
7+
params: {
8+
sessionKey: liveId
9+
}
10+
});
11+
12+
return response.data;
13+
};

frontend/src/apis/checkReplayExist.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { AxiosResponse } from 'axios';
2+
import { fetchInstance } from '.';
3+
import { ReplayExistenceResponse } from '@type/replay';
4+
5+
export const checkReplayExist = async ({ videoId }: { videoId: string }): Promise<ReplayExistenceResponse> => {
6+
const response: AxiosResponse<ReplayExistenceResponse> = await fetchInstance().get('/replay/existence', {
7+
params: {
8+
videoId
9+
}
10+
});
11+
12+
return response.data;
13+
};

frontend/src/apis/fetchChatRule.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { AxiosResponse } from 'axios';
2+
import { fetchInstance } from '.';
3+
4+
export type ChatRuleResponse = {
5+
notice: string;
6+
channelName: string;
7+
};
8+
9+
export const fetchChatRule = async ({ sessionKey }: { sessionKey: string }): Promise<ChatRuleResponse> => {
10+
const response: AxiosResponse<ChatRuleResponse> = await fetchInstance().get('/streams/notice', {
11+
params: {
12+
sessionKey
13+
}
14+
});
15+
16+
return response.data;
17+
};

frontend/src/apis/fetchLive.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import { AxiosResponse } from 'axios';
22
import { fetchInstance } from '.';
3-
import { ClientLive } from '@type/live';
3+
import { ClientLiveResponse } from '@type/live';
44

5-
type ClientLiveResponse = {
6-
info: ClientLive;
7-
};
8-
9-
export const fetchLive = async ({ liveId }: { liveId: string }): Promise<ClientLive> => {
10-
const response: AxiosResponse<ClientLiveResponse> = await fetchInstance().get('/streams/live', {
11-
params: {
12-
liveId
5+
export const fetchLive = async ({ liveId }: { liveId: string }): Promise<ClientLiveResponse> => {
6+
try {
7+
const response: AxiosResponse = await fetchInstance().get('/streams/live', {
8+
params: { liveId }
9+
});
10+
return response.data;
11+
} catch (error: any) {
12+
if (error.response && error.response.status === 400) {
13+
console.log('error', error);
14+
throw error;
1315
}
14-
});
15-
16-
return response.data.info;
16+
throw error;
17+
}
1718
};

frontend/src/apis/fetchReplay.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import { AxiosResponse } from 'axios';
22
import { fetchInstance } from '.';
3-
import { ReplayStream } from '@type/replay';
3+
import { ClientReplayResponse } from '@type/replay';
44

5-
type ReplayStreamResponse = {
6-
info: ReplayStream;
7-
};
8-
9-
export const fetchReplay = async ({ videoId }: { videoId: string }): Promise<ReplayStream> => {
10-
const response: AxiosResponse<ReplayStreamResponse> = await fetchInstance().get('/replay/video', {
11-
params: {
12-
videoId
5+
export const fetchReplay = async ({ videoId }: { videoId: string }): Promise<ClientReplayResponse> => {
6+
try {
7+
const response: AxiosResponse = await fetchInstance().get('/replay/video', {
8+
params: {
9+
videoId
10+
}
11+
});
12+
return response.data;
13+
} catch (error: any) {
14+
if (error.response && error.response.status === 400) {
15+
console.log('error', error);
16+
throw error;
1317
}
14-
});
15-
16-
return response.data.info;
18+
throw error;
19+
}
1720
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { useQuery } from '@tanstack/react-query';
2+
import { ChatRuleResponse, fetchChatRule } from '@apis/fetchChatRule';
3+
4+
export const useFetchChatRule = ({ sessionKey }: { sessionKey: string }) => {
5+
return useQuery<ChatRuleResponse, Error>({
6+
queryKey: ['chatRule'],
7+
queryFn: () => fetchChatRule({ sessionKey }),
8+
refetchOnWindowFocus: false
9+
});
10+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { useQuery } from '@tanstack/react-query';
2+
3+
import { checkLiveExist } from '@apis/checkLiveExist';
4+
import { LiveExistenceResponse } from '@type/live';
5+
6+
export const useCheckLiveExist = ({ liveId }: { liveId: string }) => {
7+
return useQuery<LiveExistenceResponse, Error>({
8+
queryKey: ['checkLiveExist'],
9+
queryFn: () => checkLiveExist({ liveId }),
10+
refetchOnWindowFocus: false,
11+
initialData: { existed: true }
12+
});
13+
};
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { useQuery } from '@tanstack/react-query';
2-
32
import { fetchLive } from '@apis/fetchLive';
4-
import { ClientLive } from '@type/live';
3+
import { ClientLive, ClientLiveResponse } from '@type/live';
54

65
export const useClientLive = ({ liveId }: { liveId: string }) => {
7-
return useQuery<ClientLive, Error>({
6+
return useQuery<ClientLiveResponse, Error>({
87
queryKey: ['clientLive'],
9-
queryFn: () => fetchLive({ liveId: liveId }),
10-
refetchOnWindowFocus: false
8+
queryFn: () => fetchLive({ liveId }),
9+
refetchOnWindowFocus: false,
10+
initialData: { info: {} as ClientLive },
11+
throwOnError: true,
12+
retry: 0,
1113
});
1214
};

frontend/src/apis/queries/main/useFetchMainLive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ export const useMainLive = () => {
77
return useSuspenseQuery<MainLive[], Error>({
88
queryKey: ['mainLive'],
99
queryFn: fetchMainLive,
10-
refetchOnWindowFocus: false,
10+
refetchOnWindowFocus: false
1111
});
1212
};

0 commit comments

Comments
 (0)