-
Notifications
You must be signed in to change notification settings - Fork 240
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
26 changed files
with
266 additions
and
122 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
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
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,72 @@ | ||
import { | ||
usePathname, | ||
useRouter as useRouterNavigation, | ||
useSearchParams, | ||
useSelectedLayoutSegment, | ||
} from 'next/navigation'; | ||
import { useRouter as useRouterPages } from 'next/router'; | ||
import { useMemo } from 'react'; | ||
|
||
const useRouteName = (): string => { | ||
let pathname = usePathname(); | ||
|
||
try { | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
pathname = useSelectedLayoutSegment() as string; | ||
} catch (error) { | ||
// throws because we are inside pages directory | ||
} | ||
|
||
try { | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
const pagesRouter = useRouterPages(); | ||
pathname = pagesRouter.pathname; | ||
} catch (error) { | ||
// throws because we are inside apps directory | ||
} | ||
|
||
return pathname as string; | ||
}; | ||
|
||
export const useRouter: typeof useRouterPages = () => { | ||
const route = useRouteName(); | ||
const pathname = usePathname(); | ||
const searchParams = useSearchParams(); | ||
const routerNavigation = useRouterNavigation(); | ||
|
||
return { | ||
pathname, | ||
push: async (url, as, options) => { | ||
routerNavigation.push(as?.toString() || url.toString(), options); | ||
|
||
return true; | ||
}, | ||
replace: async (url, as, options) => { | ||
routerNavigation.replace(as?.toString() || url.toString(), options); | ||
|
||
return true; | ||
}, | ||
query: useMemo(() => { | ||
return Object.fromEntries(searchParams.entries()); | ||
}, [searchParams]), | ||
route, | ||
basePath: pathname, | ||
asPath: pathname, | ||
isLocaleDomain: false, | ||
isReady: true, | ||
isFallback: false, | ||
events: { | ||
on: () => {}, | ||
off: () => {}, | ||
emit: () => {}, | ||
}, | ||
back: routerNavigation.back, | ||
forward: routerNavigation.forward, | ||
prefetch: async (url, as) => { | ||
routerNavigation.prefetch(as?.toString() || url.toString()); | ||
}, | ||
beforePopState: () => {}, | ||
reload: routerNavigation.refresh, | ||
isPreview: false, | ||
}; | ||
}; |
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,55 @@ | ||
'use client'; | ||
|
||
import { BootDataProvider } from '@dailydotdev/shared/src/contexts/BootProvider'; | ||
import { ProgressiveEnhancementContextProvider } from '@dailydotdev/shared/src/contexts/ProgressiveEnhancementContext'; | ||
import { PushNotificationContextProvider } from '@dailydotdev/shared/src/contexts/PushNotificationContext'; | ||
import { SubscriptionContextProvider } from '@dailydotdev/shared/src/contexts/SubscriptionContext'; | ||
import { useManualScrollRestoration } from '@dailydotdev/shared/src/hooks'; | ||
import useDeviceId from '@dailydotdev/shared/src/hooks/log/useDeviceId'; | ||
import { useError } from '@dailydotdev/shared/src/hooks/useError'; | ||
import { BootApp } from '@dailydotdev/shared/src/lib/boot'; | ||
import { defaultQueryClientConfig } from '@dailydotdev/shared/src/lib/query'; | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'; | ||
import React, { ReactElement, ReactNode, useState } from 'react'; | ||
import useWebappVersion from '../hooks/useWebappVersion'; | ||
|
||
const getRedirectUri = () => | ||
`${window.location.origin}${window.location.pathname}`; | ||
|
||
const getPage = () => window.location.pathname; | ||
|
||
export const Providers = ({ | ||
children, | ||
}: Readonly<{ | ||
children: ReactNode; | ||
}>): ReactElement => { | ||
const [queryClient] = useState( | ||
() => new QueryClient(defaultQueryClientConfig), | ||
); | ||
const version = useWebappVersion(); | ||
const deviceId = useDeviceId(); | ||
useError(); | ||
useManualScrollRestoration(); | ||
|
||
return ( | ||
<ProgressiveEnhancementContextProvider> | ||
<QueryClientProvider client={queryClient}> | ||
<BootDataProvider | ||
app={BootApp.Webapp} | ||
getRedirectUri={getRedirectUri} | ||
getPage={getPage} | ||
version={version} | ||
deviceId={deviceId} | ||
> | ||
<PushNotificationContextProvider> | ||
<SubscriptionContextProvider> | ||
{children} | ||
</SubscriptionContextProvider> | ||
</PushNotificationContextProvider> | ||
</BootDataProvider> | ||
<ReactQueryDevtools /> | ||
</QueryClientProvider> | ||
</ProgressiveEnhancementContextProvider> | ||
); | ||
}; |
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,40 @@ | ||
import '@dailydotdev/shared/src/styles/globals.css'; | ||
|
||
import React, { ReactElement, ReactNode } from 'react'; | ||
import { Providers } from './Providers'; | ||
|
||
const RootLayout = ({ | ||
children, | ||
}: Readonly<{ | ||
children: ReactNode; | ||
}>): ReactElement => { | ||
return ( | ||
<html lang="en"> | ||
<head> | ||
<link | ||
rel="apple-touch-icon" | ||
sizes="180x180" | ||
href="/apple-touch-icon.png" | ||
/> | ||
<link | ||
rel="icon" | ||
type="image/png" | ||
sizes="32x32" | ||
href="/favicon-32x32.png" | ||
/> | ||
<link | ||
rel="icon" | ||
type="image/png" | ||
sizes="16x16" | ||
href="/favicon-16x16.png" | ||
/> | ||
<link rel="manifest" href="/site.webmanifest" /> | ||
</head> | ||
<body> | ||
<Providers>{children}</Providers> | ||
</body> | ||
</html> | ||
); | ||
}; | ||
|
||
export default RootLayout; |
Oops, something went wrong.