Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
be6e9e0
Migrate isPrettified
zzxthehappiest May 21, 2025
1f0aeda
Remove UrlContextProvider
zzxthehappiest May 22, 2025
81585cb
Remove hashchange event when updateHashUrlParams
zzxthehappiest May 24, 2025
0ae420c
Add logEventNum to viewStore and remove from Url
zzxthehappiest May 22, 2025
cd36fb8
Add fileSrc to logFileStore and remove from UrlContext
zzxthehappiest May 22, 2025
0dfe7b8
Fix lint
zzxthehappiest May 25, 2025
5852960
Merge branch 'main' into zzx/feat-269
zzxthehappiest May 25, 2025
c808cf2
Fix coderabit comments
zzxthehappiest May 25, 2025
00cadb9
Fix coderabbit review
zzxthehappiest May 25, 2025
6a873d4
Add junhaoliao@b972113
zzxthehappiest May 25, 2025
6620583
Fix lint
zzxthehappiest May 26, 2025
66abf15
Fix coderabbit comments
zzxthehappiest May 26, 2025
cf10ebe
Fix comments
zzxthehappiest May 27, 2025
0910692
Fix comments
zzxthehappiest May 27, 2025
6ebcf09
Merge branch 'main' into zzx/feat-269
zzxthehappiest May 28, 2025
f4cc127
refactor: Rename uiStoreState type to UiStoreState to follow PascalCa…
Henry8192 May 26, 2025
9879d0a
docs: Add deployment instructions (resolves #217). (#236)
junhaoliao May 27, 2025
7159bf2
Fix comments
zzxthehappiest May 28, 2025
e9b2cbb
Merge branch 'zzx/feat-269' of github.com:zzxthehappiest/yscope-log-v…
zzxthehappiest May 28, 2025
4139d0e
Merge branch 'main' into zzx/feat-269
zzxthehappiest May 29, 2025
23aa8b3
Merge queryStore to zustandard (not test yet)
zzxthehappiest May 29, 2025
d204c9b
Fix lint
zzxthehappiest May 29, 2025
a464dc9
Finish the rest
zzxthehappiest May 30, 2025
0dabdfc
Fix #306
zzxthehappiest Jun 1, 2025
de74c4f
Merge branch 'main' into zzx/feat-269
zzxthehappiest Jun 1, 2025
3add41d
Fix coderabbit comments
zzxthehappiest Jun 1, 2025
7166d2b
Fix comments except: Remove null in URL params
zzxthehappiest Jun 4, 2025
def27ea
Final fix
zzxthehappiest Jun 5, 2025
3369449
Minor fix
zzxthehappiest Jun 5, 2025
3c9bd0d
Merge branch 'main' into zzx/feat-269
zzxthehappiest Jun 5, 2025
9669cd5
Fix latest comments
zzxthehappiest Jun 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import AppController from "./components/AppController";
import Layout from "./components/Layout";
import NotificationContextProvider from "./contexts/NotificationContextProvider";
import UrlContextProvider from "./contexts/UrlContextProvider";


/**
Expand All @@ -12,11 +11,9 @@ import UrlContextProvider from "./contexts/UrlContextProvider";
const App = () => {
return (
<NotificationContextProvider>
<UrlContextProvider>
<AppController>
<Layout/>
</AppController>
</UrlContextProvider>
<AppController>
<Layout/>
</AppController>
</NotificationContextProvider>
);
};
Expand Down
103 changes: 74 additions & 29 deletions src/components/AppController.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
/* eslint max-statements: ["error", 30] */
import React, {
useContext,
useEffect,
useRef,
} from "react";

import {NotificationContext} from "../contexts/NotificationContextProvider";
import {
updateWindowUrlHashParams,
URL_HASH_PARAMS_DEFAULT,
URL_SEARCH_PARAMS_DEFAULT,
UrlContext,
} from "../contexts/UrlContextProvider";
import useContextStore from "../stores/contextStore";
import useLogFileManagerStore from "../stores/logFileManagerProxyStore";
import useLogFileStore from "../stores/logFileStore";
Expand All @@ -28,6 +23,13 @@ import {
isWithinBounds,
} from "../utils/data";
import {clamp} from "../utils/math";
import {
getWindowUrlHashParams,
getWindowUrlSearchParams,
updateWindowUrlHashParams,
URL_HASH_PARAMS_DEFAULT,
URL_SEARCH_PARAMS_DEFAULT,
} from "../utils/url.ts";


/**
Expand All @@ -41,9 +43,9 @@ import {clamp} from "../utils/math";
const updateUrlIfEventOnPage = (
logEventNum: number,
logEventNumsOnPage: number[]
): boolean => {
): {isUpdated: boolean; nearestLogEventNum: number} => {
if (false === isWithinBounds(logEventNumsOnPage, logEventNum)) {
return false;
return {isUpdated: false, nearestLogEventNum: 0};
}

const nearestIdx = findNearestLessThanOrEqualElement(
Expand All @@ -65,7 +67,7 @@ const updateUrlIfEventOnPage = (
logEventNum: nearestLogEventNum,
});

return true;
return {isUpdated: true, nearestLogEventNum: nearestLogEventNum};
};

interface AppControllerProps {
Expand All @@ -81,40 +83,75 @@ interface AppControllerProps {
*/
const AppController = ({children}: AppControllerProps) => {
const {postPopUp} = useContext(NotificationContext);
const {filePath, isPrettified, logEventNum} = useContext(UrlContext);

// States
const beginLineNumToLogEventNum = useViewStore((state) => state.beginLineNumToLogEventNum);
const setIsPrettified = useViewStore((state) => state.updateIsPrettified);

const fileSrc = useLogFileStore((state) => state.fileSrc);
const loadFile = useLogFileStore((state) => state.loadFile);
const setFileSrc = useLogFileStore((state) => state.setFileSrc);

const isPrettified = useViewStore((state) => state.isPrettified);
const updateIsPrettified = useViewStore((state) => state.updateIsPrettified);

const {logFileManagerProxy} = useLogFileManagerStore.getState();
const numEvents = useLogFileStore((state) => state.numEvents);
const setLogEventNum = useContextStore((state) => state.setLogEventNum);

const logEventNum = useViewStore((state) => state.logEventNum);
const setLogEventNum = useViewStore((state) => state.setLogEventNum);

const setUiState = useUiStore((state) => state.setUiState);
const setPostPopUp = useContextStore((state) => state.setPostPopUp);

// Refs
const isPrettifiedRef = useRef<boolean>(isPrettified ?? false);
const isPrettifiedRef = useRef<boolean>(isPrettified);
const logEventNumRef = useRef(logEventNum);

// Synchronize `logEventNumRef` with `logEventNum`.
useEffect(() => {
if (null !== logEventNum) {
logEventNumRef.current = logEventNum;
setLogEventNum(logEventNum);
}
}, [
logEventNum,
const handleHashChange = () => {
const hashParams = getWindowUrlHashParams();

if (null !== hashParams.logEventNum) {
setLogEventNum(hashParams.logEventNum);
}

if (null !== hashParams.isPrettified) {
updateIsPrettified(hashParams.isPrettified);
}

// It is weird that updating search params when hash params changed, even there
// might be hidden condition that search params always change together with hash
// params.
const searchParams = getWindowUrlSearchParams();

if (null !== searchParams.filePath) {
setFileSrc(searchParams.filePath);
}
};

handleHashChange();

window.addEventListener("hashchange", handleHashChange);

return () => {
window.removeEventListener("hashchange", handleHashChange);
};
}, [setFileSrc,
setLogEventNum,
]);
updateIsPrettified]);

