Skip to content
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

Corina/644 fix a11y picks page #656

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
ebedd5a
fix(644): add focus outline to radio button
CorinaMurg Nov 8, 2024
29b2ea9
fix(644): create a radio group for each game
CorinaMurg Nov 8, 2024
2514642
fix(644): add focus outline offset to radio button
CorinaMurg Nov 8, 2024
2d00061
fix(644): correct the htmlFor value for radio buttons
CorinaMurg Nov 8, 2024
b7f829e
fix(644): reverse teams order in radio group
CorinaMurg Nov 11, 2024
ffa5e18
Merge branch 'develop' into corina/644-fix-a11y-picks-page
CorinaMurg Nov 11, 2024
25803e7
fix(644): remove direction ltr from radio group div container
CorinaMurg Nov 11, 2024
8887e09
fix(644): add focus outline with focus-visible, remove focus-within
CorinaMurg Nov 12, 2024
affca69
fix(644): move focus related classes to Label component
CorinaMurg Nov 12, 2024
7c77bf2
fix(644): add sr only label to current week pick logo
CorinaMurg Nov 12, 2024
1110acf
fix(644): import INFLTeam in Week module
CorinaMurg Nov 12, 2024
79e5934
fix(644): remove unused code
CorinaMurg Nov 13, 2024
af76040
fix(644): add direction ltr to radio group div
CorinaMurg Nov 13, 2024
75b0d4f
fix(644): remove alt text value from test
CorinaMurg Nov 13, 2024
2c784f3
fix(644): add comment to inflteam interface
CorinaMurg Nov 15, 2024
3318d55
fix(644): replace sr-only span with alt text for logos of previous we…
CorinaMurg Nov 18, 2024
e1d3a7a
Merge branch 'develop' into corina/644-fix-a11y-picks-page
CorinaMurg Nov 19, 2024
7cf34d4
fix(644): create interface for previous weeks picks
CorinaMurg Nov 20, 2024
192ad24
fix(644): remove comments, refactor entryHistoryObject
CorinaMurg Nov 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/apiFunctions.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ export interface INFLTeam {
teamLogo: string;
teamName: string;
}
export interface IPickHistoryTeam extends Omit<INFLTeam, 'teamId'> {}

export interface IUserPicksData extends IUserPick {}

