Skip to content

Commit

Permalink
second fix for bouncing
Browse files Browse the repository at this point in the history
  • Loading branch information
davemarco committed Sep 7, 2024
1 parent fdf2af4 commit 2c4d735
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions new-log-viewer/src/contexts/StateContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,26 @@ const StateContextProvider = ({children}: StateContextProviderProps) => {
const {filePath, logEventNum} = useContext(UrlContext);

const [fileName, setFileName] = useState<string>(STATE_DEFAULT.fileName);
const [firstLogEventNumPerPage, setFirstLogEventNumPerPage] =
useState<number[]>(STATE_DEFAULT.firstLogEventNumPerPage);
const [lastLogEventNumPerPage, setLastLogEventNumPerPage] =
useState<number[]>(STATE_DEFAULT.lastLogEventNumPerPage);

const [logData, setLogData] = useState<string>(STATE_DEFAULT.logData);
const [numEvents, setNumEvents] = useState<number>(STATE_DEFAULT.numEvents);
const [numFilteredEvents, setNumFilteredEvents] =
useState<number>(STATE_DEFAULT.numFilteredEvents);

const beginLineNumToLogEventNumRef =
useRef<BeginLineNumToLogEventNumMap>(STATE_DEFAULT.beginLineNumToLogEventNum);
const logEventNumRef = useRef(logEventNum);
const logLevelFilterRef = useRef<LogLevelFilter>(STATE_DEFAULT.logLevelFilter);
const numPagesRef = useRef<number>(STATE_DEFAULT.numPages);
const pageNumRef = useRef<Nullable<number>>(STATE_DEFAULT.pageNum);

const firstLogEventNumPerPage =
useRef<number[]>(STATE_DEFAULT.firstLogEventNumPerPage);
const lastLogEventNumPerPage =
useRef<number[]>(STATE_DEFAULT.lastLogEventNumPerPage);
const numFilteredEvents =
useRef<number>(STATE_DEFAULT.numFilteredEvents);



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

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

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

new-log-viewer/src/contexts/StateContextProvider.tsx#L166-L167

[@stylistic/js/no-multiple-empty-lines] More than 2 blank lines not allowed.

const handleMainWorkerResp = useCallback((ev: MessageEvent<MainWorkerRespMessage>) => {
Expand All @@ -179,6 +184,7 @@ const StateContextProvider = ({children}: StateContextProviderProps) => {
setLogData(args.logs);
beginLineNumToLogEventNumRef.current = args.beginLineNumToLogEventNum;
const lastLogEventNum = getLastLogEventNum(args.beginLineNumToLogEventNum);

updateLogEventNumInUrl(
lastLogEventNum,
Array.from(args.beginLineNumToLogEventNum.values())
Expand All @@ -189,9 +195,9 @@ const StateContextProvider = ({children}: StateContextProviderProps) => {
break;
}
case WORKER_RESP_CODE.VIEW_INFO:
setNumFilteredEvents(args.numFilteredEvents);
setFirstLogEventNumPerPage(args.firstLogEventNumPerPage);
setLastLogEventNumPerPage(args.lastLogEventNumPerPage);
numFilteredEvents.current = args.numFilteredEvents
firstLogEventNumPerPage.current = args.firstLogEventNumPerPage

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

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

new-log-viewer/src/contexts/StateContextProvider.tsx#L198-L199

[@stylistic/js/semi] Missing semicolon.
lastLogEventNumPerPage.current = args.lastLogEventNumPerPage

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

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

new-log-viewer/src/contexts/StateContextProvider.tsx#L199-L200

[@stylistic/js/semi] Missing semicolon.
break;

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

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

new-log-viewer/src/contexts/StateContextProvider.tsx#L200-L201

[@stylistic/js/semi] Missing semicolon.
default:
console.error(`Unexpected ev.data: ${JSON.stringify(ev.data)}`);
Expand Down Expand Up @@ -238,22 +244,22 @@ const StateContextProvider = ({children}: StateContextProviderProps) => {

// On `numEvents` update, recalculate `numPagesRef`.
useEffect(() => {
if (STATE_DEFAULT.numFilteredEvents === numFilteredEvents) {
if (STATE_DEFAULT.numFilteredEvents === numFilteredEvents.current) {
return;
}

numPagesRef.current = getChunkNum(numFilteredEvents, getConfig(CONFIG_KEY.PAGE_SIZE));
numPagesRef.current = getChunkNum(numFilteredEvents.current, getConfig(CONFIG_KEY.PAGE_SIZE));

Check warning on line 251 in new-log-viewer/src/contexts/StateContextProvider.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

new-log-viewer/src/contexts/StateContextProvider.tsx#L251

[@stylistic/js/max-len] This line has a length of 102. Maximum allowed is 100.
}, [numFilteredEvents]);

// On `logEventNum` update, clamp it then switch page if necessary or simply update the URL.
useEffect(() => {
if (null === mainWorkerRef.current || URL_HASH_PARAMS_DEFAULT.logEventNum === logEventNum ||
0 === firstLogEventNumPerPage.length) {
0 === firstLogEventNumPerPage.current.length) {
return;
}

const newPageNum = 1 +
firstLogEventNumPerPage.findLastIndex((value: number) => value <= logEventNum);
firstLogEventNumPerPage.current.findLastIndex((value: number) => value <= logEventNum);

if (0 === newPageNum) {
return;
Expand Down Expand Up @@ -312,12 +318,12 @@ const StateContextProvider = ({children}: StateContextProviderProps) => {
value={{
beginLineNumToLogEventNum: beginLineNumToLogEventNumRef.current,
fileName: fileName,
firstLogEventNumPerPage: firstLogEventNumPerPage,
lastLogEventNumPerPage: lastLogEventNumPerPage,
firstLogEventNumPerPage: firstLogEventNumPerPage.current,
lastLogEventNumPerPage: lastLogEventNumPerPage.current,
logData: logData,
logLevelFilter: logLevelFilterRef.current,
numEvents: numEvents,
numFilteredEvents: numFilteredEvents,
numFilteredEvents: numFilteredEvents.current,
numPages: numPagesRef.current,
pageNum: pageNumRef.current,

Expand Down

0 comments on commit 2c4d735

Please sign in to comment.