import { useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { useMemoStore } from "../store/module"; import toImage from "../labs/html2image"; import useToggle from "../hooks/useToggle"; import { DAILY_TIMESTAMP } from "../helpers/consts"; import * as utils from "../helpers/utils"; import Icon from "./Icon"; import { generateDialog } from "./Dialog"; import DatePicker from "./common/DatePicker"; import showPreviewImageDialog from "./PreviewImageDialog"; import DailyMemo from "./DailyMemo"; import "../less/daily-review-dialog.less"; interface Props extends DialogProps { currentDateStamp: DateStamp; } const monthChineseStrArray = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"]; const weekdayChineseStrArray = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; const DailyReviewDialog: React.FC = (props: Props) => { const { t } = useTranslation(); const memoStore = useMemoStore(); const memos = memoStore.state.memos; const [currentDateStamp, setCurrentDateStamp] = useState(utils.getDateStampByDate(utils.getDateString(props.currentDateStamp))); const [showDatePicker, toggleShowDatePicker] = useToggle(false); const memosElRef = useRef(null); const currentDate = new Date(currentDateStamp); const dailyMemos = memos .filter( (m) => m.rowStatus === "NORMAL" && utils.getTimeStampByDate(m.displayTs) >= currentDateStamp && utils.getTimeStampByDate(m.displayTs) < currentDateStamp + DAILY_TIMESTAMP ) .sort((a, b) => utils.getTimeStampByDate(a.displayTs) - utils.getTimeStampByDate(b.displayTs)); const handleShareBtnClick = () => { if (!memosElRef.current) { return; } toggleShowDatePicker(false); toImage(memosElRef.current, { pixelRatio: window.devicePixelRatio * 2, }) .then((url) => { showPreviewImageDialog(url); }) .catch(() => { // do nth }); }; const handleDataPickerChange = (datestamp: DateStamp): void => { setCurrentDateStamp(datestamp); toggleShowDatePicker(false); }; return ( <>

toggleShowDatePicker()}> 📅 {t("sidebar.daily-review")}

/
{currentDate.getFullYear()}
{monthChineseStrArray[currentDate.getMonth()]}
{currentDate.getDate()}
{weekdayChineseStrArray[currentDate.getDay()]}
{dailyMemos.length === 0 ? (

{t("daily-review.oops-nothing")}

) : (
{dailyMemos.map((memo) => ( ))}
)}
); }; export default function showDailyReviewDialog(datestamp: DateStamp = Date.now()): void { generateDialog( { className: "daily-review-dialog", dialogName: "daily-review-dialog", }, DailyReviewDialog, { currentDateStamp: datestamp } ); }