Implement a better routing and api creation method

This commit is contained in:
Prayag Prajapati committed 2023-11-20 18:53:54 +05:30
1 parent c58d656449
commit 27e2ee971d
5 files changed
+377 -338

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
/** @format */
import { create } from "zustand";
import { getAllServer, getDefaultServer, getServer } from "../storage/servers";
import { getUser } from "../storage/user";
/**
* Central Store controls the base state required by the app
*/
export const useCentralStore = create(() => ({
defaultServerOnDisk: async () => await getDefaultServer(),
defaultServerInfoOnDisk: async () => {
let a = await getDefaultServer();
return await getServer(a);
},
allServersOnDisk: async () => getAllServer(),
userOnDisk: async () => getUser(),
/** This is the initial route that app goes to just after app startups */
initialRoute: null,
}));
/**
* Sets app inital route
* @param {string} route
*/
export const setInitialRoute = (route) => {
useCentralStore.setState((state) => ({ ...state, initialRoute: route }));
};