Skip to content

feat: Migrate utilities from UrlContextProvider to Zustand stores (resolves #269; fixes #294; resolves #306). #286

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

Merged
merged 31 commits into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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.

5 changes: 3 additions & 2 deletions src/components/AppController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ interface AppControllerProps {
*/
const AppController = ({children}: AppControllerProps) => {
const {postPopUp} = useContext(NotificationContext);
const {filePath, isPrettified, logEventNum} = useContext(UrlContext);
const {filePath, logEventNum} = useContext(UrlContext);

// States
const beginLineNumToLogEventNum = useViewStore((state) => state.beginLineNumToLogEventNum);
const setIsPrettified = useViewStore((state) => state.updateIsPrettified);
const isPrettified = useViewStore((state) => state.isPrettified);
const setIsPrettified = useViewStore((state) => state.setIsPrettified);
const loadFile = useLogFileStore((state) => state.loadFile);
const {logFileManagerProxy} = useLogFileManagerStore.getState();
const numEvents = useLogFileStore((state) => state.numEvents);
Expand Down
6 changes: 5 additions & 1 deletion src/components/StatusBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import LogLevelSelect from "./LogLevelSelect";
import StatusBarToggleButton from "./StatusBarToggleButton";

import "./index.css";
import useViewStore from "../../stores/viewStore.ts";


/**
Expand All @@ -42,7 +43,9 @@ const handleCopyLinkButtonClick = () => {
const StatusBar = () => {
const numEvents = useLogFileStore((state) => state.numEvents);
const uiState = useUiStore((state) => state.uiState);
const {isPrettified, logEventNum} = useContext(UrlContext);
const {logEventNum} = useContext(UrlContext);
const isPrettified = useViewStore((state) => state.isPrettified);
const setIsPrettified = useViewStore((state) => state.setIsPrettified);

const handleStatusButtonClick = (ev: React.MouseEvent<HTMLButtonElement>) => {
const {actionName} = ev.currentTarget.dataset;
Expand All @@ -52,6 +55,7 @@ const StatusBar = () => {
updateWindowUrlHashParams({
[HASH_PARAM_NAMES.IS_PRETTIFIED]: !isPrettified,
});
setIsPrettified(!isPrettified);
break;
default:
console.error(`Unexpected action: ${actionName}`);
Expand Down
15 changes: 11 additions & 4 deletions src/contexts/UrlContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
UrlSearchParamUpdatesType,
} from "../typings/url";
import {getAbsoluteUrl} from "../utils/url";
import useViewStore from "../stores/viewStore.ts";


const UrlContext = createContext <UrlParamsType>({} as UrlParamsType);
Expand Down Expand Up @@ -218,10 +219,10 @@ const getWindowUrlHashParams = () => {
parsed;
}

const isPrettified = hashParams.get(HASH_PARAM_NAMES.IS_PRETTIFIED);
if (null !== isPrettified) {
urlHashParams[HASH_PARAM_NAMES.IS_PRETTIFIED] = "true" === isPrettified;
}
// const isPrettified = hashParams.get(HASH_PARAM_NAMES.IS_PRETTIFIED);
// if (null !== isPrettified) {
// urlHashParams[HASH_PARAM_NAMES.IS_PRETTIFIED] = "true" === isPrettified;
// }

return urlHashParams;
};
Expand All @@ -247,6 +248,7 @@ const UrlContextProvider = ({children}: UrlContextProviderProps) => {
...searchParams,
...getWindowUrlHashParams(),
});
const setIsPrettified = useViewStore((state) => state.setIsPrettified);

useEffect(() => {
const handleHashChange = () => {
Expand All @@ -256,6 +258,11 @@ const UrlContextProvider = ({children}: UrlContextProviderProps) => {
...searchParams,
...getWindowUrlHashParams(),
});
const hashParams = new URLSearchParams(window.location.hash.substring(1));
const isPrettified = hashParams.get(HASH_PARAM_NAMES.IS_PRETTIFIED);
if (null !== isPrettified) {
setIsPrettified("true" === isPrettified);
}
};

window.addEventListener("hashchange", handleHashChange);
Expand Down
4 changes: 2 additions & 2 deletions src/stores/viewStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ interface ViewStoreActions {
filterLogs: (filter: LogLevelFilter) => void;

loadPageByAction: (navAction: NavigationAction) => void;
updateIsPrettified: (newIsPrettified: boolean) => void;
setIsPrettified: (newIsPrettified: boolean) => void;
updatePageData: (pageData: PageData) => void;
}

Expand Down Expand Up @@ -200,7 +200,7 @@ const useViewStore = create<ViewState>((set, get) => ({
setPageNum: (newPageNum) => {
set({pageNum: newPageNum});
},
updateIsPrettified: (newIsPrettified: boolean) => {
setIsPrettified: (newIsPrettified: boolean) => {
const {updatePageData} = get();
const {logEventNum, postPopUp} = useContextStore.getState();
const {logFileManagerProxy} = useLogFileManagerStore.getState();
Expand Down