From a25f160eb93ad3a1bed89cdf6ed7784e85eaf1e7 Mon Sep 17 00:00:00 2001 From: Danny Rorabaugh Date: Wed, 25 Oct 2023 11:12:33 -0400 Subject: [PATCH] Add Redux for completed ReviewEntries edits --- .../GoalTimeline/Redux/GoalActions.ts | 6 ++++++ .../GoalTimeline/Redux/GoalReducer.ts | 20 +++++++++++++++++++ src/goals/ReviewEntries/ReviewEntries.ts | 9 +++++++++ .../Redux/ReviewEntriesActions.ts | 1 + src/types/goals.ts | 3 ++- 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/components/GoalTimeline/Redux/GoalActions.ts b/src/components/GoalTimeline/Redux/GoalActions.ts index 66db597cc0..e583c63cb6 100644 --- a/src/components/GoalTimeline/Redux/GoalActions.ts +++ b/src/components/GoalTimeline/Redux/GoalActions.ts @@ -8,6 +8,7 @@ import router from "browserRouter"; import { addCharInvChangesToGoalAction, addCompletedMergeToGoalAction, + addEntryEditToGoalAction, incrementGoalStepAction, loadUserEditsAction, setCurrentGoalAction, @@ -17,6 +18,7 @@ import { } from "components/GoalTimeline/Redux/GoalReducer"; import { CharacterChange } from "goals/CharacterInventory/CharacterInventoryTypes"; import { dispatchMergeStepData } from "goals/MergeDuplicates/Redux/MergeDupsActions"; +import { EntryEdit } from "goals/ReviewEntries/ReviewEntries"; import { StoreState } from "types"; import { StoreStateDispatch } from "types/Redux/actions"; import { Goal, GoalStatus, GoalType } from "types/goals"; @@ -31,6 +33,10 @@ export function addCharInvChangesToGoal( return addCharInvChangesToGoalAction(charChanges); } +export function addEntryEditToGoal(entryEdit: EntryEdit): PayloadAction { + return addEntryEditToGoalAction(entryEdit); +} + export function addCompletedMergeToGoal(changes: MergeUndoIds): PayloadAction { return addCompletedMergeToGoalAction(changes); } diff --git a/src/components/GoalTimeline/Redux/GoalReducer.ts b/src/components/GoalTimeline/Redux/GoalReducer.ts index 2632f2f400..44915b3725 100644 --- a/src/components/GoalTimeline/Redux/GoalReducer.ts +++ b/src/components/GoalTimeline/Redux/GoalReducer.ts @@ -5,6 +5,7 @@ import { MergeDupsData, MergesCompleted, } from "goals/MergeDuplicates/MergeDupsTypes"; +import { EntriesEdited, EntryEdit } from "goals/ReviewEntries/ReviewEntries"; import { StoreActionTypes } from "rootActions"; import { GoalType } from "types/goals"; @@ -30,6 +31,24 @@ const goalSlice = createSlice({ state.currentGoal.changes = changes; } }, + addEntryEditToGoalAction: (state, action) => { + if (state.currentGoal.goalType === GoalType.ReviewEntries) { + const changes = { ...state.currentGoal.changes } as EntriesEdited; + if (!changes.entryEdits) { + changes.entryEdits = []; + } + const newEdit = action.payload as EntryEdit; + const oldEdit = changes.entryEdits.find( + (e) => e.newId === newEdit.oldId + ); + if (oldEdit) { + oldEdit.newId = newEdit.newId; + } else { + changes.entryEdits.push(newEdit); + } + state.currentGoal.changes = changes; + } + }, incrementGoalStepAction: (state) => { if (state.currentGoal.currentStep + 1 < state.currentGoal.numSteps) { state.currentGoal.currentStep++; @@ -81,6 +100,7 @@ const goalSlice = createSlice({ export const { addCharInvChangesToGoalAction, addCompletedMergeToGoalAction, + addEntryEditToGoalAction, incrementGoalStepAction, loadUserEditsAction, setCurrentGoalAction, diff --git a/src/goals/ReviewEntries/ReviewEntries.ts b/src/goals/ReviewEntries/ReviewEntries.ts index efd3a26cf2..d51fefbfdd 100644 --- a/src/goals/ReviewEntries/ReviewEntries.ts +++ b/src/goals/ReviewEntries/ReviewEntries.ts @@ -5,3 +5,12 @@ export class ReviewEntries extends Goal { super(GoalType.ReviewEntries, GoalName.ReviewEntries); } } + +export type EntryEdit = { + newId: string; + oldId: string; +}; + +export interface EntriesEdited { + entryEdits: EntryEdit[]; +} diff --git a/src/goals/ReviewEntries/ReviewEntriesComponent/Redux/ReviewEntriesActions.ts b/src/goals/ReviewEntries/ReviewEntriesComponent/Redux/ReviewEntriesActions.ts index e13dc1f781..cee09a7570 100644 --- a/src/goals/ReviewEntries/ReviewEntriesComponent/Redux/ReviewEntriesActions.ts +++ b/src/goals/ReviewEntries/ReviewEntriesComponent/Redux/ReviewEntriesActions.ts @@ -30,6 +30,7 @@ export function updateAllWords(words: ReviewEntriesWord[]): ReviewUpdateWords { }; } +// TODO: also dispatch(addEntryEditToGoal({newId: updatedWord.id, oldId})) function updateWord( oldId: string, updatedWord: ReviewEntriesWord diff --git a/src/types/goals.ts b/src/types/goals.ts index 0a7e995780..8935d38af6 100644 --- a/src/types/goals.ts +++ b/src/types/goals.ts @@ -11,12 +11,13 @@ import { MergeStepData, MergesCompleted, } from "goals/MergeDuplicates/MergeDupsTypes"; +import { EntriesEdited } from "goals/ReviewEntries/ReviewEntries"; import { newUser } from "types/user"; export type GoalData = CharInvData | MergeDupsData; // Record is the recommended type for an empty object. export type GoalStep = CharInvStepData | MergeStepData | Record; -export type GoalChanges = CharInvChanges | MergesCompleted; +export type GoalChanges = CharInvChanges | EntriesEdited | MergesCompleted; export interface GoalProps { goal?: Goal;