Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
feat: sphere image in hero for safari browser
Browse files Browse the repository at this point in the history
  • Loading branch information
oxiqod committed Jun 17, 2024
1 parent 9d30826 commit 2c29628
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 61 deletions.
9 changes: 9 additions & 0 deletions landing/entrypoints/renderer/src/public/sphere.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Browser } from '../landing-hero.constants'

export const defineSafariBrowser = (): boolean => {
if (typeof navigator !== 'undefined') {
const userAgent = navigator.userAgent.toLowerCase()

return (
userAgent.includes(Browser.SAFARI) &&
!userAgent.includes(Browser.CHROME) &&
!userAgent.includes(Browser.OPERA) &&
!userAgent.includes(Browser.YANDEX) &&
!userAgent.includes(Browser.FIREFOX)
)
}

return false
}
1 change: 1 addition & 0 deletions landing/fragments/landing-hero/src/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './define-safari-browser.helper'
74 changes: 26 additions & 48 deletions landing/fragments/landing-hero/src/landing-hero.component.tsx
Original file line number Diff line number Diff line change
@@ -1,56 +1,31 @@
import React from 'react'
import { FastAverageColor } from 'fast-average-color'
import { FastAverageColorResult } from 'fast-average-color'
import { FC } from 'react'
import { useEffect } from 'react'
import { useState } from 'react'
import React from 'react'
import { FC } from 'react'
import { useState } from 'react'

import { Layout } from '@ui/layout'
import { Column } from '@ui/layout'
import { Box } from '@ui/layout'
import { AnimateOnLoad } from '@ui/preloader'
import { extractObject } from '@globals/data'
import { Condition } from '@ui/condition'
import { Image } from '@ui/image'
import { Layout } from '@ui/layout'
import { Column } from '@ui/layout'
import { Box } from '@ui/layout'
import { AnimateOnLoad } from '@ui/preloader'
import { extractObject } from '@globals/data'

import { Content } from './content'
import { CDN_VIDEO_MINE } from './landing-hero.constants'
import { FAST_BLACK_COLOR_RGBA } from './landing-hero.constants'
import { CDN_VIDEO_PATH } from './landing-hero.constants'
import { HeroProps } from './landing-hero.interface'
import { Video } from './video'
import { useHero } from './data'

const fac = new FastAverageColor()
import { Content } from './content'
import { HeroProps } from './landing-hero.interface'
import { Sphere } from './sphere/sphere.component'
import { useHero } from './data'
import { defineSafariBrowser } from './helpers'

