2022-04-05 15:02:17 +00:00
|
|
|
import { Action, AppViewState } from "./types";
|
2022-03-20 08:56:28 +00:00
|
|
|
|
2022-05-13 12:36:26 +00:00
|
|
|
let m = new Map();
|
|
|
|
m.size;
|
|
|
|
|
2022-03-20 08:56:28 +00:00
|
|
|
export default function reducer(
|
|
|
|
state: AppViewState,
|
|
|
|
action: Action
|
|
|
|
): AppViewState {
|
|
|
|
// console.log("Got action", action);
|
|
|
|
switch (action.type) {
|
|
|
|
case "page-loaded":
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
allPages: new Set(
|
2022-03-31 15:25:34 +00:00
|
|
|
[...state.allPages].map((pageMeta) =>
|
2022-05-17 09:53:17 +00:00
|
|
|
pageMeta.name === action.meta.name
|
2022-03-31 15:25:34 +00:00
|
|
|
? { ...pageMeta, lastOpened: Date.now() }
|
|
|
|
: pageMeta
|
|
|
|
)
|
2022-03-20 08:56:28 +00:00
|
|
|
),
|
2022-05-17 09:53:17 +00:00
|
|
|
perm: action.meta.perm,
|
|
|
|
currentPage: action.meta.name,
|
2022-03-20 08:56:28 +00:00
|
|
|
};
|
2022-03-31 12:28:07 +00:00
|
|
|
case "page-changed":
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
unsavedChanges: true,
|
|
|
|
};
|
|
|
|
case "page-saved":
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
unsavedChanges: false,
|
|
|
|
};
|
2022-03-20 08:56:28 +00:00
|
|
|
case "start-navigate":
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
showPageNavigator: true,
|
|
|
|
};
|
|
|
|
case "stop-navigate":
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
showPageNavigator: false,
|
|
|
|
};
|
|
|
|
case "pages-listed":
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
allPages: action.pages,
|
|
|
|
};
|
|
|
|
case "show-palette":
|
2022-04-21 09:46:33 +00:00
|
|
|
let commands = new Map(state.commands);
|
|
|
|
for (let [k, v] of state.commands.entries()) {
|
|
|
|
if (
|
|
|
|
v.command.contexts &&
|
|
|
|
(!action.context || !v.command.contexts.includes(action.context))
|
|
|
|
) {
|
|
|
|
commands.delete(k);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
commands,
|
2022-03-20 08:56:28 +00:00
|
|
|
showCommandPalette: true,
|
|
|
|
};
|
|
|
|
case "hide-palette":
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
showCommandPalette: false,
|
|
|
|
};
|
2022-05-16 13:09:36 +00:00
|
|
|
case "command-run":
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
recentCommands: state.recentCommands.set(action.command, new Date()),
|
|
|
|
};
|
2022-03-20 08:56:28 +00:00
|
|
|
case "update-commands":
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
commands: action.commands,
|
|
|
|
};
|
|
|
|
case "show-notification":
|
|
|
|
return {
|
|
|
|
...state,
|
2022-05-09 12:59:12 +00:00
|
|
|
notifications: [...state.notifications, action.notification],
|
2022-03-20 08:56:28 +00:00
|
|
|
};
|
|
|
|
case "dismiss-notification":
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
notifications: state.notifications.filter((n) => n.id !== action.id),
|
|
|
|
};
|
2022-03-28 13:25:05 +00:00
|
|
|
case "show-rhs":
|
|
|
|
return {
|
|
|
|
...state,
|
2022-04-04 16:33:13 +00:00
|
|
|
showRHS: action.flex,
|
2022-03-28 13:25:05 +00:00
|
|
|
rhsHTML: action.html,
|
2022-05-09 12:59:12 +00:00
|
|
|
rhsScript: action.script,
|
2022-03-28 13:25:05 +00:00
|
|
|
};
|
|
|
|
case "hide-rhs":
|
|
|
|
return {
|
|
|
|
...state,
|
2022-04-04 16:33:13 +00:00
|
|
|
showRHS: 0,
|
2022-03-28 13:25:05 +00:00
|
|
|
rhsHTML: "",
|
2022-05-09 12:59:12 +00:00
|
|
|
rhsScript: undefined,
|
2022-03-28 13:25:05 +00:00
|
|
|
};
|
2022-04-04 16:33:13 +00:00
|
|
|
case "show-lhs":
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
showLHS: action.flex,
|
|
|
|
lhsHTML: action.html,
|
2022-05-09 12:59:12 +00:00
|
|
|
lhsScript: action.script,
|
2022-04-04 16:33:13 +00:00
|
|
|
};
|
|
|
|
case "hide-lhs":
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
showLHS: 0,
|
|
|
|
lhsHTML: "",
|
2022-05-09 12:59:12 +00:00
|
|
|
lhsScript: undefined,
|
2022-04-04 16:33:13 +00:00
|
|
|
};
|
2022-04-26 17:04:36 +00:00
|
|
|
case "show-bhs":
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
showBHS: action.flex,
|
|
|
|
bhsHTML: action.html,
|
2022-05-09 12:59:12 +00:00
|
|
|
bhsScript: action.script,
|
2022-04-26 17:04:36 +00:00
|
|
|
};
|
|
|
|
case "hide-bhs":
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
showBHS: 0,
|
|
|
|
bhsHTML: "",
|
2022-05-09 12:59:12 +00:00
|
|
|
bhsScript: undefined,
|
2022-04-26 17:04:36 +00:00
|
|
|
};
|
2022-04-13 12:46:52 +00:00
|
|
|
case "show-filterbox":
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
showFilterBox: true,
|
|
|
|
filterBoxOnSelect: action.onSelect,
|
|
|
|
filterBoxPlaceHolder: action.placeHolder,
|
|
|
|
filterBoxOptions: action.options,
|
2022-04-21 09:46:33 +00:00
|
|
|
filterBoxLabel: action.label,
|
2022-04-13 12:46:52 +00:00
|
|
|
filterBoxHelpText: action.helpText,
|
|
|
|
};
|
|
|
|
case "hide-filterbox":
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
showFilterBox: false,
|
|
|
|
filterBoxOnSelect: () => {},
|
|
|
|
filterBoxPlaceHolder: "",
|
|
|
|
filterBoxOptions: [],
|
|
|
|
filterBoxHelpText: "",
|
|
|
|
};
|
2022-03-20 08:56:28 +00:00
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|