mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
feat: date popovers
This commit is contained in:
1 parent
e2cef42667
commit
de5dfbab8e
4 files changed
+1587
-1317
No files matched your search
+2
-2
@@ -41,7 +41,7 @@
|
|||||||
"@prisma/client": "^5.4.1",
|
"@prisma/client": "^5.4.1",
|
||||||
"@radix-ui/colors": "^3.0.0",
|
"@radix-ui/colors": "^3.0.0",
|
||||||
"@radix-ui/react-icons": "^1.3.0",
|
"@radix-ui/react-icons": "^1.3.0",
|
||||||
"@radix-ui/themes": "^3.0.1",
|
"@radix-ui/themes": "^3.0.5",
|
||||||
"@react-three/drei": "^9.93.0",
|
"@react-three/drei": "^9.93.0",
|
||||||
"@react-three/fiber": "^8.15.14",
|
"@react-three/fiber": "^8.15.14",
|
||||||
"@resvg/resvg-js": "^2.4.1",
|
"@resvg/resvg-js": "^2.4.1",
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
"lz4js": "^0.2.0",
|
"lz4js": "^0.2.0",
|
||||||
"markdown-escape": "^2.0.0",
|
"markdown-escape": "^2.0.0",
|
||||||
"markdown-to-jsx": "^7.4.7",
|
"markdown-to-jsx": "^7.4.7",
|
||||||
"next": "^14.1.0",
|
"next": "^14.2.3",
|
||||||
"parse-dds": "^1.2.1",
|
"parse-dds": "^1.2.1",
|
||||||
"pickleparser": "^0.2.1",
|
"pickleparser": "^0.2.1",
|
||||||
"postprocessing": "^6.34.1",
|
"postprocessing": "^6.34.1",
|
||||||
|
|||||||
@@ -6,36 +6,38 @@ import {
|
|||||||
Callout,
|
Callout,
|
||||||
Flex,
|
Flex,
|
||||||
Heading,
|
Heading,
|
||||||
|
Link,
|
||||||
Popover,
|
Popover,
|
||||||
Tabs,
|
Tabs,
|
||||||
Text,
|
Text,
|
||||||
} from '@radix-ui/themes';
|
} from '@radix-ui/themes';
|
||||||
import { use, useMemo, useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { BkniIndicator } from '../../../../components/BkniIndicator';
|
import { BkniIndicator } from '../../../../components/BkniIndicator';
|
||||||
import { DatePicker } from '../../../../components/DatePicker';
|
import { DatePicker } from '../../../../components/DatePicker';
|
||||||
import { DummyLink } from '../../../../components/DummyLink';
|
|
||||||
import PageWrapper from '../../../../components/PageWrapper';
|
import PageWrapper from '../../../../components/PageWrapper';
|
||||||
import { getAccountInfo } from '../../../../core/blitz/getAccountInfo';
|
import { getAccountInfo } from '../../../../core/blitz/getAccountInfo';
|
||||||
import { getClanAccountInfo } from '../../../../core/blitz/getClanAccountInfo';
|
import { getClanAccountInfo } from '../../../../core/blitz/getClanAccountInfo';
|
||||||
import { idToRegion } from '../../../../core/blitz/idToRegion';
|
import { idToRegion } from '../../../../core/blitz/idToRegion';
|
||||||
import { parseBkni } from '../../../../core/blitzkit/parseBkni';
|
import { parseBkni } from '../../../../core/blitzkit/parseBkni';
|
||||||
|
import { useAwait } from '../../../../hooks/useAwait';
|
||||||
import strings from '../../../../lang/en-US.json';
|
import strings from '../../../../lang/en-US.json';
|
||||||
import { FlippedTrigger } from './components/FlippedTrigger';
|
import { FlippedTrigger } from './components/FlippedTrigger';
|
||||||
|
|
||||||
export default function Page({ params }: { params: { id: string } }) {
|
export default function Page({ params }: { params: { id: string } }) {
|
||||||
const id = parseInt(params.id);
|
const id = parseInt(params.id);
|
||||||
const region = idToRegion(id);
|
const region = idToRegion(id);
|
||||||
const accountInfoPromise = useMemo(() => getAccountInfo(region, id), [id]);
|
const accountInfo = useAwait(getAccountInfo(region, id));
|
||||||
const accountInfo = use(accountInfoPromise);
|
const clanAccountInfo = useAwait(getClanAccountInfo(region, id, ['clan']));
|
||||||
const clanAccountInfoPromise = useMemo(
|
|
||||||
() => getClanAccountInfo(region, id, ['clan']),
|
|
||||||
[id],
|
|
||||||
);
|
|
||||||
const clanAccountInfo = use(clanAccountInfoPromise);
|
|
||||||
const bkni = ((Math.round(Date.now() / 1000 / 60) / 100) % 2) - 1;
|
const bkni = ((Math.round(Date.now() / 1000 / 60) / 100) % 2) - 1;
|
||||||
const [period, setPeriod] = useState<'custom' | number>(30);
|
const [period, setPeriod] = useState<'custom' | number>(30);
|
||||||
const { bkniColor } = parseBkni(bkni);
|
const { bkniColor } = parseBkni(bkni);
|
||||||
const isTracking = false;
|
const isTracking = false;
|
||||||
|
const [customFrom, setCustomFrom] = useState<Date>(
|
||||||
|
new Date(Date.now() - 29 * 24 * 60 * 60 * 1000),
|
||||||
|
);
|
||||||
|
const [customTo, setCustomTo] = useState<Date>(new Date());
|
||||||
|
const [fromSelectorOpen, setFromSelectorOpen] = useState(false);
|
||||||
|
const [toSelectorOpen, setToSelectorOpen] = useState(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -112,16 +114,55 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
{period === 'custom' && (
|
{period === 'custom' && (
|
||||||
<Text>
|
<Text>
|
||||||
From{' '}
|
From{' '}
|
||||||
<Popover.Root>
|
<Popover.Root
|
||||||
|
open={fromSelectorOpen}
|
||||||
|
onOpenChange={setFromSelectorOpen}
|
||||||
|
>
|
||||||
<Popover.Trigger>
|
<Popover.Trigger>
|
||||||
<DummyLink underline="always">June 1, 2021</DummyLink>
|
<Link underline="always" href="#">
|
||||||
|
{customFrom.toLocaleString(undefined, {
|
||||||
|
month: 'short',
|
||||||
|
day: 'numeric',
|
||||||
|
year: 'numeric',
|
||||||
|
})}
|
||||||
|
</Link>
|
||||||
</Popover.Trigger>
|
</Popover.Trigger>
|
||||||
|
|
||||||
<Popover.Content>
|
<Popover.Content>
|
||||||
<DatePicker />
|
<DatePicker
|
||||||
|
defaultDate={customFrom}
|
||||||
|
onDateChange={(date) => {
|
||||||
|
setCustomFrom(date);
|
||||||
|
setFromSelectorOpen(false);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</Popover.Content>
|
</Popover.Content>
|
||||||
</Popover.Root>{' '}
|
</Popover.Root>{' '}
|
||||||
to <DummyLink underline="always">June 7, 2024</DummyLink>
|
to{' '}
|
||||||
|
<Popover.Root
|
||||||
|
open={toSelectorOpen}
|
||||||
|
onOpenChange={setToSelectorOpen}
|
||||||
|
>
|
||||||
|
<Popover.Trigger>
|
||||||
|
<Link underline="always" href="#">
|
||||||
|
{customTo.toLocaleString(undefined, {
|
||||||
|
month: 'short',
|
||||||
|
day: 'numeric',
|
||||||
|
year: 'numeric',
|
||||||
|
})}
|
||||||
|
</Link>
|
||||||
|
</Popover.Trigger>
|
||||||
|
|
||||||
|
<Popover.Content>
|
||||||
|
<DatePicker
|
||||||
|
defaultDate={customTo}
|
||||||
|
onDateChange={(date) => {
|
||||||
|
setCustomTo(date);
|
||||||
|
setToSelectorOpen(false);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Popover.Content>
|
||||||
|
</Popover.Root>
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
</PageWrapper>
|
</PageWrapper>
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import {
|
|||||||
} from '@radix-ui/react-icons';
|
} from '@radix-ui/react-icons';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Card,
|
|
||||||
ChevronDownIcon,
|
ChevronDownIcon,
|
||||||
Flex,
|
Flex,
|
||||||
Grid,
|
Grid,
|
||||||
@@ -17,26 +16,22 @@ import {
|
|||||||
} from '@radix-ui/themes';
|
} from '@radix-ui/themes';
|
||||||
import { times } from 'lodash';
|
import { times } from 'lodash';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Vector3Tuple } from 'three';
|
|
||||||
|
|
||||||
const DAY_TITLES = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
const DAY_TITLES = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
||||||
const YEAR_OPTIONS = 7;
|
const YEAR_OPTIONS = 7;
|
||||||
|
|
||||||
interface DatePickerProps {
|
interface DatePickerProps {
|
||||||
onDateChange?: (date: Vector3Tuple) => void;
|
onDateChange?: (date: Date) => void;
|
||||||
defaultDate?: Vector3Tuple;
|
defaultDate?: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function DatePicker({ onDateChange, defaultDate }: DatePickerProps) {
|
export function DatePicker({
|
||||||
const initialDate = new Date();
|
onDateChange,
|
||||||
|
defaultDate = new Date(),
|
||||||
const [year, setYear] = useState(
|
}: DatePickerProps) {
|
||||||
defaultDate?.[2] ?? initialDate.getFullYear(),
|
const [year, setYear] = useState(defaultDate.getFullYear());
|
||||||
);
|
const [month, setMonth] = useState(defaultDate.getMonth());
|
||||||
const [month, setMonth] = useState(
|
const [day, setDay] = useState(defaultDate.getDate());
|
||||||
defaultDate?.[1] ?? initialDate.getMonth(),
|
|
||||||
);
|
|
||||||
const [day, setDay] = useState(defaultDate?.[0] ?? initialDate.getDate());
|
|
||||||
const [yearScroll, setYearScroll] = useState(0);
|
const [yearScroll, setYearScroll] = useState(0);
|
||||||
const [yearOffset, setYearOffset] = useState(0);
|
const [yearOffset, setYearOffset] = useState(0);
|
||||||
const [monthOffset, setMonthOffset] = useState(0);
|
const [monthOffset, setMonthOffset] = useState(0);
|
||||||
@@ -64,11 +59,7 @@ export function DatePicker({ onDateChange, defaultDate }: DatePickerProps) {
|
|||||||
).getDay();
|
).getDay();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card
|
<Flex direction="column" width="fit-content">
|
||||||
style={{
|
|
||||||
width: 'fit-content',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Flex justify="between" mb="2" align="center" py="2">
|
<Flex justify="between" mb="2" align="center" py="2">
|
||||||
<IconButton
|
<IconButton
|
||||||
size="3"
|
size="3"
|
||||||
@@ -91,9 +82,9 @@ export function DatePicker({ onDateChange, defaultDate }: DatePickerProps) {
|
|||||||
size="3"
|
size="3"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setYear(initialDate.getFullYear());
|
setYear(defaultDate.getFullYear());
|
||||||
setMonth(initialDate.getMonth());
|
setMonth(defaultDate.getMonth());
|
||||||
setDay(initialDate.getDate());
|
setDay(defaultDate.getDate());
|
||||||
setYearOffset(0);
|
setYearOffset(0);
|
||||||
setMonthOffset(0);
|
setMonthOffset(0);
|
||||||
}}
|
}}
|
||||||
@@ -223,7 +214,7 @@ export function DatePicker({ onDateChange, defaultDate }: DatePickerProps) {
|
|||||||
setYearOffset(0);
|
setYearOffset(0);
|
||||||
setMonthOffset(0);
|
setMonthOffset(0);
|
||||||
|
|
||||||
onDateChange?.([newDay, newMonth, newYear]);
|
onDateChange?.(new Date(newYear, newMonth, newDay));
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{index + 1}
|
{index + 1}
|
||||||
@@ -237,6 +228,6 @@ export function DatePicker({ onDateChange, defaultDate }: DatePickerProps) {
|
|||||||
</IconButton>
|
</IconButton>
|
||||||
))}
|
))}
|
||||||
</Grid>
|
</Grid>
|
||||||
</Card>
|
</Flex>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user