Skip to content

Commit

Permalink
Add Redux for completed ReviewEntries edits
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec committed Nov 6, 2023
1 parent 93866e5 commit a25f160
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/components/GoalTimeline/Redux/GoalActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import router from "browserRouter";
import {
addCharInvChangesToGoalAction,
addCompletedMergeToGoalAction,
addEntryEditToGoalAction,
incrementGoalStepAction,
loadUserEditsAction,
setCurrentGoalAction,
Expand All @@ -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";
Expand All @@ -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);
}
Expand Down
20 changes: 20 additions & 0 deletions src/components/GoalTimeline/Redux/GoalReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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++;
Expand Down Expand Up @@ -81,6 +100,7 @@ const goalSlice = createSlice({
export const {
addCharInvChangesToGoalAction,
addCompletedMergeToGoalAction,
addEntryEditToGoalAction,
incrementGoalStepAction,
loadUserEditsAction,
setCurrentGoalAction,
Expand Down
9 changes: 9 additions & 0 deletions src/goals/ReviewEntries/ReviewEntries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function updateAllWords(words: ReviewEntriesWord[]): ReviewUpdateWords {
};
}

// TODO: also dispatch(addEntryEditToGoal({newId: updatedWord.id, oldId}))
function updateWord(
oldId: string,
updatedWord: ReviewEntriesWord
Expand Down
3 changes: 2 additions & 1 deletion src/types/goals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, never> is the recommended type for an empty object.
export type GoalStep = CharInvStepData | MergeStepData | Record<string, never>;
export type GoalChanges = CharInvChanges | MergesCompleted;
export type GoalChanges = CharInvChanges | EntriesEdited | MergesCompleted;

export interface GoalProps {
goal?: Goal;
Expand Down

0 comments on commit a25f160

Please sign in to comment.