import { useRef, useState } from "react"; import { useAppSelector } from "../store"; import toImage from "../labs/html2image"; import useToggle from "../hooks/useToggle"; import { DAILY_TIMESTAMP } from "../helpers/consts"; import * as utils from "../helpers/utils"; import { showDialog } 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", "Dev"]; const weekdayChineseStrArray = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; const DailyReviewDialog: React.FC = (props: Props) => { const memos = useAppSelector((state) => state.memo.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.createdTs) >= currentDateStamp && utils.getTimeStampByDate(m.createdTs) < currentDateStamp + DAILY_TIMESTAMP ) .sort((a, b) => utils.getTimeStampByDate(a.createdTs) - utils.getTimeStampByDate(b.createdTs)); const handleShareBtnClick = () => { if (!memosElRef.current) { return; } toggleShowDatePicker(false); toImage(memosElRef.current, { backgroundColor: "#ffffff", pixelRatio: window.devicePixelRatio * 2, }) .then((url) => { showPreviewImageDialog(url); }) .catch(() => { // do nth }); }; const handleDataPickerChange = (datestamp: DateStamp): void => { setCurrentDateStamp(datestamp); toggleShowDatePicker(false); }; return ( <>

toggleShowDatePicker()}> 📅 Daily Review

setCurrentDateStamp(currentDateStamp - DAILY_TIMESTAMP)}> setCurrentDateStamp(currentDateStamp + DAILY_TIMESTAMP)}> props.destroy()}>
{currentDate.getFullYear()}
{monthChineseStrArray[currentDate.getMonth()]}
{currentDate.getDate()}
{weekdayChineseStrArray[currentDate.getDay()]}
{dailyMemos.length === 0 ? (

Oops, there is nothing.

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