2022-03-20 08:56:28 +00:00
|
|
|
import { Action, AppViewState } from "./types";
|
|
|
|
|
|
|
|
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(
|
|
|
|
[...state.allPages].map((pageMeta) =>
|
|
|
|
pageMeta.name === action.name
|
|
|
|
? { ...pageMeta, lastOpened: Date.now() }
|
|
|
|
: pageMeta
|
|
|
|
)
|
|
|
|
),
|
|
|
|
currentPage: action.name,
|
|
|
|
};
|
|
|
|
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":
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
showCommandPalette: true,
|
|
|
|
};
|
|
|
|
case "hide-palette":
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
showCommandPalette: false,
|
|
|
|
};
|
|
|
|
case "update-commands":
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
commands: action.commands,
|
|
|
|
};
|
|
|
|
case "show-notification":
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
notifications: [action.notification, ...state.notifications],
|
|
|
|
};
|
|
|
|
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,
|
|
|
|
showRHS: true,
|
|
|
|
rhsHTML: action.html,
|
|
|
|
};
|
|
|
|
case "hide-rhs":
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
showRHS: false,
|
|
|
|
rhsHTML: "",
|
|
|
|
};
|
2022-03-20 08:56:28 +00:00
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|