-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from hufs-sports-live/feat/main-sports-categories
[FEAT] main sports categories 생성
- Loading branch information
Showing
9 changed files
with
167 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { SportsType } from '@/types/league'; | ||
|
||
type SportsListProps = { | ||
sportsList: SportsType[]; | ||
onClick: (key: string, value: string) => void; | ||
}; | ||
|
||
export default function SportsList({ sportsList, onClick }: SportsListProps) { | ||
return ( | ||
<ul className="mb-5 flex w-full items-center gap-5"> | ||
{sportsList.map(sports => ( | ||
<li | ||
key={sports.sportId} | ||
className="text-gary-5 cursor-pointer rounded-xl bg-gray-2" | ||
> | ||
<button | ||
onClick={() => onClick('sportsId', String(sports.sportId))} | ||
className="px-3 py-2" | ||
> | ||
{sports.name} | ||
</button> | ||
</li> | ||
))} | ||
</ul> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { usePathname, useRouter, useSearchParams } from 'next/navigation'; | ||
|
||
export default function useQueryParams() { | ||
const params = useSearchParams(); | ||
const pathname = usePathname(); | ||
const router = useRouter(); | ||
|
||
const appendToParams = (key: string, value: string) => { | ||
const newParams = new URLSearchParams(params.toString()); | ||
const targetParams = newParams.getAll(key); | ||
|
||
if (targetParams.includes(value)) { | ||
newParams.delete(key, value); | ||
} else { | ||
newParams.append(key, value); | ||
} | ||
router.push(`${pathname}?${newParams.toString()}`); | ||
}; | ||
|
||
const setInParams = (key: string, value: string) => { | ||
const newParams = new URLSearchParams(params.toString()); | ||
|
||
if (newParams.get(key) === value) return; | ||
|
||
newParams.set(key, value); | ||
router.push(`${pathname}?${newParams.toString()}`); | ||
}; | ||
|
||
return { params, appendToParams, setInParams }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { ReactNode } from 'react'; | ||
|
||
import { SportsType } from '@/types/league'; | ||
|
||
import useSportsListByLeagueId from './query'; | ||
|
||
type SportsListFetcherProps = { | ||
leagueId: string; | ||
children: (data: SportsType[]) => ReactNode; | ||
}; | ||
|
||
const DUMMY = [ | ||
{ | ||
sportId: 1, | ||
name: '축구', | ||
}, | ||
{ | ||
sportId: 3, | ||
name: '농구', | ||
}, | ||
{ | ||
sportId: 2, | ||
name: '롤', | ||
}, | ||
]; | ||
|
||
export default function SportsListFetcher({ | ||
leagueId, | ||
children, | ||
}: SportsListFetcherProps) { | ||
const { error } = useSportsListByLeagueId(leagueId); | ||
|
||
if (error) throw error; | ||
|
||
return children(DUMMY); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { useSuspenseQuery } from '@tanstack/react-query'; | ||
|
||
import { getSportsListByLeagueId } from '@/api/league'; | ||
|
||
export default function useSportsListByLeagueId(leagueId: string) { | ||
const { data, error } = useSuspenseQuery({ | ||
queryKey: ['sports-list', leagueId], | ||
queryFn: () => getSportsListByLeagueId(leagueId), | ||
}); | ||
|
||
return { | ||
sportsList: data, | ||
error, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export type LeagueType = { | ||
leagueId: number; | ||
name: string; | ||
}; | ||
|
||
export type SportsType = { | ||
name: string; | ||
sportId: number; | ||
}; |