Skip to content

refactor: Replace NotificationContext with useNotificationStore for improved state management (fixes #290, resolves #292). #293

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

Closed
wants to merge 2 commits into from

Conversation

junhaoliao
Copy link
Member

@junhaoliao junhaoliao commented May 22, 2025

Description

This PR replaces the React Context-based notification system with a Zustand store implementation. The change simplifies the codebase by:

  1. Eliminating the need for a context provider wrapper component
  2. Making the notification system more accessible throughout the application without prop drilling or context consumption

The implementation maintains all the existing functionality:

  • Storing and displaying popup messages
  • Adding new popup messages
  • Removing popup messages when closed
  • Maintaining unique IDs for each message

The Zustand approach provides better performance characteristics than React Context, especially for frequent updates, and makes the notification system easier to use in components.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

  1. npm run build; npm run preview and verified that the pop-up box show up when accessing an non-existent file. (see Bug: Error pop-ups don't appear when loading non-existent files #290 for issue reproduction).
  2. Verified that popup messages can be created with the new useNotificationStore().postPopUp() method
  3. Confirmed that popup messages are correctly stored in the Zustand state
  4. Tested that popup messages can be removed with the handlePopUpMessageClose() method
  5. Ensured that the ID generation works correctly and produces unique, incremental IDs
  6. Checked that components using the notification system continue to work as expected after the refactor
  7. Verified that multiple components / Zustand store actions can access the notification state without unnecessary re-renders

Summary by CodeRabbit

  • Refactor
    • Updated the notification system to use a new store-based approach instead of React context.
    • Removed the NotificationContextProvider and related context usage throughout the app.
    • Notification pop-up messages are now managed via a centralized store for improved consistency.
    • Error notifications continue to display as before, with no visible changes to the user interface.

@junhaoliao junhaoliao requested a review from a team as a code owner May 22, 2025 00:59
@junhaoliao junhaoliao requested a review from Henry8192 May 22, 2025 00:59
Copy link

coderabbitai bot commented May 22, 2025

## Walkthrough

This change removes the `NotificationContextProvider` and all related React context usage for notification pop-ups, replacing it with a new Zustand store (`useNotificationStore`). All components and stores previously using the context now interact directly with the Zustand store for notification state and actions. The context provider and its types are deleted.

## Changes

| File(s)                                                                                          | Change Summary                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
|--------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| src/App.tsx                                                                                      | Removed `NotificationContextProvider` from the component tree and its import. The app now uses `UrlContextProvider` as the outermost provider.                                                                                                                                                                                                                                                                                                                                                                      |
| src/components/AppController.tsx<br>src/components/CentralContainer/Sidebar/SidebarTabs/SettingsTabPanel/index.tsx<br>src/components/PopUps/PopUpMessageBox.tsx<br>src/components/PopUps/index.tsx | Replaced usage of `NotificationContext` and `useContext` with the new `useNotificationStore` for notification pop-up state and actions. Removed all context-related imports and logic.                                                                                                                                                                                                                                                                                       |
| src/contexts/NotificationContextProvider.tsx                                                      | Deleted the file implementing the notification context provider, its types, and default values.                                                                                                                                                                                                                                                                                                                                                                                                                     |
| src/stores/contextStore.ts                                                                       | Removed all properties and methods related to notification pop-ups (`postPopUp`, `setPostPopUp`) from the context store and its types.                                                                                                                                                                                                                                                                                                                                                                              |
| src/stores/notificationStore.ts                                                                  | Added a new Zustand store (`useNotificationStore`) to manage notification pop-up messages, including actions for posting and closing notifications. Exported the `PopUpMessage` type.                                                                                                                                                                                                                                                                                        |
| src/stores/logExportStore.ts<br>src/stores/logFileStore.ts<br>src/stores/queryStore/createQueryControllerSlice.ts<br>src/stores/viewStore.ts | Changed notification handling in error cases to use `useNotificationStore` instead of the context store. In `logFileStore.ts`, also resets file name and log data to defaults on load failure.                                                                                                                                                                                                                                                                                |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant Component
    participant useNotificationStore

    Component->>useNotificationStore: postPopUp(message)
    useNotificationStore-->>useNotificationStore: Add message with unique ID to popUpMessages

    Component->>useNotificationStore: handlePopUpMessageClose(messageId)
    useNotificationStore-->>useNotificationStore: Remove message by ID from popUpMessages

    Component->>useNotificationStore: Read popUpMessages for rendering

Possibly related issues

Possibly related PRs

Suggested reviewers

  • hoophalab
  • Henry8192

<!-- walkthrough_end -->
<!-- This is an auto-generated comment: all tool run failures by coderabbit.ai -->

> [!WARNING]
> There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.
> 
> <details>
> <summary>🔧 ESLint</summary>
> 
> > If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.
> 
> npm warn config production Use `--omit=dev` instead.
> npm error Exit handler never called!
> npm error This is an error with npm itself. Please report this error at:
> npm error   <https://github.com/npm/cli/issues>
> npm error A complete log of this run can be found in: /.npm/_logs/2025-05-22T05_08_48_203Z-debug-0.log
> 
> 
> 
> </details>

<!-- end of auto-generated comment: all tool run failures by coderabbit.ai -->

<!-- announcements_start -->

> [!NOTE]
> <details>
> <summary>⚡️ AI Code Reviews for VS Code, Cursor, Windsurf</summary>
> 
> CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
> Learn more [here](http://coderabbit.ai/ide).
> 
> </details>

---

> [!NOTE]
> <details>
> <summary>⚡️ Faster reviews with caching</summary>
> 
> CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure `Review - Disable Cache` at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the `Data Retention` setting under your Organization Settings.
> Enjoy the performance boost—your workflow just got faster.
> 
> </details>

<!-- announcements_end -->
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AI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beGjnLsairazmbb/yT8rnz9T1cmYgMcYg8icWCi2CpUIm7HYWsz4K32YLdIcH27QMh75HoWMHe7EMoBMKJio2FqX3oHIXpBSPiWQW8CwWB7Wq3ZE64IXB/dwNfSSAABFYIFwWDeJPoTMV0o+Cevq6djR1nYa2wjnHRqFA+/RoJ1e+1ExiPLeyl1txemxpCvQxxiGlxxEH1a+rAM66xXAITygWQRJRJwiZJ/VYcbaUbE9x+6OPwkzcNIcXiDx0Bg63xgiOHaBiXdT8MeBkJ2J1BqGDD7gqJyLmJuYPBsWkIEFIhtz++jzzUUvcvOrXLmOcEx6mELL46eZkqUk/qWluilhiibQdhxY9bLh0gJbMoyeyoyfE578iDxD5oqYh2k5R0Nj2RgF4epplR+nNRpFlnIa54xTj+feodIlzDxLm1Ix9AEouAoxGqV0gUDBDw5kKLPKIYILiBuGGLfVRxMg+sgJ8LzEYJxBmLwj4hh+zaagR0p+vw7ooYKB7s5lSQh2QqeXM7sO6keLwLR70J/FEZ0zLo/gQqTpNY7+pJioFz17k9q9iztzbVygD+vAxRbZ2gJjSnWQVugMW1JJcZmgeCRAQhIHWA0BNmxQBos60yWyYKFp5Dj3OFn7VzqdEhjrfdih1tMiZUHqcW5r2HWw4zfgDARxSZ9AmZuaVCM6ldv+oGHp3iJw8I/n0YWlv8OGan0ooD6ZPh45p5nrp7T50R6Dn5r7Ibs5GRteDeXOF0F+ZvdR0eFgSuPwNAKeFF+QT4ZuKgVuZeDuF3rue0V4XAbG80RAbG/wJpugbG6z1edeKPgAFl2DQEOAYH2DQBIH2AAFZDgSBDgrxDgBAAAOBgNOZIYvtOWgXYNOAARmr4AHZM/q/Dgg1Dg059hW/i/0+DAo/q/i/W+O/x+SBq/aBq/p+SA05g00BB/i/Cpa/DgO+5/rwEhM/1+BAkhdgR/R+c5o/1A4/rXE+iEE5aBsa850+gA= -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=y-scope/yscope-log-viewer&utm_content=293):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Explain this complex logic.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai explain this code block.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and explain its main purpose.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

### Support

Need help? Create a ticket on our [support page](https://www.coderabbit.ai/contact-us/support) for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### CodeRabbit Configuration File (`.coderabbit.yaml`)

- You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository.
- Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json`

### Documentation and Community

- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 69d59c9 and 42a0c9a.

📒 Files selected for processing (12)
  • src/App.tsx (1 hunks)
  • src/components/AppController.tsx (2 hunks)
  • src/components/CentralContainer/Sidebar/SidebarTabs/SettingsTabPanel/index.tsx (3 hunks)
  • src/components/PopUps/PopUpMessageBox.tsx (2 hunks)
  • src/components/PopUps/index.tsx (2 hunks)
  • src/contexts/NotificationContextProvider.tsx (0 hunks)
  • src/stores/contextStore.ts (0 hunks)
  • src/stores/logExportStore.ts (2 hunks)
  • src/stores/logFileStore.ts (3 hunks)
  • src/stores/notificationStore.ts (1 hunks)
  • src/stores/queryStore/createQueryControllerSlice.ts (2 hunks)
  • src/stores/viewStore.ts (4 hunks)
💤 Files with no reviewable changes (2)
  • src/stores/contextStore.ts
  • src/contexts/NotificationContextProvider.tsx
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.

**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

  • src/stores/logExportStore.ts
  • src/stores/queryStore/createQueryControllerSlice.ts
  • src/components/PopUps/PopUpMessageBox.tsx
  • src/App.tsx
  • src/components/AppController.tsx
  • src/components/CentralContainer/Sidebar/SidebarTabs/SettingsTabPanel/index.tsx
  • src/stores/logFileStore.ts
  • src/stores/viewStore.ts
  • src/components/PopUps/index.tsx
  • src/stores/notificationStore.ts
🧬 Code Graph Analysis (2)
src/stores/logFileStore.ts (1)
src/stores/viewStore.ts (1)
  • VIEW_STORE_DEFAULT (271-271)
src/stores/notificationStore.ts (1)
src/typings/common.ts (1)
  • WithId (12-12)
🔇 Additional comments (25)
src/stores/logExportStore.ts (2)

10-10: Import change looks good!

The replacement of the context store import with the new Zustand-based notification store aligns perfectly with the PR's objective.


53-53: State access properly updated!

The change correctly retrieves the postPopUp function from the new Zustand notification store while maintaining the same error handling logic.

src/stores/queryStore/createQueryControllerSlice.ts (2)

6-6: Import change looks good!

The replacement of the context store import with the new Zustand-based notification store aligns with the PR's objective of improving state management.


57-57: State access properly updated!

The change correctly retrieves the postPopUp function from the new Zustand notification store while maintaining the same error handling logic.

src/App.tsx (1)

13-17: Component tree simplified!

The removal of the NotificationContextProvider wrapper successfully simplifies the component tree while maintaining functionality. This change is a key part of the refactoring effort and aligns with the PR objective of eliminating the need for a context provider wrapper component.

src/components/PopUps/PopUpMessageBox.tsx (2)

18-18: Import update looks good!

The import change correctly brings in both the useNotificationStore hook and the PopUpMessage type from the new Zustand store.


42-43: State access properly updated!

The change correctly replaces context consumption with a direct subscription to the Zustand store. The selector pattern used here is efficient and will prevent unnecessary re-renders.

src/stores/viewStore.ts (4)

26-26: LGTM: Added import for the new notification store.

The addition of the import for useNotificationStore aligns with the PR objective of replacing context-based notifications with Zustand store.


142-142: LGTM: Migrated error notification handling to useNotificationStore.

This change correctly replaces the context-based approach with the new Zustand store implementation, maintaining the same error notification behavior.


196-196: LGTM: Consistent implementation of notification store usage.

The change maintains consistency with other error handlers in the file by using the same pattern to access the notification store.


246-246: LGTM: Successfully migrated the last error handler to useNotificationStore.

This completes the migration of all error handlers in this file from context to Zustand store.

src/components/CentralContainer/Sidebar/SidebarTabs/SettingsTabPanel/index.tsx (3)

1-1: LGTM: Simplified import by removing useContext.

The change correctly removes the no-longer-needed useContext import, which aligns with the PR objective.


15-15: LGTM: Added import for useNotificationStore.

This change properly adds the import for the new notification store that will replace the context-based approach.


138-138: LGTM: Successfully migrated to Zustand-based notification store.

The component now correctly uses the Zustand store selector pattern to access the postPopUp function, which simplifies the code and improves maintainability.

src/components/AppController.tsx (2)

16-16: LGTM: Added import for notification store.

This change correctly imports the new notification store to replace the context-based approach.


90-90: LGTM: Switched to store-based notifications.

The component now properly uses the Zustand store selector pattern to access the postPopUp function, simplifying state management.

src/components/PopUps/index.tsx (2)

6-6: LGTM: Added import for notification store.

This change correctly imports the useNotificationStore hook that will replace the context-based notification system.


18-18: LGTM: Migrated to store-based message retrieval.

The component now correctly uses the Zustand store selector pattern to access the popUpMessages array, maintaining the same functionality while simplifying the state management approach.

src/stores/logFileStore.ts (4)

27-27: LGTM! Good replacement of context with Zustand store.

The import change from context to Zustand store aligns with the PR objective to improve state management.


30-30: LGTM! Necessary import for error handling.

Adding VIEW_STORE_DEFAULT import enables proper reset of log data on error.


125-125: LGTM! Updated notification source.

Successfully migrated from context-based notification to the new Zustand store implementation.


160-161: LGTM! Improved error handling.

Enhanced error recovery by explicitly resetting file name and log data to default values. This ensures the application state is clean after an error occurs.

src/stores/notificationStore.ts (3)

1-51: LGTM! Well-implemented Zustand store replacing context.

This implementation successfully replaces the React Context notification system with a clean, well-typed Zustand store. The store structure clearly separates state and actions while maintaining the same functionality.


7-20: LGTM! Clear type definitions and default state.

The TypeScript interfaces provide excellent type safety for the store. The use of WithId type to add IDs to messages is a good pattern for maintaining unique identifiers.


27-31: LGTM! Good immutable state update patterns.

Both actions follow immutable update patterns, creating new state objects rather than mutating existing ones. This is the recommended approach for Zustand stores and helps prevent unexpected side effects.

Also applies to: 41-47

popUpMessages: [],
};

let nextPopUpMessageId = 0;
Copy link

@coderabbitai coderabbitai bot May 22, 2025

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider persisting the ID counter.

The simple counter approach works well for generating unique IDs, but it resets on page reload. While likely acceptable for this use case, you might consider persisting it if maintaining unique IDs across sessions becomes important.

Also applies to: 34-40

🤖 Prompt for AI Agents
In src/stores/notificationStore.ts at lines 22 and 34-40, the nextPopUpMessageId
counter resets on page reload, losing uniqueness across sessions. To fix this,
persist the counter value in localStorage or another persistent storage,
initializing nextPopUpMessageId from there on load and updating the stored value
whenever the counter increments. This ensures IDs remain unique even after page
reloads.

Copy link
Member Author

Choose a reason for hiding this comment

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

The IDs are not expected to be persisted across page reloads.

Copy link

Choose a reason for hiding this comment

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

@junhaoliao Got it, thanks for clarifying. That makes sense for this use case since notifications are typically transient UI elements that would be cleared on reload anyway.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/stores/logFileStore.ts (1)

151-160: Consider resetting fileName and logData on error

When a file loading error occurs, the UI state is reset to UNOPENED, but the filename and log data aren't reset to their default values, which could lead to inconsistent UI state.

I see this issue was already identified in a previous review and is being tracked separately in issue #296. This approach of separating concerns helps maintain the focus of the current PR on the notification system refactoring.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 42a0c9a and 851785e.

📒 Files selected for processing (1)
  • src/stores/logFileStore.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.

**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

  • src/stores/logFileStore.ts
🪛 GitHub Check: lint-check
src/stores/logFileStore.ts

[failure] 30-30:
'VIEW_STORE_DEFAULT' is defined but never used

🪛 GitHub Actions: lint
src/stores/logFileStore.ts

[error] 30-30: ESLint: 'VIEW_STORE_DEFAULT' is defined but never used. (@typescript-eslint/no-unused-vars)

🔇 Additional comments (1)
src/stores/logFileStore.ts (1)

125-125: LGTM! Properly migrated from context to store

The notification system has been successfully migrated from React Context to Zustand store, maintaining the same functionality while making the state management more consistent.

import useQueryStore from "./queryStore";
import useUiStore from "./uiStore";
import useViewStore from "./viewStore";
import useViewStore, {VIEW_STORE_DEFAULT} from "./viewStore";
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove unused import

The VIEW_STORE_DEFAULT import is defined but never used in this file, which is causing linting errors in the CI pipeline.

-import useViewStore, {VIEW_STORE_DEFAULT} from "./viewStore";
+import useViewStore from "./viewStore";
📝 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 useViewStore, {VIEW_STORE_DEFAULT} from "./viewStore";
-import useViewStore, {VIEW_STORE_DEFAULT} from "./viewStore";
+import useViewStore from "./viewStore";
🧰 Tools
🪛 GitHub Check: lint-check

[failure] 30-30:
'VIEW_STORE_DEFAULT' is defined but never used

🪛 GitHub Actions: lint

[error] 30-30: ESLint: 'VIEW_STORE_DEFAULT' is defined but never used. (@typescript-eslint/no-unused-vars)

🤖 Prompt for AI Agents
In src/stores/logFileStore.ts at line 30, the import VIEW_STORE_DEFAULT is
unused and causing lint errors. Remove VIEW_STORE_DEFAULT from the import
statement to fix the issue.

@junhaoliao
Copy link
Member Author

This was created from a wrong branch and was replaced by #297

@junhaoliao junhaoliao closed this May 22, 2025
@junhaoliao junhaoliao deleted the notification-store branch May 22, 2025 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant