diff --git a/app/(stats)/compositions/[[...range]]/compositions.tsx b/app/(stats)/compositions/[[...range]]/compositions.tsx index 63fccb77..49823c62 100644 --- a/app/(stats)/compositions/[[...range]]/compositions.tsx +++ b/app/(stats)/compositions/[[...range]]/compositions.tsx @@ -1,8 +1,9 @@ 'use client'; import { Card } from '@/ui'; -import { useSmallSamplesFilter } from '@/ui/filter/small-samples-filter'; -import { useFactionFilter } from '@/ui/filter/faction-filter'; +import { useSmallSamplesFilter } from '@/ui/params/small-samples-filter'; +import { useFactionFilter } from '@/ui/params/faction-filter'; +import { useSortParam } from '@/ui/params/sort-param'; import { CompositionTable } from '@/ui/stats/composition-stats'; import type { CompositionData } from '@/lib/stats/module/composition'; @@ -14,6 +15,7 @@ export interface CompositionsProps { export const Compositions = ({ data }: CompositionsProps) => { const [smallSamples] = useSmallSamplesFilter(); const [faction] = useFactionFilter(); + const [sort] = useSortParam(); return ( @@ -32,6 +34,7 @@ export const Compositions = ({ data }: CompositionsProps) => { return true; }} + sortBy={sort} /> diff --git a/app/(stats)/compositions/[[...range]]/page.tsx b/app/(stats)/compositions/[[...range]]/page.tsx index 317f43de..7285d26d 100644 --- a/app/(stats)/compositions/[[...range]]/page.tsx +++ b/app/(stats)/compositions/[[...range]]/page.tsx @@ -10,14 +10,14 @@ import { fromDateRange } from '@/lib/utils/url.utils'; import { Caption, Inline, Title } from '@/ui'; import { Calendar, Rocket, Trophy } from '@/ui/icons'; -import { StatsFilter } from '@/ui/stats/stats-filter'; import { StatsHint } from '@/ui/stats/stats-hint'; import { setup } from '@/lib/stats'; import { CompositionData, composition } from '@/lib/stats/module'; -import { DateRangeFilter } from '@/ui/filter/date-range-filter'; -import { FactionFilter } from '@/ui/filter/faction-filter'; -import { SmallSamplesFilter } from '@/ui/filter/small-samples-filter'; +import { DateRangeFilter } from '@/ui/params/date-range-filter'; +import { FactionFilter } from '@/ui/params/faction-filter'; +import { SmallSamplesFilter } from '@/ui/params/small-samples-filter'; +import { SortParam } from '@/ui/params/sort-param'; import { Compositions } from './compositions'; @@ -103,13 +103,14 @@ const CompositionsPage = async ({ params }: PageProps) => { - + +
diff --git a/ui/index.ts b/ui/index.ts index 274b7695..e1ac9505 100644 --- a/ui/index.ts +++ b/ui/index.ts @@ -28,6 +28,7 @@ export * from './select'; export * from './sheet'; export * from './ship-icon'; export * from './skeleton'; +export * from './sort-selection'; export * from './spinner'; export * from './squad'; export * from './switch'; diff --git a/ui/filter/date-range-filter.tsx b/ui/params/date-range-filter.tsx similarity index 100% rename from ui/filter/date-range-filter.tsx rename to ui/params/date-range-filter.tsx diff --git a/ui/filter/faction-filter.tsx b/ui/params/faction-filter.tsx similarity index 100% rename from ui/filter/faction-filter.tsx rename to ui/params/faction-filter.tsx diff --git a/ui/filter/small-samples-filter.tsx b/ui/params/small-samples-filter.tsx similarity index 100% rename from ui/filter/small-samples-filter.tsx rename to ui/params/small-samples-filter.tsx diff --git a/ui/params/sort-param.tsx b/ui/params/sort-param.tsx new file mode 100644 index 00000000..e66633fc --- /dev/null +++ b/ui/params/sort-param.tsx @@ -0,0 +1,28 @@ +'use client'; + +import { SortOptions, SortSelection } from '@/ui/sort-selection'; +import { useParams } from './useParams'; + +// Hook +// --------------- +export const useSortParam = () => { + const [filter, setFilter] = useParams(['sort']); + + const setSort = (sortBy: SortOptions) => { + setFilter({ + sort: sortBy !== 'percentile' ? sortBy : null, + }); + }; + + return [filter.sort || 'percentile', setSort] as [ + SortOptions, + (sortBy: SortOptions) => void, + ]; +}; + +// Components +// --------------- +export const SortParam = () => { + const [sort, setSort] = useSortParam(); + return ; +}; diff --git a/ui/filter/useParams.tsx b/ui/params/useParams.tsx similarity index 100% rename from ui/filter/useParams.tsx rename to ui/params/useParams.tsx diff --git a/ui/sort-selection.tsx b/ui/sort-selection.tsx new file mode 100644 index 00000000..e28d3b33 --- /dev/null +++ b/ui/sort-selection.tsx @@ -0,0 +1,34 @@ +import { Select } from './select'; + +// Props +// --------------- +export type SortOptions = + | 'percentile' + | 'deviation' + | 'winrate' + | 'frequency' + | 'count' + | 'score'; + +export interface SortSelectionProps { + value: SortOptions; + onChange: (sortBy: SortOptions) => void; +} + +// Component +// --------------- +export const SortSelection = ({ value, onChange }: SortSelectionProps) => ( + +); diff --git a/ui/stats/composition-stats/composition-stats.tsx b/ui/stats/composition-stats/composition-stats.tsx index 2bd813f0..8f35d3c5 100644 --- a/ui/stats/composition-stats/composition-stats.tsx +++ b/ui/stats/composition-stats/composition-stats.tsx @@ -1,10 +1,10 @@ 'use client'; import { useState } from 'react'; -import { Card, FactionSelection, Select } from '@/ui'; +import { Card, FactionSelection, SortSelection } from '@/ui'; +import type { SortOptions } from '@/ui'; import { CompositionTable } from './composition-table'; -import type { SortOptions } from './composition-table'; import type { CompositionStatsType } from './types'; import { XWSFaction } from '@/lib/types'; @@ -26,18 +26,7 @@ export const CompositionStats = ({ value }: CompositionStatsProps) => { Compositions - + diff --git a/ui/stats/composition-stats/composition-table.tsx b/ui/stats/composition-stats/composition-table.tsx index d173afa6..5ba2de46 100644 --- a/ui/stats/composition-stats/composition-table.tsx +++ b/ui/stats/composition-stats/composition-table.tsx @@ -3,21 +3,12 @@ import { Fragment } from 'react'; import { toPercentage } from '@/lib/utils'; +import type { SortOptions } from '@/ui'; import { Collapsible, FactionIcon, Link, ShipIcon, Table } from '@/ui'; import { Folder } from '@/ui/icons'; import type { CompositionStatsType } from './types'; -// Types -// --------------- -export type SortOptions = - | 'percentile' - | 'deviation' - | 'winrate' - | 'frequency' - | 'count' - | 'score'; - // Props // --------------- export interface CompositionTableProps {