-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from RonHouben/styling/apply-backdrop-filter-o…
…n-first-render Styling/apply backdrop filter on first render
- Loading branch information
Showing
4 changed files
with
52 additions
and
93 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,34 @@ | ||
import { useContext } from 'react' | ||
import { | ||
IUserAgentContext, | ||
UserAgentContext, | ||
} from '../providers/UserAgentProvider' | ||
|
||
export const useUserAgent = () => | ||
useContext<IUserAgentContext>(UserAgentContext) | ||
import { useEffect, useState } from 'react' | ||
|
||
interface IUserAgentResult { | ||
browser: 'Chrome' | 'Safari' | 'Firefox' | undefined | ||
isChrome: boolean | ||
isSafari: boolean | ||
isFirefox: boolean | ||
} | ||
|
||
export const useUserAgent = (): IUserAgentResult => { | ||
const [browser, setBrowser] = useState<IUserAgentResult['browser']>() | ||
|
||
if (process.browser && navigator) { | ||
useEffect(() => { | ||
setBrowser(getBrowser(navigator.userAgent)) | ||
}, [navigator.userAgent]) | ||
} | ||
|
||
return { | ||
browser, | ||
isChrome: browser === 'Chrome', | ||
isFirefox: browser === 'Firefox', | ||
isSafari: browser === 'Safari', | ||
} | ||
} | ||
|
||
// helper functions | ||
const getBrowser = (userAgent: NavigatorID['userAgent']) => { | ||
const regexMatch = userAgent | ||
? userAgent.match(/Chrome|Safari|Firefox/) | ||
: undefined | ||
|
||
return regexMatch ? (regexMatch[0] as IUserAgentResult['browser']) : undefined | ||
} |
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,29 +1,19 @@ | ||
import { IncomingHttpHeaders } from 'http' | ||
import { AppContext, AppProps } from 'next/app' | ||
import { AppProps } from 'next/app' | ||
import React from 'react' | ||
import initAuth from '../lib/initAuth' | ||
import ChakraProvider from '../providers/Chakra' | ||
import { UserAgentProvider } from '../providers/UserAgentProvider' | ||
|
||
initAuth() | ||
interface Props extends AppProps { | ||
cookies: string | ||
userAgent: IncomingHttpHeaders['user-agent'] | ||
} | ||
|
||
function App({ Component, pageProps, cookies, userAgent }: Props) { | ||
function App({ Component, pageProps, cookies }: Props) { | ||
return ( | ||
<UserAgentProvider userAgent={userAgent}> | ||
<ChakraProvider cookies={cookies}> | ||
<Component {...pageProps} /> | ||
</ChakraProvider> | ||
</UserAgentProvider> | ||
<ChakraProvider cookies={cookies}> | ||
<Component {...pageProps} /> | ||
</ChakraProvider> | ||
) | ||
} | ||
|
||
// SSR to get the client browser. This can later be used to apply styling for a specific browser | ||
App.getInitialProps = async (app: AppContext) => { | ||
return { userAgent: app.ctx.req?.headers['user-agent'] } | ||
} | ||
|
||
export default App |
This file was deleted.
Oops, something went wrong.
9869bd7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: