diff --git a/web/modals/threads/thread-settings-general-tab.react.js b/web/modals/threads/thread-settings-general-tab.react.js --- a/web/modals/threads/thread-settings-general-tab.react.js +++ b/web/modals/threads/thread-settings-general-tab.react.js @@ -2,36 +2,73 @@ import * as React from 'react'; +import { type SetState } from 'lib/types/hook-types.js'; +import { type ThreadInfo, type ThreadChanges } from 'lib/types/thread-types'; +import { firstLine } from 'lib/utils/string-utils'; + import Input from '../input.react.js'; import ColorSelector from './color-selector.react.js'; import css from './thread-settings-general-tab.css'; type ThreadSettingsGeneralTabProps = { +inputDisabled: boolean, - +threadNameValue: string, + +threadInfo: ThreadInfo, +threadNamePlaceholder: string, - +threadNameOnChange: (event: SyntheticEvent) => void, - +threadDescriptionValue: string, - +threadDescriptionOnChange: ( - event: SyntheticEvent, - ) => void, - +threadColorCurrentColor: string, - +threadColorOnColorSelection: (color: string) => void, + +queuedChanges: ThreadChanges, + +setQueuedChanges: SetState, }; function ThreadSettingsGeneralTab( props: ThreadSettingsGeneralTabProps, ): React.Node { const { inputDisabled, - threadNameValue, + threadInfo, threadNamePlaceholder, - threadNameOnChange, - threadDescriptionValue, - threadDescriptionOnChange, - threadColorCurrentColor, - threadColorOnColorSelection, + queuedChanges, + setQueuedChanges, } = props; + const onChangeName = React.useCallback( + (event: SyntheticEvent) => { + const target = event.currentTarget; + setQueuedChanges( + Object.freeze({ + ...queuedChanges, + name: firstLine( + target.value !== threadInfo.name ? target.value : undefined, + ), + }), + ); + }, + [queuedChanges, setQueuedChanges, threadInfo.name], + ); + + const onChangeDescription = React.useCallback( + (event: SyntheticEvent) => { + const target = event.currentTarget; + setQueuedChanges( + Object.freeze({ + ...queuedChanges, + description: + target.value !== threadInfo.description ? target.value : undefined, + }), + ); + }, + [queuedChanges, setQueuedChanges, threadInfo.description], + ); + + const onChangeColor = React.useCallback( + (color: string) => { + setQueuedChanges( + Object.freeze({ + ...queuedChanges, + color: color !== threadInfo.color ? color : undefined, + }), + ); + }, + [queuedChanges, setQueuedChanges, threadInfo.color], + ); + return (
@@ -39,9 +76,9 @@
@@ -50,9 +87,9 @@
Description