diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 387d9a93..f277c59a 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,11 +1,10 @@ import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'; import { ThemeProvider } from 'styled-components'; import { theme } from './styles/theme'; -import { MainPage, ClientPage, HostPage } from './pages'; +import { ClientPage, ErrorPage, HostPage, MainPage, ReplayPage } from './pages'; import { QueryClientProvider } from '@tanstack/react-query'; import { queryClient } from '@apis/index'; import withUserId from '@hocs/withUserId'; -import ReplayPage from '@pages/ReplayPage'; function AppComponent() { return ( @@ -19,12 +18,10 @@ function AppComponent() { > } /> - } /> } /> - } /> } /> } /> - } /> + } /> diff --git a/frontend/src/apis/checkLiveExist.ts b/frontend/src/apis/checkLiveExist.ts new file mode 100644 index 00000000..99de0460 --- /dev/null +++ b/frontend/src/apis/checkLiveExist.ts @@ -0,0 +1,13 @@ +import { AxiosResponse } from 'axios'; +import { fetchInstance } from '.'; +import { LiveExistenceResponse } from '@type/live'; + +export const checkLiveExist = async ({ liveId }: { liveId: string }): Promise => { + const response: AxiosResponse = await fetchInstance().get('/streams/existence', { + params: { + sessionKey: liveId + } + }); + + return response.data; +}; diff --git a/frontend/src/apis/checkReplayExist.ts b/frontend/src/apis/checkReplayExist.ts new file mode 100644 index 00000000..ffcac144 --- /dev/null +++ b/frontend/src/apis/checkReplayExist.ts @@ -0,0 +1,13 @@ +import { AxiosResponse } from 'axios'; +import { fetchInstance } from '.'; +import { ReplayExistenceResponse } from '@type/replay'; + +export const checkReplayExist = async ({ videoId }: { videoId: string }): Promise => { + const response: AxiosResponse = await fetchInstance().get('/replay/existence', { + params: { + videoId + } + }); + + return response.data; +}; diff --git a/frontend/src/apis/fetchLive.ts b/frontend/src/apis/fetchLive.ts index f1ff0807..102c5501 100644 --- a/frontend/src/apis/fetchLive.ts +++ b/frontend/src/apis/fetchLive.ts @@ -1,17 +1,18 @@ import { AxiosResponse } from 'axios'; import { fetchInstance } from '.'; -import { ClientLive } from '@type/live'; +import { ClientLiveResponse } from '@type/live'; -type ClientLiveResponse = { - info: ClientLive; -}; - -export const fetchLive = async ({ liveId }: { liveId: string }): Promise => { - const response: AxiosResponse = await fetchInstance().get('/streams/live', { - params: { - liveId +export const fetchLive = async ({ liveId }: { liveId: string }): Promise => { + try { + const response: AxiosResponse = await fetchInstance().get('/streams/live', { + params: { liveId } + }); + return response.data; + } catch (error: any) { + if (error.response && error.response.status === 400) { + console.log('error', error); + throw error; } - }); - - return response.data.info; + throw error; + } }; diff --git a/frontend/src/apis/fetchReplay.ts b/frontend/src/apis/fetchReplay.ts index 834518af..01c80742 100644 --- a/frontend/src/apis/fetchReplay.ts +++ b/frontend/src/apis/fetchReplay.ts @@ -1,17 +1,20 @@ import { AxiosResponse } from 'axios'; import { fetchInstance } from '.'; -import { ReplayStream } from '@type/replay'; +import { ClientReplayResponse } from '@type/replay'; -type ReplayStreamResponse = { - info: ReplayStream; -}; - -export const fetchReplay = async ({ videoId }: { videoId: string }): Promise => { - const response: AxiosResponse = await fetchInstance().get('/replay/video', { - params: { - videoId +export const fetchReplay = async ({ videoId }: { videoId: string }): Promise => { + try { + const response: AxiosResponse = await fetchInstance().get('/replay/video', { + params: { + videoId + } + }); + return response.data; + } catch (error: any) { + if (error.response && error.response.status === 400) { + console.log('error', error); + throw error; } - }); - - return response.data.info; + throw error; + } }; diff --git a/frontend/src/apis/queries/client/useCheckLiveExist.ts b/frontend/src/apis/queries/client/useCheckLiveExist.ts new file mode 100644 index 00000000..75048221 --- /dev/null +++ b/frontend/src/apis/queries/client/useCheckLiveExist.ts @@ -0,0 +1,13 @@ +import { useQuery } from '@tanstack/react-query'; + +import { checkLiveExist } from '@apis/checkLiveExist'; +import { LiveExistenceResponse } from '@type/live'; + +export const useCheckLiveExist = ({ liveId }: { liveId: string }) => { + return useQuery({ + queryKey: ['checkLiveExist'], + queryFn: () => checkLiveExist({ liveId }), + refetchOnWindowFocus: false, + initialData: { existed: true } + }); +}; diff --git a/frontend/src/apis/queries/client/useFetchLive.ts b/frontend/src/apis/queries/client/useFetchLive.ts index a5c7a4e4..38e22ab4 100644 --- a/frontend/src/apis/queries/client/useFetchLive.ts +++ b/frontend/src/apis/queries/client/useFetchLive.ts @@ -1,12 +1,14 @@ import { useQuery } from '@tanstack/react-query'; - import { fetchLive } from '@apis/fetchLive'; -import { ClientLive } from '@type/live'; +import { ClientLive, ClientLiveResponse } from '@type/live'; export const useClientLive = ({ liveId }: { liveId: string }) => { - return useQuery({ + return useQuery({ queryKey: ['clientLive'], - queryFn: () => fetchLive({ liveId: liveId }), - refetchOnWindowFocus: false + queryFn: () => fetchLive({ liveId }), + refetchOnWindowFocus: false, + initialData: { info: {} as ClientLive }, + throwOnError: true, + retry: 0, }); }; diff --git a/frontend/src/apis/queries/replay/useCheckReplayExist.ts b/frontend/src/apis/queries/replay/useCheckReplayExist.ts new file mode 100644 index 00000000..12a03e5e --- /dev/null +++ b/frontend/src/apis/queries/replay/useCheckReplayExist.ts @@ -0,0 +1,13 @@ +import { useQuery } from '@tanstack/react-query'; + +import { checkReplayExist } from '@apis/checkReplayExist'; +import { ReplayExistenceResponse } from '@type/replay'; + +export const useCheckReplayExist = ({ videoId }: { videoId: string }) => { + return useQuery({ + queryKey: ['checkReplayExist'], + queryFn: () => checkReplayExist({ videoId }), + refetchOnWindowFocus: false, + initialData: { existed: true } + }); +}; diff --git a/frontend/src/apis/queries/replay/useFetchReplay.ts b/frontend/src/apis/queries/replay/useFetchReplay.ts index 24d89d32..d84143a4 100644 --- a/frontend/src/apis/queries/replay/useFetchReplay.ts +++ b/frontend/src/apis/queries/replay/useFetchReplay.ts @@ -1,12 +1,15 @@ import { useQuery } from '@tanstack/react-query'; import { fetchReplay } from '@apis/fetchReplay'; -import { ReplayStream } from '@type/replay'; +import { ClientReplayResponse, ReplayStream } from '@type/replay'; export const useClientReplay = ({ videoId }: { videoId: string }) => { - return useQuery({ + return useQuery({ queryKey: ['clientReplay'], - queryFn: () => fetchReplay({ videoId: videoId }), - refetchOnWindowFocus: false + queryFn: () => fetchReplay({ videoId }), + refetchOnWindowFocus: false, + initialData: { info: {} as ReplayStream }, + throwOnError: true, + retry: 0 }); }; diff --git a/frontend/src/assets/icons/warning_icon.svg b/frontend/src/assets/icons/warning_icon.svg new file mode 100644 index 00000000..5ed19bd8 --- /dev/null +++ b/frontend/src/assets/icons/warning_icon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/frontend/src/components/client/Chat.tsx b/frontend/src/components/client/Chat.tsx deleted file mode 100644 index 3d950ddc..00000000 --- a/frontend/src/components/client/Chat.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import { useState } from 'react'; -import styled from 'styled-components'; - -const Chat = () => { - const [chatVisible, setChatVisible] = useState(true); - - const handleChatVisible = () => { - setChatVisible(!chatVisible); - }; - - return ( - <> - {chatVisible && ( - -

채팅

- -
- )} - - ); -}; - -export default Chat; - -const ChatContainer = styled.section` - min-width: 350px; - border: 1px solid red; - padding: 10px 20px; - background-color: ${({ theme }) => theme.tokenColors['color-white']}; -`; diff --git a/frontend/src/components/client/ClientView.tsx b/frontend/src/components/client/ClientView.tsx index 86f74a45..447eb84f 100644 --- a/frontend/src/components/client/ClientView.tsx +++ b/frontend/src/components/client/ClientView.tsx @@ -6,21 +6,22 @@ import PlayerInfo from './PlayerInfo'; import Footer from '@common/Footer'; import Header from '@common/Header'; import { useClientLive } from '@queries/client/useFetchLive'; +import { getLiveURL } from '@utils/getVideoURL'; const ClientView = () => { const { id: liveId } = useParams(); - const { data: clientLiveData } = useClientLive({ liveId: liveId as string }); + const { data: clientLiveData } = useClientLive({ + liveId: liveId as string + }); - if (!clientLiveData) { - return
로딩 중...
; - } + const { info } = clientLiveData; return (

클라이언트 페이지

- - + +