-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ui/ux: update week page #370
Changes from 7 commits
393e5bc
af1912a
de0ec33
068aad8
0ffdec6
6021a54
1995b8c
31b1a58
7c086e9
37e9f5a
ab7cfea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
|
||
'use client'; | ||
import React, { JSX, useEffect, useState } from 'react'; | ||
import { Button } from '@/components/Button/Button'; | ||
import { | ||
FormField, | ||
FormItem, | ||
|
@@ -19,6 +18,10 @@ import { zodResolver } from '@hookform/resolvers/zod'; | |
import { useDataStore } from '@/store/dataStore'; | ||
import WeekTeams from './WeekTeams'; | ||
import { ISchedule } from './WeekTeams.interface'; | ||
import LinkCustom from '@/components/LinkCustom/LinkCustom'; | ||
import { ChevronLeft } from 'lucide-react'; | ||
import { getCurrentLeague } from '@/api/apiFunctions'; | ||
import { ILeague } from '@/api/apiFunctions.interface'; | ||
|
||
/** | ||
* Renders the weekly picks page. | ||
|
@@ -28,12 +31,22 @@ import { ISchedule } from './WeekTeams.interface'; | |
// eslint-disable-next-line no-unused-vars | ||
const Week = ({ league, NFLTeams, week }: IWeekProps): JSX.Element => { | ||
const [schedule, setSchedule] = useState<ISchedule[]>([]); | ||
const [selectedLeague, setSelectedLeague] = useState<ILeague | undefined>(); | ||
const [isLoading, setIsLoading] = useState<boolean>(true); | ||
const [userPick, setUserPick] = useState<string>(''); | ||
|
||
const { user, updateWeeklyPicks, weeklyPicks } = useDataStore( | ||
(state) => state, | ||
); | ||
|
||
/** | ||
* Fetches the selected league. | ||
* @returns {Promise<void>} | ||
*/ | ||
const getSelectedLeague = async (): Promise<void> => { | ||
const res = await getCurrentLeague(league); | ||
setSelectedLeague(res); | ||
}; | ||
|
||
const NFLTeamsList = NFLTeams.map((team) => team.teamName) as [ | ||
string, | ||
...string[] | ||
|
@@ -110,44 +123,61 @@ const Week = ({ league, NFLTeams, week }: IWeekProps): JSX.Element => { | |
}; | ||
|
||
useEffect(() => { | ||
if (!selectedLeague) { | ||
getSelectedLeague(); | ||
return; | ||
} | ||
getSchedule(week); | ||
}, [week]); | ||
setIsLoading(false); | ||
}, [week, selectedLeague]); | ||
|
||
if (schedule.length === 0) { | ||
if (schedule.length === 0 || isLoading) { | ||
return <p>Loading...</p>; | ||
} | ||
|
||
return ( | ||
<section className="w-full pt-8" data-testid="weekly-picks"> | ||
<h1 className="pb-8 text-center text-[2rem] font-bold text-white"> | ||
Your pick sheet | ||
</h1> | ||
|
||
<FormProvider {...form}> | ||
<form | ||
className="mx-auto flex w-[90%] max-w-3xl flex-col items-center gap-8" | ||
onSubmit={form.handleSubmit(onSubmit)} | ||
<div> | ||
<nav className="py-6 text-orange-500 hover:no-underline"> | ||
<LinkCustom | ||
className="text-orange-500 flex gap-3 items-center font-semibold text-xl hover:no-underline" | ||
href="/league/all" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC it did in my testing, but now you're making me question myself! I'll confirm tomorrow (7/9/24) and report back. |
||
> | ||
<FormField | ||
control={form.control as Control<object>} | ||
name="type" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormControl> | ||
<WeekTeams | ||
schedule={schedule} | ||
field={field} | ||
userPick={userPick} | ||
/> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<Button label="Submit Button" type="submit" /> | ||
</form> | ||
</FormProvider> | ||
</section> | ||
<span aria-hidden="true"> | ||
<ChevronLeft size={16} /> | ||
</span> | ||
{selectedLeague?.leagueName as string} | ||
</LinkCustom> | ||
</nav> | ||
<section className="w-full pt-8" data-testid="weekly-picks"> | ||
<h1 className="pb-8 text-center text-[2rem] font-bold text-white"> | ||
Week {week} pick | ||
</h1> | ||
|
||
<FormProvider {...form}> | ||
<form | ||
className="mx-auto flex w-[90%] max-w-3xl flex-col items-center" | ||
onSubmit={form.handleSubmit(onSubmit)} | ||
> | ||
<FormField | ||
control={form.control as Control<object>} | ||
name="type" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormControl> | ||
<WeekTeams | ||
schedule={schedule} | ||
field={field} | ||
userPick={userPick} | ||
/> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
</form> | ||
</FormProvider> | ||
</section> | ||
</div> | ||
); | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the state be initialized to string? i.e.:
const [selectedLeague, setSelectedLeague] = useState<string>('');
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm gonna leave this to @chris-nowicki, since he helped me with this by implementing it Though, initializing it to a string makes sense to me!