-
Notifications
You must be signed in to change notification settings - Fork 19
refactor: Create async function loadPageByCursor
for code reduction; Centralize uiState
change in loadPageByCursor
(fixes #355).
#367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9884088
54c3b8a
4e33a08
64819e0
d7d2885
9d98718
55f0a32
45292a3
6d60177
8d679ca
466b4f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,16 +92,6 @@ const createViewPageSlice: StateCreator< | |
ViewState, [], [], ViewPageSlice | ||
> = (set, get) => ({ | ||
...VIEW_PAGE_DEFAULT, | ||
updatePageData: (pageData: PageData) => { | ||
set({ | ||
beginLineNumToLogEventNum: pageData.beginLineNumToLogEventNum, | ||
logData: pageData.logs, | ||
logEventNum: pageData.logEventNum, | ||
numPages: pageData.numPages, | ||
pageNum: pageData.pageNum, | ||
}); | ||
updateWindowUrlHashParams({logEventNum: pageData.logEventNum}); | ||
}, | ||
loadPageByAction: (navAction: NavigationAction) => { | ||
if (navAction.code === ACTION_NAME.RELOAD) { | ||
const {fileSrc, loadFile} = useLogFileStore.getState(); | ||
|
@@ -113,37 +103,55 @@ const createViewPageSlice: StateCreator< | |
)}, logEventNum=${logEventNum} when reloading.` | ||
); | ||
} | ||
loadFile(fileSrc, { | ||
code: CURSOR_CODE.EVENT_NUM, | ||
args: {eventNum: logEventNum}, | ||
}); | ||
(async () => { | ||
await loadFile(fileSrc); | ||
const {loadPageByCursor} = get(); | ||
await loadPageByCursor({ | ||
code: CURSOR_CODE.EVENT_NUM, | ||
args: {eventNum: logEventNum}, | ||
}); | ||
})().catch(handleErrorWithNotification); | ||
|
||
return; | ||
} | ||
|
||
const {uiState, setUiState} = useUiStore.getState(); | ||
const {uiState} = useUiStore.getState(); | ||
if (UI_STATE.READY !== uiState) { | ||
console.warn("Skipping navigation: page load in progress."); | ||
|
||
return; | ||
} | ||
setUiState(UI_STATE.FAST_LOADING); | ||
|
||
const {numPages, pageNum} = get(); | ||
const {numPages, pageNum, loadPageByCursor} = get(); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const cursor = getPageNumCursor(navAction, pageNum, numPages); | ||
if (null === cursor) { | ||
console.error(`Error with nav action ${navAction.code}.`); | ||
|
||
return; | ||
} | ||
loadPageByCursor(cursor).catch(handleErrorWithNotification); | ||
}, | ||
Henry8192 marked this conversation as resolved.
Show resolved
Hide resolved
Henry8192 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
loadPageByCursor: async (cursor: CursorType) => { | ||
const {setUiState} = useUiStore.getState(); | ||
setUiState(UI_STATE.FAST_LOADING); | ||
|
||
(async () => { | ||
try { | ||
const {logFileManagerProxy} = useLogFileManagerStore.getState(); | ||
const pageData = await logFileManagerProxy.loadPage(cursor); | ||
const {updatePageData} = get(); | ||
updatePageData(pageData); | ||
} finally { | ||
setUiState(UI_STATE.READY); | ||
})().catch(handleErrorWithNotification); | ||
} | ||
Comment on lines
+137
to
+144
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably should remove this try - finally There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one is actually coderabbitai's suggestion: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make sense. Even though I feel there might be better solutions than try-finally, let's merge this for now. |
||
}, | ||
updatePageData: (pageData: PageData) => { | ||
set({ | ||
beginLineNumToLogEventNum: pageData.beginLineNumToLogEventNum, | ||
logData: pageData.logs, | ||
logEventNum: pageData.logEventNum, | ||
numPages: pageData.numPages, | ||
pageNum: pageData.pageNum, | ||
}); | ||
updateWindowUrlHashParams({logEventNum: pageData.logEventNum}); | ||
}, | ||
Henry8192 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.