// Synchronize `isPrettifiedRef` with `isPrettified`.
useEffect(() => {
isPrettifiedRef.current = isPrettified ?? false;
setIsPrettified(isPrettifiedRef.current);
isPrettifiedRef.current = isPrettified;
}, [
isPrettified,
setIsPrettified,
]);

// Synchronize `logEventNumRef` with `logEventNum`.
useEffect(() => {
logEventNumRef.current = logEventNum;
}, [
logEventNum,
]);

// On `logEventNum` update, clamp it then switch page if necessary or simply update the URL.
Expand All @@ -128,8 +165,15 @@ const AppController = ({children}: AppControllerProps) => {

const clampedLogEventNum = clamp(logEventNum, 1, numEvents);

if (updateUrlIfEventOnPage(clampedLogEventNum, logEventNumsOnPage)) {
const {
isUpdated,
nearestLogEventNum,
} = updateUrlIfEventOnPage(clampedLogEventNum, logEventNumsOnPage);

if (isUpdated) {
// No need to request a new page since the log event is on the current page.
setLogEventNum(nearestLogEventNum);

return;
}

Expand All @@ -156,13 +200,14 @@ const AppController = ({children}: AppControllerProps) => {
logEventNum,
logFileManagerProxy,
numEvents,
setLogEventNum,
setUiState,
postPopUp,
]);

// On `filePath` update, load file.
// On `fileSrc` update, load file.
useEffect(() => {
if (URL_SEARCH_PARAMS_DEFAULT.filePath === filePath) {
if (URL_SEARCH_PARAMS_DEFAULT.filePath === fileSrc) {
return;
}

Expand All @@ -173,9 +218,9 @@ const AppController = ({children}: AppControllerProps) => {
args: {eventNum: logEventNumRef.current},
};
}
loadFile(filePath, cursor);
loadFile(fileSrc, cursor);
}, [
filePath,
fileSrc,
loadFile,
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
Typography,
} from "@mui/joy";

import {updateWindowUrlHashParams} from "../../../../../contexts/UrlContextProvider";
import useViewStore from "../../../../../stores/viewStore.ts";
import {updateWindowUrlHashParams} from "../../../../../utils/url.ts";

import "./Result.css";

Expand Down Expand Up @@ -36,8 +37,10 @@ const Result = ({logEventNum, message, matchRange}: ResultProps) => {
message.slice(...matchRange),
message.slice(matchRange[1]),
];
const setLogEventNum = useViewStore((state) => state.setLogEventNum);
const handleResultButtonClick = () => {
updateWindowUrlHashParams({logEventNum});
setLogEventNum(logEventNum);
};

return (
Expand Down
34 changes: 21 additions & 13 deletions src/components/Editor/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint max-lines: ["error", 350] */
/* eslint max-lines-per-function: ["error", 170] */
/* eslint max-lines-per-function: ["error", 200] */
/* eslint max-statements: ["error", 30] */
import {
useCallback,
useContext,
useEffect,
useRef,
useState,
Expand All @@ -11,10 +11,6 @@ import {
import {useColorScheme} from "@mui/joy";
import * as monaco from "monaco-editor/esm/vs/editor/editor.api.js";

import {
updateWindowUrlHashParams,
UrlContext,
} from "../../contexts/UrlContextProvider";
import useViewStore from "../../stores/viewStore";
import {Nullable} from "../../typings/common";
import {
Expand All @@ -36,6 +32,7 @@ import {
getMapKeyByValue,
getMapValueWithNearestLessThanOrEqualKey,
} from "../../utils/data";
import {updateWindowUrlHashParams} from "../../utils/url.ts";
import MonacoInstance from "./MonacoInstance";
import {goToPositionAndCenter} from "./MonacoInstance/utils";

Expand Down Expand Up @@ -138,16 +135,22 @@ const Editor = () => {
const {mode, systemMode} = useColorScheme();

const beginLineNumToLogEventNum = useViewStore((state) => state.beginLineNumToLogEventNum);
const isPrettified = useViewStore((state) => state.isPrettified);
const updateIsPrettified = useViewStore((state) => state.updateIsPrettified);

const logData = useViewStore((state) => state.logData);

const logEventNum = useViewStore((state) => state.logEventNum);
const setLogEventNum = useViewStore((state) => state.setLogEventNum);

const loadPageByAction = useViewStore((state) => state.loadPageByAction);
const {isPrettified, logEventNum} = useContext(UrlContext);

const [lineNum, setLineNum] = useState<number>(1);
const beginLineNumToLogEventNumRef = useRef<BeginLineNumToLogEventNumMap>(
beginLineNumToLogEventNum
);
const editorRef = useRef<Nullable<monaco.editor.IStandaloneCodeEditor>>(null);
const isPrettifiedRef = useRef<boolean>(isPrettified ?? false);
const isPrettifiedRef = useRef<boolean>(isPrettified);
const isMouseDownRef = useRef<boolean>(false);
const pageSizeRef = useRef(getConfig(CONFIG_KEY.PAGE_SIZE));

Expand Down Expand Up @@ -176,18 +179,22 @@ const Editor = () => {
case ACTION_NAME.COPY_LOG_EVENT:
handleCopyLogEventAction(editor, beginLineNumToLogEventNumRef.current);
break;
case ACTION_NAME.TOGGLE_PRETTIFY:
case ACTION_NAME.TOGGLE_PRETTIFY: {
const newIsPrettified = !isPrettifiedRef.current;
updateWindowUrlHashParams({
[HASH_PARAM_NAMES.IS_PRETTIFIED]: !isPrettifiedRef.current,
[HASH_PARAM_NAMES.IS_PRETTIFIED]: newIsPrettified,
});
updateIsPrettified(newIsPrettified);
break;
}
case ACTION_NAME.TOGGLE_WORD_WRAP:
handleToggleWordWrapAction(editor);
break;
default:
break;
}
}, [loadPageByAction]);
}, [loadPageByAction,
updateIsPrettified]);

/**
* Sets `editorRef` and configures callbacks for mouse down detection.
Expand Down Expand Up @@ -255,7 +262,8 @@ const Editor = () => {
return;
}
updateWindowUrlHashParams({logEventNum: newLogEventNum});
}, []);
setLogEventNum(newLogEventNum);
}, [setLogEventNum]);

// Synchronize `beginLineNumToLogEventNumRef` with `beginLineNumToLogEventNum`.
useEffect(() => {
Expand All @@ -264,7 +272,7 @@ const Editor = () => {

// Synchronize `isPrettifiedRef` with `isPrettified`.
useEffect(() => {
isPrettifiedRef.current = isPrettified ?? false;
isPrettifiedRef.current = isPrettified;
}, [isPrettified]);

// On `logEventNum` update, update line number in the editor.
Expand Down
Loading