mirror of
				https://github.com/usememos/memos.git
				synced 2025-10-31 16:59:30 +08:00 
			
		
		
		
	feat: highlight the DatePicker's date (#1669)
Co-authored-by: Athurg Feng <athurg@gooth.org>
This commit is contained in:
		
							parent
							
								
									34913cfc83
								
							
						
					
					
						commit
						2730b90512
					
				
					 1 changed files with 17 additions and 1 deletions
				
			
		|  | @ -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…
	
	Add table
		
		Reference in a new issue