-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ac3598
commit f7aa8cd
Showing
4 changed files
with
56 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use client'; | ||
|
||
import { getTrackWeeks } from '@/apis/trackWeek'; | ||
import { tracksWeekInfo } from '@/types/types'; | ||
import useStore from '@/zustand/store'; | ||
import { Select, SelectItem } from '@nextui-org/react'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import React, { useState } from 'react'; | ||
|
||
const WeekSelector = () => { | ||
const { setTrackWeek, selectedTrackWeek } = useStore((state) => state); | ||
|
||
const { selectedTrack } = useStore((state) => state); | ||
|
||
const { data, isLoading } = useQuery({ | ||
queryKey: ['allTrackWeeks'], | ||
queryFn: () => getTrackWeeks(selectedTrack?.trackId!), | ||
}); | ||
|
||
console.log(data); | ||
|
||
if (isLoading) { | ||
return <p>로딩중...</p>; | ||
} | ||
|
||
return ( | ||
<Select | ||
placeholder='주차선택' | ||
aria-label='week-selector' | ||
onChange={(e) => { | ||
console.log('여기', e.target.value); | ||
let targetName = e.target.value; | ||
const result = data.payload.find( | ||
(trackWeek: tracksWeekInfo) => trackWeek.weekName === targetName, | ||
); | ||
console.log(result); | ||
|
||
setTrackWeek(result); | ||
}} | ||
selectedKeys={[selectedTrackWeek!]} | ||
> | ||
{data.payload.map((trackWeek: tracksWeekInfo) => ( | ||
<SelectItem key={trackWeek.weekName}>{trackWeek.weekName}</SelectItem> | ||
))} | ||
</Select> | ||
); | ||
}; | ||
|
||
export default WeekSelector; |
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