Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» chore: add an isMobile selector
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed May 2, 2024
1 parent 22cd8fb commit 5280cb7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/layout/GlobalProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { getServerGlobalConfig } from '@/server/globalConfig';
import { ServerConfigStoreProvider } from '@/store/serverConfig';
import { getAntdLocale } from '@/utils/locale';
import { isMobileDevice } from '@/utils/responsive';

import AppTheme from './AppTheme';
import Locale from './Locale';
Expand Down Expand Up @@ -48,6 +49,7 @@ const GlobalLayout = async ({ children }: GlobalLayoutProps) => {
// get default feature flags to use with ssr
const serverFeatureFlags = getServerFeatureFlagsValue();
const serverConfig = getServerGlobalConfig();
const isMobile = isMobileDevice();
return (
<StyleRegistry>
<Locale antdLocale={antdLocale} defaultLang={defaultLang?.value}>
Expand All @@ -57,7 +59,11 @@ const GlobalLayout = async ({ children }: GlobalLayoutProps) => {
defaultPrimaryColor={primaryColor?.value as any}
>
<StoreInitialization />
<ServerConfigStoreProvider featureFlags={serverFeatureFlags} serverConfig={serverConfig}>
<ServerConfigStoreProvider
featureFlags={serverFeatureFlags}
isMobile={isMobile}
serverConfig={serverConfig}
>
{children}
</ServerConfigStoreProvider>
<DebugUI />
Expand Down
5 changes: 3 additions & 2 deletions src/store/serverConfig/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import { Provider, createServerConfigStore } from './store';
interface GlobalStoreProviderProps {
children: ReactNode;
featureFlags?: Partial<IFeatureFlags>;
isMobile?: boolean;
serverConfig?: GlobalServerConfig;
}

export const ServerConfigStoreProvider = memo<GlobalStoreProviderProps>(
({ children, featureFlags, serverConfig }) => (
<Provider createStore={() => createServerConfigStore({ featureFlags, serverConfig })}>
({ children, featureFlags, serverConfig, isMobile }) => (
<Provider createStore={() => createServerConfigStore({ featureFlags, isMobile, serverConfig })}>
{children}
</Provider>
),
Expand Down
1 change: 1 addition & 0 deletions src/store/serverConfig/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export const featureFlagsSelectors = (s: ServerConfigStore) =>
export const serverConfigSelectors = {
enabledOAuthSSO: (s: ServerConfigStore) => s.serverConfig.enabledOAuthSSO,
enabledTelemetryChat: (s: ServerConfigStore) => s.serverConfig.telemetry.langfuse || false,
isMobile: (s: ServerConfigStore) => s.isMobile || false,
};
1 change: 1 addition & 0 deletions src/store/serverConfig/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const initialState: ServerConfigStore = {

export interface ServerConfigStore {
featureFlags: IFeatureFlags;
isMobile?: boolean;
serverConfig: GlobalServerConfig;
}

Expand Down

0 comments on commit 5280cb7

Please sign in to comment.