2022-02-21 12:25:41 +00:00
|
|
|
import { Action, AppViewState } from "./types";
|
|
|
|
|
2022-02-22 13:18:37 +00:00
|
|
|
export default function reducer(
|
|
|
|
state: AppViewState,
|
|
|
|
action: Action
|
|
|
|
): AppViewState {
|
|
|
|
console.log("Got action", action);
|
2022-02-21 12:25:41 +00:00
|
|
|
switch (action.type) {
|
2022-02-22 13:18:37 +00:00
|
|
|
case "note-loaded":
|
2022-02-21 12:25:41 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
currentNote: action.name,
|
|
|
|
isSaved: true,
|
|
|
|
};
|
2022-02-22 13:18:37 +00:00
|
|
|
case "note-saved":
|
2022-02-21 12:25:41 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
isSaved: true,
|
|
|
|
};
|
2022-02-22 13:18:37 +00:00
|
|
|
case "note-updated":
|
|
|
|
// Minor rerender optimization, this is triggered a lot
|
|
|
|
if (!state.isSaved) {
|
|
|
|
return state;
|
|
|
|
}
|
2022-02-21 12:25:41 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
isSaved: false,
|
|
|
|
};
|
|
|
|
case "start-navigate":
|
|
|
|
return {
|
|
|
|
...state,
|
2022-02-22 13:18:37 +00:00
|
|
|
showNoteNavigator: true,
|
2022-02-21 12:25:41 +00:00
|
|
|
};
|
|
|
|
case "stop-navigate":
|
|
|
|
return {
|
|
|
|
...state,
|
2022-02-22 13:18:37 +00:00
|
|
|
showNoteNavigator: false,
|
2022-02-21 12:25:41 +00:00
|
|
|
};
|
2022-02-22 13:18:37 +00:00
|
|
|
case "notes-listed":
|
2022-02-21 12:25:41 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
allNotes: action.notes,
|
|
|
|
};
|
2022-02-22 13:18:37 +00:00
|
|
|
case "show-palette":
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
showCommandPalette: true,
|
|
|
|
};
|
|
|
|
case "hide-palette":
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
showCommandPalette: false,
|
|
|
|
};
|
2022-02-21 12:25:41 +00:00
|
|
|
}
|
2022-02-22 13:18:37 +00:00
|
|
|
return state;
|
|
|
|
}
|