-
Notifications
You must be signed in to change notification settings - Fork 11
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
1 parent
cb21303
commit fcb0ba2
Showing
347 changed files
with
3,707 additions
and
2,980 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
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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { GRPCClient } from '@shm/shared' | ||
import { TamaguiProvider, TamaguiProviderProps, View } from '@shm/ui' | ||
import { QueryClientProvider } from '@tanstack/react-query' | ||
import { ReactQueryDevtools } from '@tanstack/react-query-devtools' | ||
import { ReactNode, useMemo } from 'react' | ||
|
||
import tamaguiConfig from '../tamagui.config' | ||
import { AppIPC } from './app-ipc' | ||
import { useExperiments } from './models/experiments' | ||
|
||
import { AppContext, AppPlatform } from './app-context' | ||
import { WindowUtils } from './models/window-utils' | ||
import { AppQueryClient } from './query-client' | ||
|
||
|
||
export function AppContextProvider({ | ||
children, | ||
platform, | ||
grpcClient, | ||
queryClient, | ||
ipc, | ||
externalOpen, | ||
windowUtils, | ||
saveCidAsFile, | ||
darkMode, | ||
}: { | ||
children: ReactNode | ||
platform: AppPlatform | ||
grpcClient: GRPCClient | ||
queryClient: AppQueryClient | ||
ipc: AppIPC | ||
externalOpen: (url: string) => Promise<void> | ||
windowUtils: WindowUtils | ||
saveCidAsFile: (cid: string, name: string) => Promise<void> | ||
darkMode: boolean | ||
}) { | ||
const appCtx = useMemo( | ||
() => ({ | ||
// platform: 'win32', // to test from macOS | ||
platform, | ||
grpcClient, | ||
queryClient, | ||
ipc, | ||
externalOpen, | ||
windowUtils, | ||
saveCidAsFile, | ||
}), | ||
[], | ||
) | ||
if (!queryClient) | ||
throw new Error('queryClient is required for AppContextProvider') | ||
return ( | ||
<AppContext.Provider value={appCtx}> | ||
<QueryClientProvider client={queryClient.client}> | ||
<StyleProvider darkMode={darkMode}>{children}</StyleProvider> | ||
<ReactQueryTools /> | ||
</QueryClientProvider> | ||
</AppContext.Provider> | ||
) | ||
} | ||
|
||
function ReactQueryTools() { | ||
const { data: experiments } = useExperiments() | ||
return experiments?.developerTools ? ( | ||
<View userSelect="none"> | ||
<ReactQueryDevtools /> | ||
</View> | ||
) : null | ||
} | ||
|
||
export function StyleProvider({ | ||
children, | ||
darkMode, | ||
...rest | ||
}: Omit<TamaguiProviderProps, 'config'> & { darkMode: boolean }) { | ||
return ( | ||
<TamaguiProvider | ||
// @ts-ignore | ||
config={tamaguiConfig} | ||
// TODO: find a way to add this props without breaking all the styles | ||
// disableInjectCSS | ||
// disableRootThemeClass | ||
className={darkMode ? 'seed-app-dark' : 'seed-app-light'} | ||
defaultTheme={darkMode ? 'dark' : 'light'} | ||
{...rest} | ||
> | ||
{children} | ||
</TamaguiProvider> | ||
) | ||
} |
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,91 @@ | ||
import { GRPCClient } from '@shm/shared' | ||
import { createContext, useContext, useEffect } from 'react' | ||
|
||
import { AppIPC, Event, EventCallback } from './app-ipc' | ||
|
||
import { WindowUtils } from './models/window-utils' | ||
import { AppQueryClient } from './query-client' | ||
|
||
|
||
export type AppPlatform = typeof process.platform | ||
|
||
export type AppContext = { | ||
platform: AppPlatform | ||
grpcClient: GRPCClient | ||
queryClient: AppQueryClient | ||
ipc: AppIPC | ||
externalOpen: (url: string) => Promise<void> | ||
windowUtils: WindowUtils | ||
saveCidAsFile: (cid: string, name: string) => Promise<void> | ||
} | ||
|
||
export const AppContext = createContext<AppContext | null>(null) | ||
|
||
|
||
export function useAppContext() { | ||
const context = useContext(AppContext) | ||
if (!context) | ||
throw new Error('useAppContext must be used within a AppContextProvider') | ||
|
||
return context | ||
} | ||
|
||
export function useGRPCClient(): GRPCClient { | ||
const context = useContext(AppContext) | ||
if (!context) | ||
throw new Error('useGRPCClient must be used within a AppContextProvider') | ||
return context.grpcClient | ||
} | ||
|
||
export function useIPC(): AppIPC { | ||
const context = useContext(AppContext) | ||
if (!context) | ||
throw new Error('useIPC must be used within a AppContextProvider') | ||
|
||
return context.ipc | ||
} | ||
|
||
export function useQueryInvalidator() { | ||
const context = useContext(AppContext) | ||
if (!context) | ||
throw new Error( | ||
'useQueryInvalidator must be used within a AppContextProvider', | ||
) | ||
|
||
return context.queryClient.invalidate | ||
} | ||
|
||
export function useWindowUtils(): WindowUtils { | ||
const context = useContext(AppContext) | ||
if (!context) | ||
throw new Error('useWindowUtils must be used within a AppContextProvider') | ||
|
||
return context.windowUtils | ||
} | ||
|
||
export function useListen<T = unknown>( | ||
cmd: string, | ||
handler: EventCallback<T>, | ||
deps: React.DependencyList = [], | ||
) { | ||
const { listen } = useIPC() | ||
useEffect(() => { | ||
if (!listen) { | ||
throw new Error('useListen called before listen is defined') | ||
} | ||
let isSubscribed = true | ||
let unlisten: () => void | ||
|
||
listen(cmd, (event: Event<T>) => { | ||
if (!isSubscribed) { | ||
return unlisten() | ||
} | ||
|
||
handler(event) | ||
}).then((_unlisten) => (unlisten = _unlisten)) | ||
|
||
return () => { | ||
isSubscribed = false | ||
} | ||
}, deps) | ||
} |
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module "*.module.css"; |
Oops, something went wrong.