-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use zustand for global store instead of contexts
- Loading branch information
Showing
10 changed files
with
60 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,8 @@ | |
"react-icons": "npm:[email protected]", | ||
"react-router-dom": "npm:[email protected]", | ||
"tailwindcss": "npm:[email protected]", | ||
"vite": "npm:[email protected]" | ||
"vite": "npm:[email protected]", | ||
"zustand": "npm:[email protected]" | ||
}, | ||
"nodeModulesDir": "auto" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,34 @@ | ||
import { Store } from "@tauri-apps/plugin-store"; | ||
import { create } from "zustand"; | ||
import { Extension } from "../types/extension.ts"; | ||
import { Manifest } from "../types/manifest.ts"; | ||
|
||
export const storeService = await Store.load("app_data.json"); | ||
const appData = await Store.load("app_data.json"); | ||
|
||
// Load the repository URL from the app data store | ||
const repositoryUrl = await appData.get<string>("extensionRepositoryUrl") ?? ""; | ||
|
||
interface StoreState { | ||
extensions: Extension[]; | ||
setExtensions: (extensions: Extension[]) => void; | ||
|
||
repositoryUrl: string; | ||
setRepositoryUrl: (repositoryUrl: string) => void; | ||
|
||
manifests: Manifest[]; | ||
setManifests: (manifests: Manifest[]) => void; | ||
} | ||
|
||
export const useStore = create<StoreState>()((set) => ({ | ||
extensions: new Array<Extension>(), | ||
setExtensions: (extensions: Extension[]) => set({ extensions }), | ||
|
||
repositoryUrl: repositoryUrl, | ||
setRepositoryUrl: (repositoryUrl: string) => { | ||
set({ repositoryUrl }); | ||
appData.set("extensionRepositoryUrl", repositoryUrl); | ||
}, | ||
|
||
manifests: new Array<Manifest>(), | ||
setManifests: (manifests: Manifest[]) => set({ manifests }), | ||
})); |