feat: highlight the DatePicker's date (#1669)

Co-authored-by: Athurg Feng <athurg@gooth.org>
pull/1682/head
Athurg Gooth 2 years ago committed by GitHub
parent 34913cfc83
commit 2730b90512
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,9 @@
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { DAILY_TIMESTAMP } from "@/helpers/consts";
import { getMemoStats } from "@/helpers/api";
import { getDateStampByDate } from "@/helpers/datetime";
import { useUserStore } from "@/store/module";
import Icon from "../Icon";
import "@/less/common/date-picker.less";
@ -14,11 +17,24 @@ const DatePicker: React.FC<DatePickerProps> = (props: DatePickerProps) => {
const { t } = useTranslation();
const { className, datestamp, handleDateStampChange } = props;
const [currentDateStamp, setCurrentDateStamp] = useState<DateStamp>(getMonthFirstDayDateStamp(datestamp));
const [countByDate, setCountByDate] = useState(new Map());
useEffect(() => {
setCurrentDateStamp(getMonthFirstDayDateStamp(datestamp));
}, [datestamp]);
const currentUserId = useUserStore().getCurrentUserId();
useEffect(() => {
getMemoStats(currentUserId).then(({ data: { data } }) => {
const m = new Map();
for (const record of data) {
const date = getDateStampByDate(record * 1000);
m.set(date, true);
}
setCountByDate(m);
});
}, [currentUserId]);
const firstDate = new Date(currentDateStamp);
const firstDateDay = firstDate.getDay() === 0 ? 7 : firstDate.getDay();
const dayList = [];
@ -89,7 +105,7 @@ const DatePicker: React.FC<DatePickerProps> = (props: DatePickerProps) => {
return (
<span
key={d.datestamp}
className={`day-item ${d.datestamp === datestamp ? "current" : ""}`}
className={`day-item ${countByDate.has(d.datestamp) && "font-bold"} ${d.datestamp === datestamp ? "current" : ""}`}
onClick={() => handleDateItemClick(d.datestamp)}
>
{d.date}

Loading…
Cancel
Save