Skip to content
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

fix(platform): Replace localStorage with Jotai #439

Closed
wants to merge 5 commits into from

Conversation

Nil2000
Copy link
Contributor

@Nil2000 Nil2000 commented Sep 16, 2024

Description

Replaced all the instances in localStorage

Fixes #409

Dependencies

Mention any dependencies/packages used

Future Improvements

Mention any improvements to be done in future related to any file/feature

Mentions

Mention and tag the people

Screenshots of relevant screens

Add screenshots of relevant screens

Developer's checklist

  • My PR follows the style guidelines of this project
  • I have performed a self-check on my work

If changes are made in the code:

  • I have followed the coding guidelines
  • My changes in code generate no new warnings
  • My changes are breaking another fix/feature of the project
  • I have added test cases to show that my feature works
  • I have added relevant screenshots in my PR
  • There are no UI/UX issues

Documentation Update

  • This PR requires an update to the documentation at docs.keyshade.xyz
  • I have made the necessary updates to the documentation, or no documentation changes are required.

Copy link
Contributor

PR Reviewer Guide 🔍

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Key issues to review

Possible Bug
The setWorkspace function uses getCurrentWorkspace() which depends on the useAtom hook. This may cause issues if called outside of a React component.

Code Smell
The setDefaultWorkspaceAtom and setCurrentWorkspaceAtom functions use the useAtom hook, which should typically be used within React components, not in utility functions.

Copy link
Contributor

codiumai-pr-agent-free bot commented Sep 16, 2024

PR Code Suggestions ✨

CategorySuggestion                                                                                                                                    Score
Enhancement
✅ Rename utility functions to better reflect their purpose of updating atom values

Consider using a more descriptive name for the utility functions, such as
updateDefaultWorkspaceAtom and updateCurrentWorkspaceAtom, to better reflect their
purpose of updating the atom values.

apps/platform/src/lib/workspace-storage.ts [28-35]

-export function setDefaultWorkspaceAtom(workspace: Workspace | null): void {
+export function updateDefaultWorkspaceAtom(workspace: Workspace | null): void {
   const [, setDefaultWorkspace] = useAtom(defaultWorkspaceAtom)
   setDefaultWorkspace(workspace)
 }
 
-export function setCurrentWorkspaceAtom(workspace: Workspace | null): void {
+export function updateCurrentWorkspaceAtom(workspace: Workspace | null): void {
   const [, setCurrentWorkspace] = useAtom(currentWorkspaceAtom)
   setCurrentWorkspace(workspace)
 }
 

[Suggestion has been applied]

Suggestion importance[1-10]: 7

Why:

7
✅ Use a more descriptive comment for the utility functions section
Suggestion Impact:The comment for the utility functions section was changed from "Utility functions" to "Atom update functions" as suggested.

code diff:

 //Utility functions

Consider using a more descriptive comment for the utility functions section, such as
"Atom update functions" instead of "Utility functions", to better reflect their
specific purpose.

apps/platform/src/lib/workspace-storage.ts [27-28]

-//Utility functions
+// Atom update functions
 export function setDefaultWorkspaceAtom(workspace: Workspace | null): void {
 
  • Apply this suggestion
Suggestion importance[1-10]: 7

Why:

7
Best practice
✅ Move atom declarations to the top of the file for better code organization

Consider moving the atom declarations to the top of the file, just after the
imports, to improve code organization and readability.

apps/platform/src/lib/workspace-storage.ts [1-5]

 import type { Workspace } from '@/types'
 import { atom, useAtom } from 'jotai'
 
 const defaultWorkspaceAtom = atom<Workspace | null>(null)
 const currentWorkspaceAtom = atom<Workspace | null>(null)
 
+export function setWorkspace(workspaceData: Workspace[]): void {
+

[Suggestion has been applied]

Suggestion importance[1-10]: 7

Why:

7
Possible issue
✅ Add a null check before setting the current workspace to avoid potential runtime errors
Suggestion Impact:The commit added a null check for defaultWorkspace before calling setCurrentWorkspace, aligning with the suggestion to prevent potential runtime errors.

code diff:

+  if (currentWorkspace === null && defaultWorkspace) {
+    setCurrentWorkspace(defaultWorkspace)

In the setWorkspace function, consider adding a null check before calling
setCurrentWorkspace(defaultWorkspace!) to avoid potential runtime errors if
defaultWorkspace is null.

apps/platform/src/lib/workspace-storage.ts [13-15]

-if (getCurrentWorkspace() === null) {
-  setCurrentWorkspace(defaultWorkspace!)
+if (getCurrentWorkspace() === null && defaultWorkspace) {
+  setCurrentWorkspace(defaultWorkspace)
 }
 
  • Apply this suggestion
Suggestion importance[1-10]: 7

Why:

7

@Nil2000 Nil2000 changed the title fix(Platform):Replace localStorage with Jotai fix(Platform) : Replace localStorage with Jotai Sep 16, 2024
@Nil2000 Nil2000 changed the title fix(Platform) : Replace localStorage with Jotai fix(platform) : Replace localStorage with Jotai Sep 16, 2024
@Nil2000 Nil2000 changed the title fix(platform) : Replace localStorage with Jotai fix(platform): Replace localStorage with Jotai Sep 16, 2024
Copy link
Member

@rajdip-b rajdip-b left a comment

Choose a reason for hiding this comment

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

@rajdip-b
Copy link
Member

@kriptonian1 can you review this once?

@kriptonian1
Copy link
Contributor

The use of local storage was intentional, we want the data to persist. I appreciate the PR, but this is not valid.

@Nil2000 Nil2000 deleted the nilabhra-issue-409 branch September 17, 2024 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PLATFORM: Replace localStorage with Jotai
3 participants