export interface ILeague {
leagueId: string;
leagueName: string;
Expand Down
38 changes: 21 additions & 17 deletions app/(main)/league/[leagueId]/entry/[entryId]/week/Week.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
getGameWeek,
} from '@/api/apiFunctions';
import { ILeague } from '@/api/apiFunctions.interface';
import { IPickHistoryTeam } from '@/api/apiFunctions.interface';
import WeekTeams from './WeekTeams';
import GlobalSpinner from '@/components/GlobalSpinner/GlobalSpinner';
import { onWeeklyPickChange } from './WeekHelper';
Expand All @@ -43,7 +44,7 @@ import Heading from '@/components/Heading/Heading';
*/
// eslint-disable-next-line no-unused-vars
const Week = ({ entry, league, NFLTeams, week }: IWeekProps): JSX.Element => {
const [pickHistory, setPickHistory] = useState<string[]>([]);
const [pickHistory, setPickHistory] = useState<IPickHistoryTeam[]>([]);
const [entryName, setEntryName] = useState<string>('');
const [error, setError] = useState<string | null>(null);
const [schedule, setSchedule] = useState<ISchedule[]>([]);
Expand Down Expand Up @@ -160,15 +161,16 @@ const Week = ({ entry, league, NFLTeams, week }: IWeekProps): JSX.Element => {
}

setEntryName(currentEntry.name);
let entryHistory = currentEntry?.selectedTeams || [];
const entryHistory = currentEntry?.selectedTeams || [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this function need to be refactored for this ticket?

Copy link
Contributor Author

@CorinaMurg CorinaMurg Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shashilo
Previously, we only stored URLs for team logos in the pickHistory state. But we need to hold on to the team name as well to use it as the alt text of the image. That's why the entryHistoryObject.


if (currentEntry?.selectedTeams.length > 0) {
entryHistory = entryHistory.map((teamName) =>
getNFLTeamLogo(NFLTeams, teamName),
);
const entryHistoryObject = entryHistory.map((teamName) => ({
teamName: teamName,
teamLogo: getNFLTeamLogo(NFLTeams, teamName),
}));
setPickHistory(entryHistoryObject);
}

setPickHistory(entryHistory);
} catch (error) {
throw new Error("Error fetching user's pick history");
} finally {
Expand Down Expand Up @@ -291,14 +293,14 @@ const Week = ({ entry, league, NFLTeams, week }: IWeekProps): JSX.Element => {
className="flex flex-wrap w-[90%] gap-4 overflow-x-scroll justify-center pb-10 items-center"
data-testid="user-pick-history"
>
{pickHistory?.map((logoURL, index) => {
{pickHistory?.map((team, index) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to refactor this code for this ticket?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shashilo
The alt text for each logo used to be hardcoded as "team logo". We needed a way to assign it a dynamic value, ie the team's name.

const isCurrentWeek = index === pickHistory.length - 1;
const hasCurrentWeekPick =
pickHistory.length === Number(week);

return (
<div
key={`${logoURL ? logoURL : 'no-pick'}-${index + 1}`}
key={`${team.teamLogo ? team.teamLogo : 'no-pick'}-${index + 1}`}
className={cn(
'flex flex-col items-center justify-center border p-2 rounded-lg gap-1',
isCurrentWeek && hasCurrentWeekPick
Expand All @@ -311,15 +313,17 @@ const Week = ({ entry, league, NFLTeams, week }: IWeekProps): JSX.Element => {
? 'CURRENT'
: `WEEK ${index + 1}`}
</span>
{logoURL ? (
<Image
className="league-entry-logo"
width={64}
height={64}
data-testid="league-history-logo"
src={logoURL}
alt="teamLogo"
/>
{team.teamLogo ? (
<>
<Image
className="league-entry-logo"
width={64}
height={64}
data-testid="league-history-logo"
src={team.teamLogo}
alt={team.teamName}
/>
</>
) : (
<span
className="text-xs h-16 w-16 text-primary pt-6 text-center"
Expand Down
37 changes: 20 additions & 17 deletions app/(main)/league/[leagueId]/entry/[entryId]/week/WeekTeams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,33 +69,34 @@ const WeekTeams = ({
onWeeklyPickChange,
loadingTeamName,
}: IWeekTeamsProps): JSX.Element => (
<RadioGroup
onValueChange={(value: string) => onWeeklyPickChange(value as NFLTeams)}
defaultValue={userPick}
value={userPick}
onChange={field.onChange}
>
<>
{schedule.map((scheduledGame) => {
const disableGame = checkCurrentGameTime(scheduledGame.date);

return (
<div
className="grid w-full grid-cols-[1fr_auto_1fr] gap-4 pb-8"
style={{ direction: 'rtl' }}
key={scheduledGame.id}
className="pb-8"
>
<div className="week-page-game-schedule col-span-3 text-center">
<div className="text-center mb-4">
<p>{formatDateTime(scheduledGame.date)}</p>
</div>
{scheduledGame.competitions[0].competitors.map(
(competition, index) => (
<>

<RadioGroup
className="flex flex-row-reverse gap-4 justify-between items-center w-full"
onChange={field.onChange}
defaultValue={userPick}
value={userPick}
onValueChange={(value: string) => onWeeklyPickChange(value as NFLTeams)}
>
{scheduledGame.competitions[0].competitors.map((competition, index) => (
<React.Fragment key={competition.id}>
{index > 0 && (
<div className="h-20 flex self-end items-center">
<span>@</span>
</div>
)}
<FormItem key={competition.id} className="text-center">
<FormItem className="text-center">
<FormControl>
<WeeklyPickButton
loadingTeamName={loadingTeamName}
Expand All @@ -111,12 +112,14 @@ const WeekTeams = ({
/>
</FormControl>
</FormItem>
</>
),
)}
</React.Fragment>
))}
</RadioGroup>
</div>
);
})}
</RadioGroup>
</>
);

export default WeekTeams;

2 changes: 1 addition & 1 deletion components/Label/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const labelVariants = cva(
variants: {
disabled: {
true: 'opacity-50 cursor-not-allowed',
false: 'peer-aria-checked:border-accent peer-hover:border-white'
false: 'peer-aria-checked:border-accent peer-hover:border-white peer-focus:outline-none peer-focus-visible:outline peer-focus-visible:outline-2 peer-focus-visible:outline-white peer-focus-visible:rounded-xl peer-focus-visible:outline-offset-4'
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion components/WeeklyPickButton/WeeklyPickButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const weeklyPickData = {
src: '/path/to/ravens.svg',
height: '48',
width: '48',
alt: 'Ravens',
alt: '',
};

describe('WeeklyPickButton', () => {
Expand Down
4 changes: 2 additions & 2 deletions components/WeeklyPickButton/WeeklyPickButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const WeeklyPickButton: React.FC<WeeklyPickButtonProps> = ({
}): JSX.Element => {
return (
<>
<label htmlFor="home" className="capitalize" data-testid="home-away">
<label htmlFor={team} className="capitalize" data-testid="home-away">
{homeAway}
</label>
<div style={{ direction: 'ltr' }} className="flex items-center mt-4">
Expand All @@ -56,7 +56,7 @@ const WeeklyPickButton: React.FC<WeeklyPickButtonProps> = ({
>
<Image
src={src}
alt={team}
alt=""
width={48}
height={48}
priority
Expand Down