Skip to content

refactor(AppController): Remove obsolete StateContext references; Relocate file to component/ (fixes #280). #281

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 3 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import AppController from "./components/AppController";
import Layout from "./components/Layout";
import AppController from "./contexts/AppController";
import NotificationContextProvider from "./contexts/NotificationContextProvider";
import UrlContextProvider from "./contexts/UrlContextProvider";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import React, {
createContext,
useContext,
useEffect,
useRef,
} from "react";
Comment on lines 1 to 5
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Optimize React import for type-only usage
Since React is only referenced for the React.ReactNode type in this file, you can switch to a type-only import to avoid pulling in the entire React namespace at runtime (with TS’s importsNotUsedAsValues: "error").

-import React, {
-    useContext,
-    useEffect,
-    useRef,
-} from "react";
+import { useContext, useEffect, useRef } from "react";
+import type { ReactNode } from "react";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import React, {
createContext,
useContext,
useEffect,
useRef,
} from "react";
import { useContext, useEffect, useRef } from "react";
import type { ReactNode } from "react";
🤖 Prompt for AI Agents
In src/components/AppController.tsx lines 1 to 5, the React import is currently
importing the entire React namespace, but React is only used for the
React.ReactNode type. Change the import to a type-only import by using `import
type { ReactNode } from "react"` instead of importing the full React object.
This will optimize the import by avoiding pulling in React at runtime
unnecessarily.


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 @@ -22,21 +28,8 @@ import {
isWithinBounds,
} from "../utils/data";
import {clamp} from "../utils/math";
import {NotificationContext} from "./NotificationContextProvider";
import {
updateWindowUrlHashParams,
URL_HASH_PARAMS_DEFAULT,
URL_SEARCH_PARAMS_DEFAULT,
UrlContext,
} from "./UrlContextProvider";


const StateContext = createContext<null>(null);

interface StateContextProviderProps {
children: React.ReactNode;
}

/**
* Updates the log event number in the URL to `logEventNum` if it's within the bounds of
* `logEventNumsOnPage`.
Expand Down Expand Up @@ -75,14 +68,18 @@ const updateUrlIfEventOnPage = (
return true;
};

interface AppControllerProps {
children: React.ReactNode;
}

/**
* Manages states for the application.
*
* @param props
* @param props.children
* @return
*/
const AppController = ({children}: StateContextProviderProps) => {
const AppController = ({children}: AppControllerProps) => {
const {postPopUp} = useContext(NotificationContext);
const {filePath, isPrettified, logEventNum} = useContext(UrlContext);

Expand Down Expand Up @@ -189,14 +186,8 @@ const AppController = ({children}: StateContextProviderProps) => {
setPostPopUp,
]);


return (
<StateContext.Provider value={null}>
{children}
</StateContext.Provider>
);
return children;
};


export default AppController;
export {StateContext};