diff --git a/src/app/features/settings/general/General.tsx b/src/app/features/settings/general/General.tsx index a2c19c25..6b5c0fe3 100644 --- a/src/app/features/settings/general/General.tsx +++ b/src/app/features/settings/general/General.tsx @@ -346,16 +346,16 @@ function Appearance() { } type CustomDateFormatProps = { - dateFormatString: string; - setDateFormatString: (format: string) => void; + value: string; + onChange: (format: string) => void; }; -function CustomDateFormat({ dateFormatString, setDateFormatString }: CustomDateFormatProps) { - const [dateFormatCustom, setDateFormatCustom] = useState(dateFormatString); +function CustomDateFormat({ value, onChange }: CustomDateFormatProps) { + const [dateFormatCustom, setDateFormatCustom] = useState(value); useEffect(() => { - setDateFormatCustom(dateFormatString); - }, [dateFormatString]); + setDateFormatCustom(value); + }, [value]); const handleChange: ChangeEventHandler = (evt) => { const format = evt.currentTarget.value; @@ -363,7 +363,7 @@ function CustomDateFormat({ dateFormatString, setDateFormatString }: CustomDateF }; const handleReset = () => { - setDateFormatCustom(dateFormatString); + setDateFormatCustom(value); }; const handleSubmit: FormEventHandler = (evt) => { @@ -374,10 +374,10 @@ function CustomDateFormat({ dateFormatString, setDateFormatString }: CustomDateF const format = customDateFormatInput?.value; if (!format) return; - setDateFormatString(format); + onChange(format); }; - const hasChanges = dateFormatCustom !== dateFormatString; + const hasChanges = dateFormatCustom !== value; return ( void; + value: string; + onChange: (format: string) => void; }; -function PresetDateFormat({ dateFormatPreset, handlePresetChange }: PresetDateFormatProps) { +function PresetDateFormat({ value, onChange }: PresetDateFormatProps) { const [menuCords, setMenuCords] = useState(); const dateFormatItems = useDateFormatItems(); + const getDisplayDate = (format: string): string => + format !== '' ? dayjs().format(format) : 'Custom'; + const handleMenu: MouseEventHandler = (evt) => { setMenuCords(evt.currentTarget.getBoundingClientRect()); }; const handleSelect = (format: DateFormat) => { - handlePresetChange(format); + onChange(format); setMenuCords(undefined); }; @@ -467,7 +470,7 @@ function PresetDateFormat({ dateFormatPreset, handlePresetChange }: PresetDateFo onClick={handleMenu} > - {dateFormatItems.find((i) => i.format === dateFormatPreset)?.name ?? dateFormatPreset} + {getDisplayDate(dateFormatItems.find((i) => i.format === value)?.format ?? value)} handleSelect(item.format)} > - {item.name} + {getDisplayDate(item.format)} ))} @@ -512,10 +515,11 @@ function PresetDateFormat({ dateFormatPreset, handlePresetChange }: PresetDateFo function SelectDateFormat() { const [dateFormatString, setDateFormatString] = useSetting(settingsAtom, 'dateFormatString'); - const [dateFormatPreset, setDateFormatPreset] = useState(dateFormatString); + const [selectedDateFormat, setSelectedDateFormat] = useState(dateFormatString); + const customDateFormat = selectedDateFormat === ''; const handlePresetChange = (format: string) => { - setDateFormatPreset(format); + setSelectedDateFormat(format); if (format !== '') { setDateFormatString(format); } @@ -525,19 +529,11 @@ function SelectDateFormat() { <> - } + description={customDateFormat ? dayjs().format(dateFormatString) : ''} + after={} /> - {dateFormatPreset === '' && ( - + {customDateFormat && ( + )} );