diff --git a/app/components/common/preferences-dialog.tsx b/app/components/common/preferences-dialog.tsx index ddcc9d5..eb5f0e3 100644 --- a/app/components/common/preferences-dialog.tsx +++ b/app/components/common/preferences-dialog.tsx @@ -1,4 +1,4 @@ -import { FormEvent, useEffect, useState } from 'react' +import { FormEvent, useCallback, useEffect, useState } from 'react' import { Form } from '@remix-run/react' @@ -63,6 +63,7 @@ import { SITE_THEMES, TOOLBAR_MODES, } from '~/lib/constants' +import { useDebounce } from '~/lib/hooks' import { Theme, useTheme } from '~/lib/providers/theme' import { MusicChannels, @@ -87,82 +88,11 @@ const SavedToastContent = () => ( ) -const Editor = ({ settings }: { settings: SettingsRow }) => { - const { toast } = useToast() - - const handleSubmit = (event: FormEvent) => { - event.preventDefault() - const formData = new FormData(event.currentTarget) - - const showSplashDialog = formData.get('show-splash-dialog') === 'on' - const toolbarMode = formData.get('editor-toolbar-mode') as string - - arls.settings.update(settings.id, { - // @ts-ignore - showSplashDialog, - toolbarMode: S.decodeSync(NonEmptyString100)(toolbarMode), - }) - toast({ - description: , - }) - } - - return ( -
-
-
- - -
- -
- - -
-
-
- -
-
- ) -} - const Appearance = ({ settings }: { settings: SettingsRow }) => { const { theme, setTheme } = useTheme() const { toast } = useToast() - const handleSubmit = (event: FormEvent) => { + const handleChange = (event: FormEvent) => { event.preventDefault() const formData = new FormData(event.currentTarget) @@ -183,7 +113,7 @@ const Appearance = ({ settings }: { settings: SettingsRow }) => { } return ( -
+
-
- -
+
+ ) +} + +const Editor = ({ settings }: { settings: SettingsRow }) => { + const { toast } = useToast() + + const handleChange = (event: FormEvent) => { + event.preventDefault() + const formData = new FormData(event.currentTarget) + + const showSplashDialog = formData.get('show-splash-dialog') === 'on' + const toolbarMode = formData.get('editor-toolbar-mode') as string + + arls.settings.update(settings.id, { + // @ts-ignore + showSplashDialog, + toolbarMode: S.decodeSync(NonEmptyString100)(toolbarMode), + }) + toast({ + description: , + }) + } + + return ( +
+
+
+ + +
+ +
+ + +
+
) } const Writing = ({ settings }: { settings: SettingsRow }) => { - const [dailyGoalType, setDailyGoalType] = useState(DAILY_GOAL_TYPE[0].value) + const [dailyGoalType, setDailyGoalType] = useState( + settings.writingDailyGoal || DAILY_GOAL_TYPE[0].value + ) const { toast } = useToast() - const handleSubmit = (event: FormEvent) => { + const saveFormData = ( + writingDailyGoal: string, + writingDailyTarget: number + ) => { + arls.settings.update(settings.id, { + writingDailyGoal: S.decodeSync(NonEmptyString100)(writingDailyGoal), + writingDailyTarget: S.decodeSync(Int)(writingDailyTarget), + }) + toast({ + description: , + }) + } + + const debouncedSaveFormData = useDebounce(saveFormData, 1000) + + const handleChange = (event: FormEvent) => { event.preventDefault() + const target = event.target as HTMLInputElement | HTMLSelectElement + const { type } = target const formData = new FormData(event.currentTarget) const writingDailyGoal = formData.get( @@ -292,17 +302,15 @@ const Writing = ({ settings }: { settings: SettingsRow }) => { ? parseInt(formData.get('daily-goal-duration') as string, 10) : parseInt(formData.get('daily-goal-word-count') as string, 10) - arls.settings.update(settings.id, { - writingDailyGoal: S.decodeSync(NonEmptyString100)(writingDailyGoal), - writingDailyTarget: S.decodeSync(Int)(writingDailyTarget), - }) - toast({ - description: , - }) + if (type === 'number') { + debouncedSaveFormData(writingDailyGoal, writingDailyTarget) + } else { + saveFormData(writingDailyGoal, writingDailyTarget) + } } return ( -
+
{ type='text' />
-
- -
) } @@ -763,9 +776,6 @@ const Advanced = () => { {/* */} {/**/}
-

- Danger Zone -