Skip to content

Commit

Permalink
Release v0.3.1-alpha (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
shashilo authored Sep 10, 2024
2 parents 88375ab + 6ce440d commit debca84
Show file tree
Hide file tree
Showing 37 changed files with 217 additions and 131 deletions.
35 changes: 28 additions & 7 deletions api/apiFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,20 +215,32 @@ export async function getAllWeeklyPicks({
leagueId: ILeague['leagueId'];
weekId: IGameWeek['id'];
}): Promise<IWeeklyPicks['userResults'] | null> {
const currentYear = new Date().getFullYear().toString();

try {
const response = await databases.listDocuments(
appwriteConfig.databaseId,
Collection.GAME_RESULTS,
[Query.equal('gameId', leagueId), Query.equal('gameWeekId', weekId)],
[Query.equal('leagueId', leagueId), Query.equal('gameWeekId', weekId)],
);

// check if any users have selected their pick
if (response.documents[0].userResults === '') {
return null;
if (response.total === 0) {
const newDocument = await databases.createDocument(
appwriteConfig.databaseId,
Collection.GAME_RESULTS,
ID.unique(),
{
leagueId: leagueId,
gameWeekId: weekId,
userResults: '{}',
year: currentYear,
},
);

return JSON.parse(newDocument.documents[0].userResults);
}

const data = JSON.parse(response.documents[0].userResults);
return data;
return JSON.parse(response.documents[0].userResults);
} catch (error) {
console.error(error);
throw new Error('Error getting all weekly picks');
Expand All @@ -249,10 +261,19 @@ export async function createWeeklyPicks({
userResults,
}: IWeeklyPicks): Promise<Models.Document> {
try {
const getLeagueGameResults = await databases.listDocuments(
appwriteConfig.databaseId,
Collection.GAME_RESULTS,
[
Query.equal('leagueId', leagueId),
Query.equal('gameWeekId', gameWeekId),
],
);

return await databases.updateDocument(
appwriteConfig.databaseId,
Collection.GAME_RESULTS, //collectionID
'663130a100297f77c3c8', //documentID
getLeagueGameResults.documents[0].$id, //documentID
{
leagueId,
gameWeekId,
Expand Down
2 changes: 1 addition & 1 deletion app/(admin)/admin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { JSX } from 'react';
const AdminHomepage = (): JSX.Element => {
return (
<section
className="admin-homepage-content space-y-4 px-6 py-6 outline outline-border rounded"
className="admin-homepage-content space-y-4 px-6 py-6 outline outline-outline rounded"
data-testid="admin-homepage-content"
>
<p>
Expand Down
2 changes: 1 addition & 1 deletion app/(admin)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const AdminRootLayout = ({
}): React.JSX.Element => {
return (
<html lang="en">
<body className="dark:dark bg-background text-foreground h-screen">
<body className="dark bg-background text-foreground h-screen">
<ErrorBoundary>
<AuthContextProvider>
<div className="admin-body-inner-container grid grid-cols-adminLayout h-full">
Expand Down
2 changes: 1 addition & 1 deletion app/(main)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const RootLayout = ({
}): JSX.Element => {
return (
<html lang="en" className={GeistSans.className}>
<body className="dark:dark bg-background pb-8 px-4 text-foreground xl:pb-0">
<body className="dark bg-background pb-8 px-4 text-foreground xl:pb-0">
<ErrorBoundary>
<AuthContextProvider>
<Nav />
Expand Down
16 changes: 16 additions & 0 deletions app/(main)/league/[leagueId]/entry/[entryId]/week/Week.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ import { onWeeklyPickChange } from './WeekHelper';
import { parseUserPick } from '@/utils/utils';
import { IWeeklyPicks } from '@/api/apiFunctions.interface';

const mockUseAuthContext = {
isSignedIn: false,
};

jest.mock('@/context/AuthContextProvider', () => ({
useAuthContext() {
return {
...mockUseAuthContext,
};
},
}));

jest.mock('@/store/dataStore', () => ({
useDataStore: jest.fn(() => ({
currentWeek: 1,
Expand Down Expand Up @@ -120,15 +132,19 @@ describe('Week', () => {
});

test('should display GlobalSpinner while loading data', async () => {
mockUseAuthContext.isSignedIn = true;

render(
<Week entry={entry} league={league} NFLTeams={NFLTeams} week={week} />,
);

await waitFor(() => {
expect(screen.getByTestId('global-spinner')).toBeInTheDocument();
});
});

test('should not display GlobalSpinner after loading data', async () => {
mockUseAuthContext.isSignedIn = true;
mockCreateWeeklyPicks.mockResolvedValue({});

render(
Expand Down
18 changes: 11 additions & 7 deletions app/(main)/league/[leagueId]/entry/[entryId]/week/Week.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { onWeeklyPickChange } from './WeekHelper';
import Alert from '@/components/AlertNotification/AlertNotification';
import { AlertVariants } from '@/components/AlertNotification/Alerts.enum';
import { NFLTeams } from '@/api/apiFunctions.enum';
import { useAuthContext } from '@/context/AuthContextProvider';

/**
* Renders the weekly picks page.
Expand All @@ -46,6 +47,7 @@ const Week = ({ entry, league, NFLTeams, week }: IWeekProps): JSX.Element => {
const [userPick, setUserPick] = useState<string>('');
const { user, updateCurrentWeek, updateWeeklyPicks, weeklyPicks } =
useDataStore((state) => state);
const { isSignedIn } = useAuthContext();

/**
* Fetches the current game week.
Expand Down Expand Up @@ -195,10 +197,12 @@ const Week = ({ entry, league, NFLTeams, week }: IWeekProps): JSX.Element => {
}, [week, selectedLeague]);

useEffect(() => {
getCurrentGameWeek();
getUserSelectedTeams();
getUserWeeklyPick();
}, [user]);
if (isSignedIn) {
getCurrentGameWeek();
getUserSelectedTeams();
getUserWeeklyPick();
}
}, [isSignedIn]);

if (loadingData) {
return <GlobalSpinner />;
Expand All @@ -214,9 +218,9 @@ const Week = ({ entry, league, NFLTeams, week }: IWeekProps): JSX.Element => {
<GlobalSpinner data-testid="global-spinner" />
) : (
<>
<nav className="py-6 text-orange-500 hover:no-underline">
<nav className="py-6 text-primary hover:no-underline">
<LinkCustom
className="text-orange-500 flex gap-3 items-center font-semibold text-xl hover:no-underline"
className="no-underline hover:underline text-primary flex gap-3 items-center font-semibold text-xl"
href={`/league/${league}/entry/all`}
>
<span aria-hidden="true">
Expand All @@ -226,7 +230,7 @@ const Week = ({ entry, league, NFLTeams, week }: IWeekProps): JSX.Element => {
</LinkCustom>
</nav>
<section className="w-full pt-8" data-testid="weekly-picks">
<h1 className="pb-8 text-center text-[2rem] font-bold text-white">
<h1 className="pb-8 text-center text-[2rem] font-bold text-foreground">
Week {week} pick
</h1>

Expand Down
19 changes: 9 additions & 10 deletions app/(main)/league/[leagueId]/entry/all/page.test.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { render, screen, waitFor, cleanup } from '@testing-library/react';
import { render, screen, waitFor } from '@testing-library/react';
import Entry from './page';
import { useDataStore } from '@/store/dataStore';
import {
getGameWeek,
getCurrentUserEntries,
getCurrentLeague,
getNFLTeams,
} from '@/api/apiFunctions';

jest.mock('@/store/dataStore', () => ({
useDataStore: jest.fn(() => ({
currentWeek: 1,
NFLTeams: [{
teamId: '1',
teamLogo: 'team-a-logo.png',
teamName: 'Packers',
}],
NFLTeams: [
{
teamId: '1',
teamLogo: 'team-a-logo.png',
teamName: 'Packers',
},
],
user: { id: '123', leagues: [] },
updateCurrentWeek: jest.fn(),
updateNFLTeams: jest.fn(),
Expand Down Expand Up @@ -149,7 +150,6 @@ describe('League entries page (Entry Component)', () => {

expect(entryPageHeader).toBeInTheDocument();
expect(entryPageHeaderToLeaguesLink).toBeInTheDocument();
expect(entryPageHeaderToLeaguesLink).toHaveAttribute('href', '/league/all');
expect(entryPageHeaderLeagueName).toBeInTheDocument();
expect(entryPageHeaderLeagueName).toHaveTextContent('GiS League');
expect(entryPageHeaderLeagueSurvivors).toBeInTheDocument();
Expand Down Expand Up @@ -204,7 +204,6 @@ describe('League entries page (Entry Component)', () => {

expect(entryPageHeader).toBeInTheDocument();
expect(entryPageHeaderToLeaguesLink).toBeInTheDocument();
expect(entryPageHeaderToLeaguesLink).toHaveAttribute('href', '/league/all');
expect(entryPageHeaderLeagueName).toBeInTheDocument();
expect(entryPageHeaderLeagueName).toHaveTextContent('GiS League');
expect(entryPageHeaderLeagueSurvivors).toBeInTheDocument();
Expand Down Expand Up @@ -313,7 +312,7 @@ describe('League entries page (Entry Component)', () => {
selectedTeams: ['Packers'],
},
]);

render(<Entry params={{ leagueId: '123' }} />);

await waitFor(() => {
Expand Down
12 changes: 6 additions & 6 deletions app/(main)/league/[leagueId]/entry/all/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Link from 'next/link';
import React, { JSX, useEffect, useState } from 'react';
import LoadingSpinner from '@/components/LoadingSpinner/LoadingSpinner';
import { cn } from '@/utils/utils';
import LinkCustom from '@/components/LinkCustom/LinkCustom';

/**
* Display all entries for a league.
Expand Down Expand Up @@ -150,15 +151,14 @@ const Entry = ({
) : (
<div className="mx-auto max-w-3xl pt-10">
<header data-testid="entry-page-header">
<div className="entry-page-header-to-leagues-link">
<Link
className="text-xl text-orange-600 hover:text-orange-500 flex items-center gap-3 font-semibold hover:underline"
data-testid="entry-page-header-to-leagues-link"
<div data-testid="entry-page-header-to-leagues-link">
<LinkCustom
className="no-underline hover:underline text-primary flex gap-3 items-center font-semibold text-xl"
href={`/league/all`}
>
<ChevronLeft />
Your Leagues
</Link>
</LinkCustom>
</div>
<div
className="entry-page-header-main flex flex-col justify-between text-center gap-10 pt-6 pb-4"
Expand Down Expand Up @@ -241,7 +241,7 @@ const Entry = ({

{currentWeek > 1 && (
<Link
className="text-orange-600 hover:text-orange-500 font-bold hover:underline"
className="text-primary hover:text-primary-muted font-bold hover:underline"
data-testid="past-weeks-link"
href={`#`}
>
Expand Down
6 changes: 3 additions & 3 deletions app/(main)/league/all/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ const Leagues = (): JSX.Element => {
<select
{...field}
id="available-leagues"
className={`border rounded p-2 w-full dark:text-secondary ${
fieldState.error ? 'border-red-500' : ''
className={`border border-border rounded p-2 w-full text-secondary ${
fieldState.error ? 'border-error' : ''
}`}
>
<option value="">Select league</option>
Expand All @@ -190,7 +190,7 @@ const Leagues = (): JSX.Element => {
))}
</select>
{fieldState.error && (
<span className="text-red-500">
<span className="text-warning">
{fieldState.error.message}
</span>
)}
Expand Down
6 changes: 3 additions & 3 deletions app/(main)/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ const Login = (): React.JSX.Element => {

return (
<section className="grid xl:grid-cols-2 xl:grid-rows-none">
<div className="row-span-1 grid w-full place-items-center from-[#4E160E] to-zinc-950 dark:bg-gradient-to-b xl:h-screen xl:bg-gradient-to-b">
<div className="row-span-1 grid w-full place-items-center from-[#4E160E] to-zinc-950 bg-gradient-to-b xl:h-screen xl:bg-gradient-to-b">
<Logo className="mx-auto w-52 xl:w-64 xl:place-self-end" src={logo} />
<div className="mx-auto grid gap-4 place-self-end px-8 pb-8 text-foreground text-white">
<div className="mx-auto grid gap-4 place-self-end px-8 pb-8 text-foreground">
<p className="hidden leading-7 xl:block">
Thank you... fantasy football draft, for letting me know that even
in my fantasies, I am bad at sports.
Expand All @@ -105,7 +105,7 @@ const Login = (): React.JSX.Element => {
<h1 className="text-5xl font-extrabold tracking-tight">
Join Gridiron Survivor
</h1>
<p className="pb-4 font-normal leading-7 text-zinc-500">
<p className="pb-4 font-normal leading-7 text-muted-foreground">
Log in to your existing account or{' '}
<LinkCustom href="/register">sign up</LinkCustom> to get started
with a league
Expand Down
2 changes: 1 addition & 1 deletion app/(main)/register/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,6 @@ describe('Register', () => {
test('renders Register component in dark mode using global css styles for background and foreground', () => {
const darkModeSection = screen.getByTestId('dark-mode-section');

expect(darkModeSection).toHaveClass('dark:bg-gradient-to-b');
expect(darkModeSection).toHaveClass('bg-gradient-to-b');
});
});
6 changes: 3 additions & 3 deletions app/(main)/register/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ const Register = (): JSX.Element => {
<section className="grid xl:grid-cols-2 xl:grid-rows-none">
<div
data-testid="dark-mode-section"
className="row-span-1 grid w-full place-items-center from-[#4E160E] to-zinc-950 dark:bg-gradient-to-b xl:h-screen xl:bg-gradient-to-b"
className="row-span-1 grid w-full place-items-center from-[#4E160E] to-zinc-950 bg-gradient-to-b xl:h-screen xl:bg-gradient-to-b"
>
<Logo className="mx-auto w-52 xl:w-64 xl:place-self-end" src={logo} />
<div className="mx-auto grid gap-4 place-self-end px-8 pb-8 text-foreground text-white">
<div className="mx-auto grid gap-4 place-self-end px-8 pb-8 text-foreground">
<p className="hidden leading-7 xl:block">
Thank you... fantasy football draft, for letting me know that even
in my fantasies, I am bad at sports.
Expand All @@ -143,7 +143,7 @@ const Register = (): JSX.Element => {
<h1 className="text-5xl font-extrabold tracking-tight text-foreground">
Register A New Account
</h1>
<p className="pb-4 font-normal leading-7 text-zinc-500">
<p className="pb-4 font-normal leading-7 text-muted-foreground">
If you have an existing account{' '}
<LinkCustom href="/login">Login!</LinkCustom>
</p>
Expand Down
2 changes: 1 addition & 1 deletion app/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const ErrorBoundary: React.FC<ErrorBoundaryProps> = ({ children }) => {
if (errorState.hasError) {
return (
<div className="align-center flex flex-col">
<h2 className="text-white">Something went wrong!</h2>
<h2 className="text-foreground">Something went wrong!</h2>
<Button
data-testid="reset-button"
onClick={resetErrorBoundary}
Expand Down
Loading

1 comment on commit debca84

@vercel
Copy link

@vercel vercel bot commented on debca84 Sep 10, 2024

Choose a reason for hiding this comment

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

Please sign in to comment.