-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathviewReducer.ts
54 lines (48 loc) · 1.22 KB
/
viewReducer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { store } from 'lib/store';
export const initialState = {view: 'default'};
type ViewParams = { noteId: string; stackIds?: string[], hash?: string };
export interface ViewState {
view: string;
params?: ViewParams;
tag?: string;
}
export type ViewAction =
| { view: 'default' }
| { view: 'chronicle' }
| { view: 'task' }
| { view: 'graph' }
| { view: 'journal' }
| {
view: 'md';
params: ViewParams;
}
| {
view: 'tag';
tag: string;
};
export function viewReducer(state: ViewState, action: ViewAction): ViewState {
const actionView = action.view;
if (actionView === 'md') {
store.getState().setCurrentNoteId(action.params.noteId);
} else {
store.getState().setCurrentNoteId('');
}
switch (actionView) {
case 'default':
return {...state, view: 'default'};
case 'chronicle':
return {...state, view: 'chronicle'};
case 'task':
return {...state, view: 'task'};
case 'graph':
return {...state, view: 'graph'};
case 'journal':
return {...state, view: 'journal'};
case 'md':
return {view: 'md', params: action.params};
case 'tag':
return {view: 'tag', tag: action.tag};
default:
throw new Error();
}
}