Skip to content

Commit

Permalink
change pageNum to useState to fix pageNum occasionaly not updating wh…
Browse files Browse the repository at this point in the history
…en manually chaning log event
  • Loading branch information
davemarco committed Oct 1, 2024
1 parent 8d38166 commit 81389df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 5 additions & 4 deletions new-log-viewer/src/contexts/StateContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ const StateContextProvider = ({children}: StateContextProviderProps) => {
const [fileName, setFileName] = useState<string>(STATE_DEFAULT.fileName);
const [logData, setLogData] = useState<string>(STATE_DEFAULT.logData);
const [numEvents, setNumEvents] = useState<number>(STATE_DEFAULT.numEvents);
const [pageNum, setPageNum] = useState<number>(STATE_DEFAULT.pageNum);
const beginLineNumToLogEventNumRef =
useRef<BeginLineNumToLogEventNumMap>(STATE_DEFAULT.beginLineNumToLogEventNum);
const [exportProgress, setExportProgress] =
Expand All @@ -194,7 +195,7 @@ const StateContextProvider = ({children}: StateContextProviderProps) => {
// Refs
const logEventNumRef = useRef(logEventNum);
const numPagesRef = useRef<number>(STATE_DEFAULT.numPages);
const pageNumRef = useRef<number>(STATE_DEFAULT.pageNum);

const logExportManagerRef = useRef<null|LogExportManager>(null);
const mainWorkerRef = useRef<null|Worker>(null);

Expand All @@ -220,7 +221,7 @@ const StateContextProvider = ({children}: StateContextProviderProps) => {
break;
case WORKER_RESP_CODE.PAGE_DATA: {
setLogData(args.logs);
pageNumRef.current = args.pageNum;
setPageNum(args.pageNum)

Check failure on line 224 in new-log-viewer/src/contexts/StateContextProvider.tsx

View workflow job for this annotation

GitHub Actions / lint-check

Missing semicolon
beginLineNumToLogEventNumRef.current = args.beginLineNumToLogEventNum;
updateWindowUrlHashParams({
logEventNum: args.logEventNum,
Expand Down Expand Up @@ -289,7 +290,7 @@ const StateContextProvider = ({children}: StateContextProviderProps) => {

return;
}
const cursor = getPageNumCursor(navAction, pageNumRef.current, numPagesRef.current);
const cursor = getPageNumCursor(navAction, pageNum, numPagesRef.current);
if (null === cursor) {
console.error(`Error with nav action ${navAction.code}.`);

Expand Down Expand Up @@ -381,7 +382,7 @@ const StateContextProvider = ({children}: StateContextProviderProps) => {
logData: logData,
numEvents: numEvents,
numPages: numPagesRef.current,
pageNum: pageNumRef.current,
pageNum: pageNum,

exportLogs: exportLogs,
loadFile: loadFile,
Expand Down
7 changes: 6 additions & 1 deletion new-log-viewer/src/services/LogFileManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,12 @@ class LogFileManager {
matchingLogEventNum,
} = this.#getCursorData(cursor);

const results = this.#decoder.decodeRange(pageBeginLogEventNum - 1, pageEndLogEventNum - 1, false);
const results = this.#decoder.decodeRange(
pageBeginLogEventNum - 1,
pageEndLogEventNum - 1,
false
);

if (null === results) {
throw new Error("Error occurred during decoding. " +
`pageBeginLogEventNum=${pageBeginLogEventNum}, ` +
Expand Down

0 comments on commit 81389df

Please sign in to comment.