From bf905bba86f9bd915eda277f5f08fc0e438db485 Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 22 Jan 2024 22:50:27 +0800 Subject: [PATCH] chore: remove unused date picker --- web/src/components/kit/DatePicker.tsx | 151 -------------------------- 1 file changed, 151 deletions(-) delete mode 100644 web/src/components/kit/DatePicker.tsx diff --git a/web/src/components/kit/DatePicker.tsx b/web/src/components/kit/DatePicker.tsx deleted file mode 100644 index a8413ea3..00000000 --- a/web/src/components/kit/DatePicker.tsx +++ /dev/null @@ -1,151 +0,0 @@ -import { Badge, Button } from "@mui/joy"; -import classNames from "classnames"; -import { useEffect, useRef, useState } from "react"; -import useClickAway from "react-use/lib/useClickAway"; -import { memoServiceClient } from "@/grpcweb"; -import { DAILY_TIMESTAMP } from "@/helpers/consts"; -import { getDateStampByDate, getTimeStampByDate, isFutureDate } from "@/helpers/datetime"; -import useCurrentUser from "@/hooks/useCurrentUser"; -import { useTranslate } from "@/utils/i18n"; -import Icon from "../Icon"; -import "@/less/common/date-picker.less"; - -interface DatePickerProps { - className?: string; - isFutureDateDisabled?: boolean; - datestamp: number; - handleDateStampChange: (datestamp: number) => void; - handleClickAway: () => void; -} - -const DatePicker: React.FC = (props: DatePickerProps) => { - const t = useTranslate(); - const { className, isFutureDateDisabled, datestamp, handleDateStampChange, handleClickAway } = props; - const containerRef = useRef(null); - const [currentDateStamp, setCurrentDateStamp] = useState(getMonthFirstDayDateStamp(datestamp)); - const [countByDate, setCountByDate] = useState(new Map()); - const user = useCurrentUser(); - - useClickAway(containerRef, () => { - handleClickAway(); - }); - - useEffect(() => { - setCurrentDateStamp(getMonthFirstDayDateStamp(datestamp)); - }, [datestamp]); - - useEffect(() => { - (async () => { - const { stats } = await memoServiceClient.getUserMemosStats({ - name: user.name, - timezone: Intl.DateTimeFormat().resolvedOptions().timeZone, - }); - const m = new Map(); - Object.entries(stats).forEach(([k]) => { - const utcOffsetMilliseconds = new Date().getTimezoneOffset() * 60 * 1000; - const date = getDateStampByDate(new Date(getTimeStampByDate(k) + utcOffsetMilliseconds)); - m.set(date, true); - }); - setCountByDate(m); - })(); - }, [user.name]); - - const firstDate = new Date(currentDateStamp); - const dayList = []; - for (let i = 0; i < firstDate.getDay(); i++) { - dayList.push({ - date: 0, - datestamp: firstDate.getTime() - DAILY_TIMESTAMP * (7 - i), - }); - } - const dayAmount = getMonthDayAmount(currentDateStamp); - for (let i = 1; i <= dayAmount; i++) { - dayList.push({ - date: i, - datestamp: firstDate.getTime() + DAILY_TIMESTAMP * (i - 1), - }); - } - - const handleDateItemClick = (datestamp: number) => { - handleDateStampChange(datestamp); - }; - - const handleChangeMonthBtnClick = (i: number) => { - const nextDate = new Date(firstDate.getTime()); - nextDate.setMonth(nextDate.getMonth() + i); - setCurrentDateStamp(getMonthFirstDayDateStamp(nextDate.getTime())); - }; - - return ( -
-
- - - - {firstDate.getFullYear()}/{(firstDate.getMonth() + 1).toString().padStart(2, "0")} - - - -
-
-
- {t("days.sun")} - {t("days.mon")} - {t("days.tue")} - {t("days.wed")} - {t("days.thu")} - {t("days.fri")} - {t("days.sat")} -
- - {dayList.map((d) => { - const isDisabled = isFutureDateDisabled && isFutureDate(d.datestamp); - if (d.date === 0) { - return ( - - {""} - - ); - } else { - return ( - (isDisabled ? null : handleDateItemClick(d.datestamp))} - > - {countByDate.has(d.datestamp) ? {d.date} : d.date} - - ); - } - })} -
-
- ); -}; - -function getMonthDayAmount(datestamp: number): number { - const dateTemp = new Date(datestamp); - const currentDate = new Date(`${dateTemp.getFullYear()}/${dateTemp.getMonth() + 1}/1`); - const nextMonthDate = - currentDate.getMonth() === 11 - ? new Date(`${currentDate.getFullYear() + 1}/1/1`) - : new Date(`${currentDate.getFullYear()}/${currentDate.getMonth() + 2}/1`); - - return (nextMonthDate.getTime() - currentDate.getTime()) / DAILY_TIMESTAMP; -} - -function getMonthFirstDayDateStamp(timestamp: number): number { - const dateTemp = new Date(timestamp); - const currentDate = new Date(`${dateTemp.getFullYear()}/${dateTemp.getMonth() + 1}/1`); - return currentDate.getTime(); -} - -export default DatePicker;