-
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.
- Loading branch information
Showing
4 changed files
with
70 additions
and
11 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { CssBaseline, ThemeProvider } from '@mui/material' | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
import { RouterProvider, createRouter } from '@tanstack/react-router' | ||
|
||
import { theme } from './Theme' | ||
import { ApiProvider } from './contexts/ApiContext' | ||
import { IntlProvider } from './contexts/IntlContext' | ||
import { | ||
PersistedActiveProjectIdProvider, | ||
createActiveProjectIdStore, | ||
} from './contexts/persistedState/PersistedProjectId' | ||
import { routeTree } from './routeTree.gen' | ||
|
||
const queryClient = new QueryClient() | ||
|
||
const router = createRouter({ routeTree }) | ||
|
||
declare module '@tanstack/react-router' { | ||
interface Register { | ||
router: typeof router | ||
} | ||
} | ||
|
||
const PersistedProjectIdStore = createActiveProjectIdStore({ | ||
isPersisted: true, | ||
}) | ||
|
||
export const App = () => ( | ||
<ThemeProvider theme={theme}> | ||
<CssBaseline /> | ||
<IntlProvider> | ||
<QueryClientProvider client={queryClient}> | ||
<PersistedActiveProjectIdProvider store={PersistedProjectIdStore}> | ||
<ApiProvider> | ||
<RouterProvider router={router} /> | ||
</ApiProvider> | ||
</PersistedActiveProjectIdProvider> | ||
</QueryClientProvider> | ||
</IntlProvider> | ||
</ThemeProvider> | ||
) |
21 changes: 21 additions & 0 deletions
21
src/renderer/src/contexts/persistedState/PersistedProjectId.tsx
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { createPersistedStoreWithProvider } from './createPersistedState' | ||
|
||
type PersistedActiveProjectId = { projectId: string } | ||
|
||
const { Provider, createStore, useCurrentStore, useActions } = | ||
createPersistedStoreWithProvider<PersistedActiveProjectId>({ | ||
slice: { projectId: 'newId' }, | ||
actions: { | ||
setProjectId: (newProjectId: string) => (set) => { | ||
set({ projectId: newProjectId }) | ||
}, | ||
}, | ||
persistedStoreKey: 'ActiveProjectId', | ||
}) | ||
|
||
export { | ||
Provider as PersistedActiveProjectIdProvider, | ||
createStore as createActiveProjectIdStore, | ||
useCurrentStore as usePersistedActiveProjectIdStore, | ||
useActions as usePersistedActiveProjectIdActions, | ||
} |
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,18 +1,9 @@ | ||
import { RouterProvider, createRouter } from '@tanstack/react-router' | ||
import { createRoot } from 'react-dom/client' | ||
|
||
import { routeTree } from './routeTree.gen' | ||
|
||
import './index.css' | ||
|
||
const router = createRouter({ routeTree }) | ||
|
||
declare module '@tanstack/react-router' { | ||
interface Register { | ||
router: typeof router | ||
} | ||
} | ||
import { App } from './App' | ||
|
||
const root = createRoot(document.getElementById('app') as HTMLElement) | ||
|
||
root.render(<RouterProvider router={router} />) | ||
root.render(<App />) |
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