From 068a7f83f6c76a44586e637e90b93018459446b2 Mon Sep 17 00:00:00 2001 From: Hailey Date: Fri, 7 Jun 2024 10:59:46 -0700 Subject: [PATCH] add entry hook for web --- src/App.web.tsx | 2 ++ .../StarterPack/StarterPackEntryProvider.tsx | 26 ------------------- src/components/hooks/useStarterPackEntry.ts | 15 +++++++++++ 3 files changed, 17 insertions(+), 26 deletions(-) delete mode 100644 src/components/StarterPack/StarterPackEntryProvider.tsx create mode 100644 src/components/hooks/useStarterPackEntry.ts diff --git a/src/App.web.tsx b/src/App.web.tsx index 5c4dc4e637..b8a493b5ee 100644 --- a/src/App.web.tsx +++ b/src/App.web.tsx @@ -39,6 +39,7 @@ import {ToastContainer} from 'view/com/util/Toast.web' import {Shell} from 'view/shell/index' import {ThemeProvider as Alf} from '#/alf' import {useColorModeTheme} from '#/alf/util/useColorModeTheme' +import {useStarterPackEntry} from '#/components/hooks/useStarterPackEntry' import {Provider as PortalProvider} from '#/components/Portal' import {BackgroundNotificationPreferencesProvider} from '../modules/expo-background-notification-handler/src/BackgroundNotificationHandlerProvider' import I18nProvider from './locale/i18nProvider' @@ -51,6 +52,7 @@ function InnerApp() { const theme = useColorModeTheme() const {_} = useLingui() useIntentHandler() + useStarterPackEntry() // init useEffect(() => { diff --git a/src/components/StarterPack/StarterPackEntryProvider.tsx b/src/components/StarterPack/StarterPackEntryProvider.tsx deleted file mode 100644 index 6651ed28ab..0000000000 --- a/src/components/StarterPack/StarterPackEntryProvider.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import React from 'react' - -interface IStarterPackEntryContext { - isReady?: boolean - starterPackId?: string -} - -const StarterPackEntryContext = React.createContext({ - isReady: false, -}) -export const useStarterPackEntry = () => - React.useContext(StarterPackEntryContext) - -export function StarterPackEntryProvider() { - const [state] = React.useState({ - isReady: false, - }) - - React.useEffect(() => {}, []) - - return ( - - {children} - - ) -} diff --git a/src/components/hooks/useStarterPackEntry.ts b/src/components/hooks/useStarterPackEntry.ts new file mode 100644 index 0000000000..5dfb476eea --- /dev/null +++ b/src/components/hooks/useStarterPackEntry.ts @@ -0,0 +1,15 @@ +import React from 'react' + +import {useSetStarterPack} from 'state/preferences/starter-pack' + +export function useStarterPackEntry() { + const setStarterPack = useSetStarterPack() + + React.useEffect(() => { + const url = new URL(window.location.href) + const pathParts = url.pathname.split('/') + if (pathParts[0] === 'start' && pathParts.length === 2) { + setStarterPack(pathParts[1]) + } + }, [setStarterPack]) +}