diff --git a/client/src/components/DashboardPage/DecisionSupportFilePanel.tsx b/client/src/components/DashboardPage/DecisionSupportFilePanel.tsx index cf3c80b..1fa31e8 100644 --- a/client/src/components/DashboardPage/DecisionSupportFilePanel.tsx +++ b/client/src/components/DashboardPage/DecisionSupportFilePanel.tsx @@ -3,11 +3,11 @@ import { DecisionSupportFile, DecisionSupportFileStatus } from '../../types/deci import { ItemPanel, TabDefinition, Item } from './ItemPanel'; import { useUserProfile } from '../../gql/queries/profile'; import { inWorkgroup } from '../../types/workgroup'; -import { useDecisions } from '../../gql/queries/decisions'; +import { useDecisionSupportFiles } from '../../gql/queries/dsf'; export function DecisionSupportFilePanel() { const { user } = useUserProfile(); - const { decisions } = useDecisions(); + const { decisionSupportFiles } = useDecisionSupportFiles(); const tabs: TabDefinition[] = [ { @@ -31,9 +31,9 @@ export function DecisionSupportFilePanel() { return ( item.id} diff --git a/client/src/components/DecisionSupportFilePage/ClarificationSection.tsx b/client/src/components/DecisionSupportFilePage/ClarificationSection.tsx index 5683bc6..264dfbc 100644 --- a/client/src/components/DecisionSupportFilePage/ClarificationSection.tsx +++ b/client/src/components/DecisionSupportFilePage/ClarificationSection.tsx @@ -1,23 +1,35 @@ import React, { FunctionComponent, useState, ChangeEvent, useEffect } from 'react'; import { DecisionSupportFileUpdaterProps } from './DecisionSupportFileUpdaterProps'; +import { useDebounce } from '../../hooks/useDebounce'; +import { asDate } from '../../util/date'; export interface ClarificationSectionProps extends DecisionSupportFileUpdaterProps {}; const ClarificationSectionName = 'clarification'; export const ClarificationSection: FunctionComponent = ({ dsf, updateDSF }) => { - const [ section, setSection ] = useState({ - objectives: '', - motivations: '', - scope: '', - nature: '', - deadline: undefined, - hasDeadline: false, + const [ state, setState ] = useState({ + changed: false, + section: { + objectives: '', + motivations: '', + scope: '', + nature: '', + deadline: undefined, + hasDeadline: false, + } }); useEffect(() => { - updateDSF({ ...dsf, sections: { ...dsf.sections, [ClarificationSectionName]: { ...section }} }) - }, [section]); + if (!state.changed) return; + updateDSF({ ...dsf, sections: { ...dsf.sections, [ClarificationSectionName]: { ...state.section }} }) + setState(state => ({ ...state, changed: false })); + }, [state.changed]); + + useEffect(() => { + if (!dsf.sections[ClarificationSectionName]) return; + setState(state => ({ ...state, changed: false, section: {...state.section, ...dsf.sections[ClarificationSectionName] }})); + }, [dsf.sections[ClarificationSectionName]]); const onTitleChange = (evt: ChangeEvent) => { const title = (evt.currentTarget).value; @@ -27,12 +39,12 @@ export const ClarificationSection: FunctionComponent const onSectionAttrChange = (attrName: string, evt: ChangeEvent) => { const target = evt.currentTarget; const value = target.hasOwnProperty('checked') ? target.checked : target.value; - setSection(section => ({ ...section, [attrName]: value })); + setState(state => ({ ...state, changed: true, section: {...state.section, [attrName]: value }})); }; const onDeadlineChange = (evt: ChangeEvent) => { const deadline = evt.currentTarget.valueAsDate; - setSection(section => ({ ...section, deadline })); + setState(state => ({ ...state, changed: true, section: { ...state.section, deadline }})); }; return ( @@ -48,7 +60,7 @@ export const ClarificationSection: FunctionComponent