Skip to content

Commit

Permalink
header image and video (#557)
Browse files Browse the repository at this point in the history
* header image and video

* fixed issues header and aside

* video and aside margin top
  • Loading branch information
gerouvi committed Feb 26, 2024
1 parent 645ce4d commit 1c70613
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -38,6 +38,7 @@
"react-i18next": "^13.0.1",
"react-icons": "^4.10.1",
"react-markdown": "^8.0.7",
"react-player": "^2.14.1",
"react-router-dom": "^6.14.1",
"remark-gfm": "^3.0.1",
"viem": "^1.16.6",
Expand Down
9 changes: 7 additions & 2 deletions src/components/Process/Header.tsx
@@ -1,5 +1,5 @@
import { WarningIcon } from '@chakra-ui/icons'
import { Box, Button, Flex, Icon, Text } from '@chakra-ui/react'
import { Box, Button, Flex, Icon, Image, Text } from '@chakra-ui/react'
import {
ElectionDescription,
ElectionSchedule,
Expand Down Expand Up @@ -33,13 +33,18 @@ const ProcessHeader = () => {
const showOrgInformation = !loaded || (loaded && organization?.account?.name)

return (
<Box mb={4}>
<Box mb={10}>
{showOrgInformation && (
<Button as={Link} to={`/organization/0x${election?.organizationId}`} variant='go-back' mt={5}>
<GoBack />
<OrganizationName as='span' />
</Button>
)}
{election?.header && (
<Box w='100%' mx='auto' maxH='300px' my='30px' overflow='hidden'>
<Image src={election?.header} w='100%' h='auto' objectFit='cover' />
</Box>
)}
<Flex direction={{ base: 'column', lg2: 'row' }} mb={7} gap={10}>
<Box flexGrow={0} flexShrink={0} flexBasis={{ base: '100%', md: '60%', lg: '65%', lg2: '70%', xl2: '75%' }}>
<ElectionTitle fontSize={{ base: '32px', md: '34px' }} textAlign='left' my={5} />
Expand Down
42 changes: 39 additions & 3 deletions src/components/Process/View.tsx
@@ -1,4 +1,5 @@
import {
AspectRatio,
Box,
Button,
Flex,
Expand All @@ -25,10 +26,11 @@ import {
import { ElectionQuestions, ElectionResults, environment, useConfirm } from '@vocdoni/chakra-components'
import { useClient, useElection } from '@vocdoni/react-providers'
import { ElectionResultsTypeNames, ElectionStatus, PublishedElection } from '@vocdoni/sdk'
import { useEffect, useState } from 'react'
import { useEffect, useRef, useState } from 'react'
import { FieldValues } from 'react-hook-form'
import { Trans, useTranslation } from 'react-i18next'
import { FaFacebook, FaReddit, FaTelegram, FaTwitter } from 'react-icons/fa'
import ReactPlayer from 'react-player'
import ProcessAside, { VoteButton } from './Aside'
import Header from './Header'
import confirmImg from '/assets/spreadsheet-confirm-modal.jpg'
Expand All @@ -37,6 +39,8 @@ import successImg from '/assets/spreadsheet-success-modal.jpg'
export const ProcessView = () => {
const { t } = useTranslation()
const { election } = useElection()
const videoRef = useRef<HTMLDivElement>(null)
const [videoTop, setVideoTop] = useState(false)

const [tabIndex, setTabIndex] = useState(0)

Expand All @@ -46,6 +50,24 @@ export const ProcessView = () => {

const setQuestionsTab = () => setTabIndex(0)

useEffect(() => {
const handleScroll = () => {
if (!videoRef.current) return

const rect = videoRef.current.getBoundingClientRect()
if (rect.top <= 84) {
setVideoTop(true)
} else {
setVideoTop(false)
}
}

window.addEventListener('scroll', handleScroll)
return () => {
window.removeEventListener('scroll', handleScroll)
}
}, [])

useEffect(() => {
if (election?.status === ElectionStatus.RESULTS) setTabIndex(1)
}, [election])
Expand All @@ -54,7 +76,21 @@ export const ProcessView = () => {
<Box>
<Box className='site-wrapper' mb={44}>
<Header />
<Flex direction={{ base: 'column', lg2: 'row' }} alignItems='start' gap={{ lg2: 10 }}>
{election?.streamUri && (
<Box
maxW={{ base: videoTop ? '250px' : '800px', lg: videoTop ? '400px' : '800px' }}
ml={videoTop ? 'auto' : 'none'}
position='sticky'
top={{ base: 0, lg2: 20 }}
zIndex={100}
>
<AspectRatio ref={videoRef} ratio={16 / 9}>
<ReactPlayer url={election?.streamUri} width='100%' height='100%' playing controls />
</AspectRatio>
</Box>
)}

<Flex direction={{ base: 'column', lg2: 'row' }} alignItems='start' gap={{ lg2: 10 }} mt={20}>
<Tabs
order={{ base: 2, lg2: 1 }}
variant='process'
Expand Down Expand Up @@ -93,7 +129,7 @@ export const ProcessView = () => {
gap={0}
mx={{ base: 'auto', lg2: 0 }}
position={{ lg2: 'sticky' }}
top={20}
top={'300px'}
mt={10}
maxW={{ lg2: '290px' }}
mb={10}
Expand Down
27 changes: 24 additions & 3 deletions yarn.lock
Expand Up @@ -4189,7 +4189,7 @@ deep-object-diff@^1.1.9:
resolved "https://registry.yarnpkg.com/deep-object-diff/-/deep-object-diff-1.1.9.tgz#6df7ef035ad6a0caa44479c536ed7b02570f4595"
integrity sha512-Rn+RuwkmkDwCi2/oXOFS9Gsr5lJZu/yTGpK7wAaAIE75CC+LCGEZHpY6VQJa/RoJcrmaA/docWJZvYohlNkWPA==

deepmerge@^4.2.2:
deepmerge@^4.0.0, deepmerge@^4.2.2:
version "4.3.1"
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.3.1.tgz#44b5f2147cd3b00d4b56137685966f26fd25dd4a"
integrity sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==
Expand Down Expand Up @@ -5787,6 +5787,11 @@ lit@2.8.0:
lit-element "^3.3.0"
lit-html "^2.8.0"

load-script@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/load-script/-/load-script-1.0.0.tgz#0491939e0bee5643ee494a7e3da3d2bac70c6ca4"
integrity sha512-kPEjMFtZvwL9TaZo0uZ2ml+Ye9HUMmPwbYRJ324qF9tqMejwykJ5ggTyvzmrbBeapCAbk98BSbTeovHEEP1uCA==

locate-path@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-5.0.0.tgz#1afba396afd676a6d42504d0a67a3a7eb9f62aa0"
Expand Down Expand Up @@ -6030,6 +6035,11 @@ media-query-parser@^2.0.2:
dependencies:
"@babel/runtime" "^7.12.5"

memoize-one@^5.1.1:
version "5.2.1"
resolved "https://registry.npmjs.org/memoize-one/-/memoize-one-5.2.1.tgz#8337aa3c4335581839ec01c3d594090cebe8f00e"
integrity sha512-zYiwtZUcYyXKo/np96AGZAckk+FWWsUdJ3cHGGmld7+AhvcWmQyGCYUh1hc4Q/pkOhb65dQR/pqCyK0cOaHz4Q==

memoize-one@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/memoize-one/-/memoize-one-6.0.0.tgz#b2591b871ed82948aee4727dc6abceeeac8c1045"
Expand Down Expand Up @@ -6842,7 +6852,7 @@ promise-map-series@^0.3.0:
resolved "https://registry.yarnpkg.com/promise-map-series/-/promise-map-series-0.3.0.tgz#41873ca3652bb7a042b387d538552da9b576f8a1"
integrity sha512-3npG2NGhTc8BWBolLLf8l/92OxMGaRLbqvIh9wjCHhDXNvk4zsxaTaCpiCunW09qWPrN2zeNSNwRLVBrQQtutA==

prop-types@^15.0.0, prop-types@^15.6.0, prop-types@^15.6.2, prop-types@^15.8.1:
prop-types@^15.0.0, prop-types@^15.6.0, prop-types@^15.6.2, prop-types@^15.7.2, prop-types@^15.8.1:
version "15.8.1"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5"
integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==
Expand Down Expand Up @@ -6993,7 +7003,7 @@ react-error-boundary@^3.1.4:
dependencies:
"@babel/runtime" "^7.12.5"

react-fast-compare@3.2.2:
react-fast-compare@3.2.2, react-fast-compare@^3.0.1:
version "3.2.2"
resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-3.2.2.tgz#929a97a532304ce9fee4bcae44234f1ce2c21d49"
integrity sha512-nsO+KSNgo1SbJqJEYRE9ERzo7YtYbou/OqjSQKxV7jcKox7+usiUVZOAC+XnDOABXggQTno0Y1CpVnuWEc1boQ==
Expand Down Expand Up @@ -7064,6 +7074,17 @@ react-markdown@^8.0.7:
unist-util-visit "^4.0.0"
vfile "^5.0.0"

react-player@^2.14.1:
version "2.14.1"
resolved "https://registry.npmjs.org/react-player/-/react-player-2.14.1.tgz#fc434c0e1e6161e76f5d5970721596c4acec52b1"
integrity sha512-jILj7F9o+6NHzrJ1GqZIxfJgskvGmKeJ05FNhPvgiCpvMZFmFneKEkukywHcULDO2lqITm+zcEkLSq42mX0FbA==
dependencies:
deepmerge "^4.0.0"
load-script "^1.0.0"
memoize-one "^5.1.1"
prop-types "^15.7.2"
react-fast-compare "^3.0.1"

react-refresh@^0.14.0:
version "0.14.0"
resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.14.0.tgz#4e02825378a5f227079554d4284889354e5f553e"
Expand Down

2 comments on commit 1c70613

@github-actions
Copy link

Choose a reason for hiding this comment

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

@github-actions
Copy link

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.