Skip to content

Commit

Permalink
setup pilot page
Browse files Browse the repository at this point in the history
  • Loading branch information
sebald committed Nov 11, 2023
1 parent 9d0ae49 commit d9a342c
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 0 deletions.
49 changes: 49 additions & 0 deletions app/(stats)/pilot/content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Suspense } from 'react';

import { getFactionCount, getSquads } from '@/lib/db/squads';
import { getTournamentsCount } from '@/lib/db/tournaments';
import { pilot, type PilotData } from '@/lib/stats/module';
import { setup } from '@/lib/stats/setup';

import { CardTableSkeleton } from '@/ui';
import { StatsHint } from '@/ui/stats/stats-hint';

// Helpers
// ---------------
const create = setup<PilotData>([pilot]);

// Props
// ---------------
export interface ContentProps {
from: Date;
to?: Date;
}

// Content
// ---------------
const AsyncContent = async ({ from, to }: ContentProps) => {
const [squads, tournaments, count] = await Promise.all([
getSquads({ from, to }),
getTournamentsCount({ from, to }),
getFactionCount({ from, to }),
]);
const stats = create(squads, {
count,
tournaments,
});

return <div />;
};

export const Content = (props: ContentProps) => (
<Suspense fallback={<CardTableSkeleton />}>
<div className="grid grid-cols-1 gap-4 md:grid-cols-12">
<div className="col-span-full">
<AsyncContent {...props} />
</div>
<div className="col-span-full pt-8 lg:col-start-2 lg:col-end-12">
<StatsHint />
</div>
</div>
</Suspense>
);
19 changes: 19 additions & 0 deletions app/(stats)/pilot/loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Skeleton, HeadlineSkeleton, CardTableSkeleton } from '@/ui';

export const Loading = () => (
<Skeleton>
<HeadlineSkeleton className="mt-8 h-14 w-72" />
<div className="flex items-center gap-4">
<HeadlineSkeleton className="mt-2 h-4 w-44" />{' '}
<HeadlineSkeleton className="mt-2 h-4 w-24" />{' '}
<HeadlineSkeleton className="mt-2 h-4 w-36" />
</div>
<div className="mb-4 mt-8 flex justify-end gap-4">
<HeadlineSkeleton className="h-8 w-12" />
<HeadlineSkeleton className="h-8 w-44" />
</div>
<CardTableSkeleton />
</Skeleton>
);

export default Loading;
66 changes: 66 additions & 0 deletions app/(stats)/pilot/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { createMetadata } from '@/lib/metadata';
import { toDateRange } from '@/lib/utils/params.utils';

import { Caption, Message, Title } from '@/ui';
import { DateRangeFilter } from '@/ui/params/date-range-filter';
import { FactionFilter } from '@/ui/params/faction-filter';
import { Filter } from '@/ui/params/filter';
import { SmallSamplesFilter } from '@/ui/params/small-samples-filter';
import { SortParam } from '@/ui/params/sort-param';
import { StatsInfo } from '@/ui/stats/stats-info';

// Metadata
// ---------------
export const metadata = createMetadata({
title: 'Pilots',
description: 'Take a look at what is currently flown in X-Wing!',
ogTitle: 'Pilots',
ogWidth: 65,
});

// Props
// ---------------
interface PageProps {
searchParams: {
from: string;
to: string;
};
}

// Page
// ---------------
const PilotsPage = async ({ searchParams }: PageProps) => {
const params = toDateRange(searchParams);

if (params.error) {
return (
<div className="grid flex-1 place-items-center">
<Message variant="error">
<Message.Title>Whoopsie, something went wrong!</Message.Title>
Looks like there is an error in the given query parameters.
</Message>
</div>
);
}

const { from, to } = params;

return (
<>
<div className="pb-6">
<Title>Pilots</Title>
<Caption>
<StatsInfo from={from} to={to} />
</Caption>
</div>
<Filter>
<SmallSamplesFilter />
<DateRangeFilter />
<FactionFilter />
<SortParam />
</Filter>
</>
);
};

export default PilotsPage;
4 changes: 4 additions & 0 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export const siteNavigation = [
name: 'Compositions',
href: '/composition',
},
{
name: 'Pilots',
href: '/pilot',
},
];

export const secondaryNavigation = [
Expand Down

0 comments on commit d9a342c

Please sign in to comment.