-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
393e5bc
feat(weeks/page.tsx): updates to datastore.ts to attempt to get curre…
ryandotfurrer af1912a
feat: update week card to show breadcrumb using league name
chris-nowicki de0ec33
feat(Week.tsx): fix styling on breadcrumb link that chris helped with…
ryandotfurrer 068aad8
feat(WeekTeams.tsx): added matchup date and finished breadcrumb link …
ryandotfurrer 0ffdec6
feat(Week.tsx): added every game time above the pick
ryandotfurrer 6021a54
feat(WeekTeams.tsx): fixed spacing between mapped items in weekteams …
ryandotfurrer 1995b8c
feat(WeeklyPickButton.tsx): made weeklypickbutton component a type of…
ryandotfurrer 31b1a58
Merge branch 'develop' into ryan/ux-update-weeks-page-to-match-design
ryandotfurrer 7c086e9
feat(Week.tsx-and-WeekTeams.tsx): Update flow of week and weekteam pa…
ryandotfurrer 37e9f5a
Fixing PR comments
shashilo ab7cfea
Fixing build issues. Adjusting save logic to append new entry object.
shashilo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -2,8 +2,7 @@ | |
// Licensed under the MIT License. | ||
|
||
'use client'; | ||
import React, { JSX, useEffect, useState } from 'react'; | ||
import { Button } from '@/components/Button/Button'; | ||
import React, { ChangeEvent, JSX, useEffect, useState } from 'react'; | ||
import { | ||
FormField, | ||
FormItem, | ||
|
@@ -18,6 +17,10 @@ import { parseUserPick } from '@/utils/utils'; | |
import { zodResolver } from '@hookform/resolvers/zod'; | ||
import { useDataStore } from '@/store/dataStore'; | ||
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'; | ||
import WeekTeams from './WeekTeams'; | ||
|
||
/** | ||
|
@@ -28,12 +31,22 @@ import WeekTeams from './WeekTeams'; | |
// eslint-disable-next-line no-unused-vars | ||
const Week = ({ entry, 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[] | ||
|
@@ -73,20 +86,28 @@ const Week = ({ entry, league, NFLTeams, week }: IWeekProps): JSX.Element => { | |
* @param data - The form data. | ||
* @returns {void} | ||
*/ | ||
const onSubmit = async (data: z.infer<typeof FormSchema>): Promise<void> => { | ||
const onWeeklyPickChange = async ( | ||
data: ChangeEvent<HTMLInputElement>, | ||
): Promise<void> => { | ||
try { | ||
const teamSelect = data.type.toLowerCase(); | ||
const teamSelect = data.target.value; | ||
const teamID = NFLTeams.find( | ||
(team) => team.teamName.toLowerCase() === teamSelect, | ||
)?.teamId; | ||
(team) => team.teamName === teamSelect, | ||
)?.teamName; | ||
|
||
const currentUserPick = parseUserPick(user.id, entry, teamID || ''); | ||
|
||
// combines current picks and the user pick into one object. | ||
// if the user pick exists then it overrides the pick of the user. | ||
const updatedWeeklyPicks = { | ||
...weeklyPicks.userResults, | ||
...currentUserPick, | ||
[user.id]: { | ||
...weeklyPicks.userResults[user.id], | ||
[entry]: { | ||
...weeklyPicks.userResults[user.id]?.[entry], | ||
...currentUserPick[user.id][entry], | ||
}, | ||
}, | ||
}; | ||
|
||
// update weekly picks in the database | ||
|
@@ -110,44 +131,59 @@ const Week = ({ entry, league, NFLTeams, week }: IWeekProps): JSX.Element => { | |
}; | ||
|
||
useEffect(() => { | ||
if (!selectedLeague) { | ||
getSelectedLeague(); | ||
return; | ||
} | ||
getSchedule(week); | ||
}, [week]); | ||
setIsLoading(false); | ||
}, [week, selectedLeague]); | ||
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. By adding |
||
|
||
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 className="league-entry-week"> | ||
<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/${league}/entry/all`} | ||
> | ||
<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"> | ||
<FormField | ||
control={form.control as Control<object>} | ||
name="type" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormControl> | ||
<WeekTeams | ||
schedule={schedule} | ||
field={field} | ||
userPick={userPick} | ||
onWeeklyPickChange={onWeeklyPickChange} | ||
/> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
</form> | ||
</FormProvider> | ||
</section> | ||
</div> | ||
); | ||
}; | ||
|
||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: We'll need to look into Suspense in the near future.