diff --git a/src/components/Explanations/index.tsx b/src/components/Explanations/index.tsx index 848e895..7b03aed 100644 --- a/src/components/Explanations/index.tsx +++ b/src/components/Explanations/index.tsx @@ -98,7 +98,7 @@ export const Explanations: FunctionComponent = ({ initialData }) => { text={e.text} unselect={() => { changeSelected(null) }} onUpdate={(text) => { - updateExplanation(e.index, text, e.position) + updateExplanation(e.index, text, e.position, e.id) }} /> diff --git a/src/fetch/question.ts b/src/fetch/question.ts index f95f8ae..b8a2c59 100644 --- a/src/fetch/question.ts +++ b/src/fetch/question.ts @@ -10,6 +10,7 @@ interface SubmitPayload { apps: App[], } explanations: { + id?: number; position: string; text: string; } @@ -101,7 +102,9 @@ export const useSubmit = () => { fieldOfWork: selectedFieldsOfWork }, explanations: explanations.map((e) => { + console.log(e) return { + id: e.id, position: e.position + '', index: e.index + '', text: e.text diff --git a/src/store/slices/explanation.ts b/src/store/slices/explanation.ts index 2cb156f..b86e6e6 100644 --- a/src/store/slices/explanation.ts +++ b/src/store/slices/explanation.ts @@ -4,6 +4,7 @@ export interface Explanation { index: number; text?: string; position?: number; + id?: number; } export interface ExplanationsSlice { @@ -13,7 +14,7 @@ export interface ExplanationsSlice { explanationIndex: number; addExplanation: (index: number, text?: string, position?: number) => void setInitialExplanations: (explanations: Explanation[]) => void - updateExplanation: (index: number, text: string, position?: number) => void + updateExplanation: (index: number, text: string, position?: number, id?: number) => void updateExplanations: (explanations: Explanation[]) => void deleteExplanation: (index: number) => void deleteExplanations: (componentId: number, componentType: string) => void @@ -73,11 +74,11 @@ export const createExplanationsSlice: StateCreator< explanations: state.explanations.filter(e => !toDelete.includes(+e.index)) })) }, - updateExplanation: (index, text, position) => { + updateExplanation: (index, text, position, id) => { let oldExplanations = get().explanations.filter(e => e.index !== index) const explanations = [ ...oldExplanations, - { index: index, text: text, position: position} + { id, index: index, text: text, position: position} ].sort((a, b) => a.position - b.position) set((state) => ({