diff --git a/apps/client/src/pages/Home/FieldFilter.tsx b/apps/client/src/pages/Home/FieldFilter.tsx new file mode 100644 index 00000000..277897ae --- /dev/null +++ b/apps/client/src/pages/Home/FieldFilter.tsx @@ -0,0 +1,35 @@ +import { Button } from '@/components/ui/button'; +import { Field } from '@/types/liveTypes'; + +const fields: Field[] = ['WEB', 'AND', 'IOS']; + +interface FieldFilterProps { + selectedField: Field; + onFieldSelect: (field: Field) => void; +} + +function FieldFilter({ selectedField, onFieldSelect }: FieldFilterProps) { + const handleClick = (field: Field) => { + onFieldSelect(selectedField === field ? '' : field); + }; + + return ( +
+ {fields.map((field: Field) => ( + + ))} +
+ ); +} + +export default FieldFilter; diff --git a/apps/client/src/pages/Home/LiveList.tsx b/apps/client/src/pages/Home/LiveList.tsx index 9f54c3a4..0dcce48b 100644 --- a/apps/client/src/pages/Home/LiveList.tsx +++ b/apps/client/src/pages/Home/LiveList.tsx @@ -1,24 +1,54 @@ +import FieldFilter from './FieldFilter'; import LiveCard from './LiveCard'; import { LivePreviewInfo } from '@/types/homeTypes'; +import { useEffect, useState } from 'react'; +import { Field } from '@/types/liveTypes'; +import axiosInstance from '@/services/axios'; +import Search from './Search'; + +function LiveList() { + const [field, setField] = useState(''); + const [liveList, setLiveList] = useState([]); + + useEffect(() => { + axiosInstance.get('/v1/broadcasts', { params: { field: field } }).then(response => { + if (response.data.success) { + setLiveList(response.data.data.broadcasts); + } + }); + }, [field]); + + const handleSelectField = (selected: Field) => { + setField(selected); + }; -function LiveList({ liveList }: { liveList: LivePreviewInfo[] }) { return ( -
- {liveList && - liveList.map(livePreviewInfo => { - const { broadcastId, broadcastTitle, camperId, profileImage, thumbnail } = livePreviewInfo; - return ( -
- -
- ); - })} +
+
+ + +
+
+ {liveList ? ( + liveList.map(data => { + const { broadcastId, broadcastTitle, camperId, profileImage, thumbnail } = data; + console.log(data); + return ( +
+ +
+ ); + }) + ) : ( +
방송 정보가 없습니다.
+ )} +
); } diff --git a/apps/client/src/pages/Home/Search.tsx b/apps/client/src/pages/Home/Search.tsx new file mode 100644 index 00000000..852be20e --- /dev/null +++ b/apps/client/src/pages/Home/Search.tsx @@ -0,0 +1,5 @@ +function Search() { + return
; +} + +export default Search; diff --git a/apps/client/src/pages/Home/index.tsx b/apps/client/src/pages/Home/index.tsx index 3e138532..8bd89c4e 100644 --- a/apps/client/src/pages/Home/index.tsx +++ b/apps/client/src/pages/Home/index.tsx @@ -1,37 +1,9 @@ import LiveList from '@pages/Home/LiveList'; -import LoadingCharacter from '@components/LoadingCharacter'; -import ErrorCharacter from '@components/ErrorCharacter'; -import { useAPI } from '@hooks/useAPI'; -import { LivePreviewListInfo } from '@/types/homeTypes'; -import { useEffect, useState } from 'react'; export default function Home() { - const { data: liveListInfo, isLoading, error } = useAPI({ url: '/v1/broadcasts' }); - const [showLoading, setShowLoading] = useState(false); - - useEffect(() => { - const timer = setTimeout(() => { - setShowLoading(true); - }, 250); - - return () => clearTimeout(timer); - }); - return (
- {error ? ( -
- -
- ) : isLoading && showLoading ? ( -
- -
- ) : liveListInfo?.broadcasts && liveListInfo.broadcasts.length > 0 ? ( - - ) : ( -
방송 중인 캠퍼가 없습니다.
- )} +
); } diff --git a/apps/client/src/types/liveTypes.ts b/apps/client/src/types/liveTypes.ts index 8352e369..4ae44e92 100644 --- a/apps/client/src/types/liveTypes.ts +++ b/apps/client/src/types/liveTypes.ts @@ -9,7 +9,9 @@ export interface LiveInfo { title: string; camperId: string; viewers: number; - field: 'WEB' | 'AND' | 'IOS'; + field: Field; profileImage: string; contacts: ContactInfo; } + +export type Field = 'WEB' | 'AND' | 'IOS' | '';