-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathcreateViewFormattingSlice.ts
More file actions
109 lines (91 loc) · 3.2 KB
/
Copy pathcreateViewFormattingSlice.ts
File metadata and controls
109 lines (91 loc) · 3.2 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import {StateCreator} from "zustand";
import {DEFAULT_TIMEZONE_NAME} from "../../typings/date";
import {UI_STATE} from "../../typings/states";
import {
CURSOR_CODE,
CursorType,
} from "../../typings/worker";
import useLogFileManagerStore from "../logFileManagerProxyStore";
import useLogFileStore from "../logFileStore";
import {handleErrorWithNotification} from "../notificationStore";
import useUiStore from "../uiStore";
import {VIEW_EVENT_DEFAULT} from "./createViewEventSlice";
import {
ViewFormattingSlice,
ViewFormattingValues,
ViewState,
} from "./types";
const VIEW_FORMATTING_DEFAULT: ViewFormattingValues = {
isPrettified: false,
timezoneName: DEFAULT_TIMEZONE_NAME,
};
/**
* Creates a slice for managing log formatting state.
*
* @param set
* @param get
* @return
*/
const createViewFormattingSlice: StateCreator<
ViewState, [], [], ViewFormattingSlice
> = (set, get) => ({
...VIEW_FORMATTING_DEFAULT,
updateIsPrettified: (newIsPrettified: boolean) => {
const {isPrettified} = get();
if (newIsPrettified === isPrettified) {
return;
}
const {setUiState} = useUiStore.getState();
setUiState(UI_STATE.FAST_LOADING);
set({isPrettified: newIsPrettified});
const {logEventNum} = get();
let cursor: CursorType = {code: CURSOR_CODE.LAST_EVENT, args: null};
if (VIEW_EVENT_DEFAULT.logEventNum !== logEventNum) {
cursor = {
code: CURSOR_CODE.EVENT_NUM,
args: {eventNum: logEventNum},
};
}
(async () => {
const {logFileManagerProxy} = useLogFileManagerStore.getState();
const pageData = await logFileManagerProxy.loadPage(cursor, newIsPrettified);
const {updatePageData} = get();
updatePageData(pageData);
})().catch(handleErrorWithNotification);
},
updateTimezoneName: (newTimezoneName: string) => {
if ("" === newTimezoneName) {
newTimezoneName = DEFAULT_TIMEZONE_NAME;
}
const {numEvents} = useLogFileStore.getState();
if (0 === numEvents) {
return;
}
const {timezoneName} = get();
if (newTimezoneName === timezoneName) {
return;
}
const {setUiState} = useUiStore.getState();
setUiState(UI_STATE.FAST_LOADING);
set({timezoneName: newTimezoneName});
const {logEventNum} = get();
let cursor: CursorType = {code: CURSOR_CODE.LAST_EVENT, args: null};
if (VIEW_EVENT_DEFAULT.logEventNum !== logEventNum) {
cursor = {
code: CURSOR_CODE.EVENT_NUM,
args: {eventNum: logEventNum},
};
}
(async () => {
const {logFileManagerProxy} = useLogFileManagerStore.getState();
const {isPrettified, updatePageData} = get();
// await logFileManagerProxy.setTimezone(newTimezoneName);
const pageData = await logFileManagerProxy.loadPage(
cursor,
isPrettified,
);
updatePageData(pageData);
})().catch(handleErrorWithNotification);
},
});
export default createViewFormattingSlice;