Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Junhao Liao <[email protected]>
  • Loading branch information
davemarco and junhaoliao authored Oct 4, 2024
1 parent a1983d5 commit 03f1670
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
8 changes: 4 additions & 4 deletions new-log-viewer/src/contexts/StateContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,17 @@ 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 [numPages, setNumPages] = useState<number>(STATE_DEFAULT.numPages);
const [pageNum, setPageNum] = useState<number>(STATE_DEFAULT.pageNum);
const beginLineNumToLogEventNumRef =
useRef<BeginLineNumToLogEventNumMap>(STATE_DEFAULT.beginLineNumToLogEventNum);
const [exportProgress, setExportProgress] =
useState<Nullable<number>>(STATE_DEFAULT.exportProgress);

// Refs
const logEventNumRef = useRef(logEventNum);
const numPagesRef = useRef<number>(pageNum);
const pageNumRef = useRef<number>(numPages);
const numPagesRef = useRef<number>(numPages);
const pageNumRef = useRef<number>(pageNum);
const logExportManagerRef = useRef<null|LogExportManager>(null);
const mainWorkerRef = useRef<null|Worker>(null);

Expand All @@ -245,8 +245,8 @@ const StateContextProvider = ({children}: StateContextProviderProps) => {
break;
case WORKER_RESP_CODE.PAGE_DATA: {
setLogData(args.logs);
setPageNum(args.pageNum);
setNumPages(args.numPages);
setPageNum(args.pageNum);
beginLineNumToLogEventNumRef.current = args.beginLineNumToLogEventNum;
updateWindowUrlHashParams({
logEventNum: args.logEventNum,
Expand Down
15 changes: 8 additions & 7 deletions new-log-viewer/src/services/LogFileManager/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,13 @@ const getMatchingLogEventNum = (
return 0;
}

return null !== filteredLogEventMap ?

// Explicit cast since typescript thinks `filteredLogEventMap[matchingIdx]` can be
// undefined, but it can't since filteredLogEventMap has a length >= 1.
(filteredLogEventMap[matchingIdx] as number) + 1 :
matchingIdx + 1;
// Explicit cast since typescript thinks `filteredLogEventMap[matchingIdx]` can be
// undefined, but it can't since filteredLogEventMap has a length >= 1.
return 1 + (
null !== filteredLogEventMap ?
(filteredLogEventMap[matchingIdx] as number) :
matchingIdx
);
};


Expand All @@ -150,8 +151,8 @@ const getMatchingLogEventNum = (
*/
const getNewNumPages = (
numEvents: number,
pageSize: number,
filteredLogEventMap: FilteredLogEventMap,
pageSize: number,
): number => {
const numActiveEvents: number = filteredLogEventMap ?
filteredLogEventMap.length :
Expand Down

0 comments on commit 03f1670

Please sign in to comment.