const LandingHero: FC<HeroProps> = ({ language }) => {

const isSafari = defineSafariBrowser()

const { heroData } = useHero()

const [backgroundColor, setBackgroundColor] = useState<string>('background.purple')
const [videoIsPlaying, setVideoIsPlaying] = useState<boolean>(false)

const { title, content } = extractObject('contentAddons', 'lead', heroData[language])

useEffect(() => {
if (!videoIsPlaying) return

const videoElement = document.querySelector('video')

const getColor = () => {
try {
let color: FastAverageColorResult | undefined

color = fac.getColor(videoElement, { algorithm: 'dominant' })
if (color.value.every(value => value === 0)) return

setBackgroundColor(color?.rgb)
} catch (error) {
if (process.env.NODE_ENV !== 'production') throw error
}
}

getColor()
}, [videoIsPlaying])


return (
<Box
height={['auto', 'auto', '100vh']}
Expand All @@ -67,11 +42,14 @@ const LandingHero: FC<HeroProps> = ({ language }) => {
animation={{ y: 0, opacity: 1 }}
delay={600}
>
<Video
mimeType={CDN_VIDEO_MINE}
src={CDN_VIDEO_PATH}
onPlay={() => setVideoIsPlaying(true)}
/>
<Condition match={!isSafari}>
<Sphere setBackgroundColor={setBackgroundColor} />
</Condition>
<Condition match={isSafari}>
<Layout>
<Image src='/sphere.svg' width={630} height={630} />
</Layout>
</Condition>
</AnimateOnLoad>
<Layout marginRight='120px' />
<Layout display={['flex', 'flex', 'none']} height={80} />
Expand Down
8 changes: 8 additions & 0 deletions landing/fragments/landing-hero/src/landing-hero.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ export const messages = {

export const sphereStyleDesktop = { width: 600, height: 600 }
export const sphereStyleMobile = { width: 300, height: 300 }

export enum Browser {
SAFARI = 'safari',
CHROME = 'chrome',
OPERA = 'opr',
YANDEX = 'yabrowser',
FIREFOX = 'firefox',
}
41 changes: 41 additions & 0 deletions landing/fragments/landing-hero/src/sphere/sphere.component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react'
import { FastAverageColorResult } from 'fast-average-color'
import { FastAverageColor } from 'fast-average-color'
import { useEffect } from 'react'
import { useState } from 'react'

import { CDN_VIDEO_PATH } from '../landing-hero.constants'
import { CDN_VIDEO_MINE } from '../landing-hero.constants'
import { Video } from '../video'

const fac = new FastAverageColor()

export const Sphere = ({ setBackgroundColor }) => {
const [videoIsPlaying, setVideoIsPlaying] = useState<boolean>(false)

useEffect(() => {
if (!videoIsPlaying) return

const videoElement = document.querySelector('video')

const getColor = () => {
try {
let color: FastAverageColorResult | undefined

// eslint-disable-next-line prefer-const
color = fac.getColor(videoElement, { algorithm: 'dominant' })
if (color.value.every((value) => value === 0)) return

setBackgroundColor(color?.rgb)
} catch (error) {
if (process.env.NODE_ENV !== 'production') throw error
}
}

getColor()
}, [videoIsPlaying, setBackgroundColor])

return (
<Video mimeType={CDN_VIDEO_MINE} src={CDN_VIDEO_PATH} onPlay={() => setVideoIsPlaying(true)} />
)
}
9 changes: 4 additions & 5 deletions landing/pages/contacts-page/src/get-static-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { GET_SEO } from '@globals/data'
import { PageUri } from '@globals/data'
import { GET_CONTACTS } from '@landing/contacts-fragment'
import { GET_NAVIGATION } from '@landing/navigation-fragment'
import { GET_FORMS } from '@ui/form'
import { initializeApollo } from '@globals/data'
import { addApolloState } from '@globals/data'
import {GET_FORMS} from '@ui/form'

export const getStaticProps = async () => {
const client = initializeApollo({})
Expand All @@ -22,12 +22,11 @@ export const getStaticProps = async () => {

const formsPromise = client.query({ query: GET_FORMS })


;[seoContent, navigationContent, contactsContent,formsContent] = await Promise.allSettled([
;[seoContent, navigationContent, contactsContent, formsContent] = await Promise.allSettled([
seoPromise,
navigationPromise,
contactsPromise,
formsPromise
formsPromise,
])

const SEO = {
Expand All @@ -43,7 +42,7 @@ export const getStaticProps = async () => {
SEO,
navigationData,
contactsData,
formsData
formsData,
},
revalidate: 3600,
})
Expand Down
11 changes: 5 additions & 6 deletions landing/pages/index-page/src/get-static-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { GET_NAVIGATION } from '@landing/navigation-fragment'
import { GET_REVIEWS } from '@landing/reviews-fragment'
import { GET_RECRUITS } from '@landing/team-fragment'
import { GET_SKILLS } from '@landing/work-directions-fragment'
import { GET_FORMS } from '@ui/form'
import { addApolloState } from '@globals/data'
import { initializeApollo } from '@globals/data'
import {GET_FORMS} from '@ui/form'
export const getStaticProps = async () => {
const client = initializeApollo({})

Expand All @@ -26,7 +26,7 @@ export const getStaticProps = async () => {
feedbackContent,
skillsContent,
recruitsContent,
formsContent
formsContent

const seoPromise = client.query({ query: GET_SEO, variables: { uri: PageUri.INDEX } })
const navigationPromise = client.query({ query: GET_NAVIGATION })
Expand All @@ -40,7 +40,6 @@ export const getStaticProps = async () => {
const recruitsPromise = client.query({ query: GET_RECRUITS })
const formsPromise = client.query({ query: GET_FORMS })


;[
seoContent,
navigationContent,
Expand All @@ -52,7 +51,7 @@ export const getStaticProps = async () => {
feedbackContent,
skillsContent,
recruitsContent,
formsContent
formsContent,
] = await Promise.allSettled([
seoPromise,
navigationPromise,
Expand All @@ -63,7 +62,7 @@ export const getStaticProps = async () => {
feedbackPromise,
skillsPromise,
recruitsPromise,
formsPromise
formsPromise,
])

const SEO = {
Expand Down Expand Up @@ -93,7 +92,7 @@ export const getStaticProps = async () => {
feedbackData,
skillsData,
recruitsData,
formData
formData,
},
revalidate: 3600,
})
Expand Down
4 changes: 2 additions & 2 deletions landing/pages/index-page/src/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const IndexPage: FC<IndexPageProps> = ({ SEO }) => {
const language = useReactiveVar<Language>(languageVar)
const containerRef = useRef(null)
return (
<Preloader seconds={6}>
<Preloader>
<LocomotiveScrollProvider
options={LOCOMOTIVE_SCROLL_OPTIONS}
watch={LOCOMOTIVE_SCROLL_WATCH}
Expand All @@ -43,7 +43,7 @@ const IndexPage: FC<IndexPageProps> = ({ SEO }) => {
<LandingFooter language={language} />
</ScrollContainer>
</LocomotiveScrollProvider>
</Preloader>
</Preloader>
)
}

Expand Down

0 comments on commit 2c29628

Please sign in to comment.