Skip to content

Commit

Permalink
Merge pull request #70 from RonHouben/styling/apply-backdrop-filter-o…
Browse files Browse the repository at this point in the history
…n-first-render

Styling/apply backdrop filter on first render
  • Loading branch information
RonHouben committed Mar 7, 2021
2 parents 5413ad1 + d36dbbf commit 9869bd7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 93 deletions.
28 changes: 13 additions & 15 deletions components/LoadingScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,19 @@ export default function LoadingScreen() {

return (
<Flex h="xl" justifyContent="center" alignItems="center">
<Flex>
{randomArray.map((k) => (
<Flex
key={k}
justifyContent="center"
alignItems="center"
h="8"
w="8"
rounded="full"
shadow="dark-lg"
backgroundImage={`linear-gradient(to bottom right, ${colors[startColor][colorMode]}, ${colors[endColor][colorMode]})`}
animation={`ping ${randomDuration}s cubic-bezier(0, 0, 0.2, 1) infinite`}
/>
))}
</Flex>
{randomArray.map((k) => (
<Flex
key={k}
justifyContent="center"
alignItems="center"
h="8"
w="8"
rounded="full"
shadow="dark-lg"
bgGradient={`linear(to-br, ${colors[startColor][colorMode]}, ${colors[endColor][colorMode]})`}
animation={`ping ${randomDuration}s cubic-bezier(0, 0, 0.2, 1) infinite`}
/>
))}
</Flex>
)
}
42 changes: 34 additions & 8 deletions hooks/useUserAgent.ts
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
}
20 changes: 5 additions & 15 deletions pages/_app.tsx
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
55 changes: 0 additions & 55 deletions providers/UserAgentProvider.tsx

This file was deleted.

1 comment on commit 9869bd7

@vercel
Copy link

@vercel vercel bot commented on 9869bd7 Mar 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.