From 0523619aee0e235d02f5808b44e087d7d6f43814 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com>
Date: Sun, 9 Jun 2024 21:00:40 -0500
Subject: [PATCH] feat: start of date picker
---
src/app/tools/player-stats/[id]/page.tsx | 9 +-
src/components/DatePicker.tsx | 186 +++++++++++++++++++++++
2 files changed, 193 insertions(+), 2 deletions(-)
create mode 100644 src/components/DatePicker.tsx
diff --git a/src/app/tools/player-stats/[id]/page.tsx b/src/app/tools/player-stats/[id]/page.tsx
index 9e1109c27..174f6072a 100644
--- a/src/app/tools/player-stats/[id]/page.tsx
+++ b/src/app/tools/player-stats/[id]/page.tsx
@@ -4,6 +4,7 @@ import { ExclamationTriangleIcon } from '@radix-ui/react-icons';
import { Box, Callout, Flex, Heading, Tabs, Text } from '@radix-ui/themes';
import { use, useMemo, useState } from 'react';
import { BkniIndicator } from '../../../../components/BkniIndicator';
+import { DatePicker } from '../../../../components/DatePicker';
import PageWrapper from '../../../../components/PageWrapper';
import { getAccountInfo } from '../../../../core/blitz/getAccountInfo';
import { getClanAccountInfo } from '../../../../core/blitz/getClanAccountInfo';
@@ -22,8 +23,8 @@ export default function Page({ params }: { params: { id: string } }) {
[id],
);
const clanAccountInfo = use(clanAccountInfoPromise);
- // const bkni = Math.random() * 2 - 1;
- const bkni = 0.87;
+ const bkni = Math.random() * 2 - 1;
+ // const bkni = 0.87;
const [period, setPeriod] = useState<'custom' | number>(30);
const { bkniColor } = parseBkni(bkni);
const isTracking = false;
@@ -101,6 +102,10 @@ export default function Page({ params }: { params: { id: string } }) {
+
+
+
+
{!isTracking && (
diff --git a/src/components/DatePicker.tsx b/src/components/DatePicker.tsx
new file mode 100644
index 000000000..d3b1c4b85
--- /dev/null
+++ b/src/components/DatePicker.tsx
@@ -0,0 +1,186 @@
+import {
+ ChevronLeftIcon,
+ ChevronRightIcon,
+ ChevronUpIcon,
+ ReloadIcon,
+} from '@radix-ui/react-icons';
+import {
+ Button,
+ Card,
+ ChevronDownIcon,
+ Flex,
+ Grid,
+ IconButton,
+ Link,
+ Popover,
+ Text,
+} from '@radix-ui/themes';
+import { times } from 'lodash';
+import { useState } from 'react';
+
+const DAY_TITLES = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
+const YEAR_OPTIONS = 7;
+
+export function DatePicker() {
+ const initialDate = new Date();
+
+ const [year, setYear] = useState(initialDate.getFullYear());
+ const [month, setMonth] = useState(initialDate.getMonth());
+ const [day, setDay] = useState(initialDate.getDate());
+ const [yearOffset, setYearOffset] = useState(0);
+ const [monthOffset, setMonthOffset] = useState(0);
+ const date = new Date(year + yearOffset, month + monthOffset, day);
+
+ const daysInLastMonth = new Date(year, month + monthOffset, 0).getDate();
+ const daysInMonth = new Date(year, month + monthOffset + 1, 0).getDate();
+ const firstDayOfMonth = new Date(year, month + monthOffset, 1).getDay();
+ const lastDayOfMonth = new Date(
+ year,
+ month + monthOffset,
+ daysInMonth,
+ ).getDay();
+
+ return (
+
+
+ setMonthOffset((state) => state - 1)}
+ ml="2"
+ >
+
+
+
+
+ {
+ setYear(initialDate.getFullYear());
+ setMonth(initialDate.getMonth());
+ setDay(initialDate.getDate());
+ setYearOffset(0);
+ setMonthOffset(0);
+ }}
+ >
+
+
+
+
+ {date.toLocaleString(undefined, { month: 'long' })}
+
+ setYearOffset(0)}>
+
+
+ {date.getFullYear()}
+
+
+
+
+
+ setYearOffset((state) => state + 1)}
+ mb="2"
+ >
+
+
+
+ {times(YEAR_OPTIONS, (index) => {
+ const thisYear =
+ year - index + Math.floor(YEAR_OPTIONS / 2) + yearOffset;
+
+ return (
+
+ );
+ })}
+
+ setYearOffset((state) => state - 1)}
+ mt="2"
+ >
+
+
+
+
+
+
+
+
+ setMonthOffset((state) => state + 1)}
+ mr="2"
+ >
+
+
+
+
+
+ {times(7, (index) => (
+
+ {DAY_TITLES[index]}
+
+ ))}
+
+
+
+ {times(firstDayOfMonth, (index) => (
+
+ {daysInLastMonth - firstDayOfMonth + index + 1}
+
+ ))}
+
+ {times(daysInMonth, (index) => {
+ const selected = index === day - 1 && monthOffset === 0;
+
+ return (
+ {
+ setYear(year + yearOffset);
+ setMonth((month + monthOffset) % 12);
+ setDay(index + 1);
+ setYearOffset(0);
+ setMonthOffset(0);
+ }}
+ >
+ {index + 1}
+
+ );
+ })}
+
+ {times(6 - lastDayOfMonth, (index) => (
+
+ {index + 1}
+
+ ))}
+
+
+ {/* {`${day} ${month} ${year}`} */}
+
+ );
+}