Skip to content

Commit 60e9375

Browse files
berentebIsti01
andauthored
Image carousel revive (#763)
* feat: revive image carousel * Display gallery on home page --------- Co-authored-by: Horváth István <[email protected]>
1 parent d7057e4 commit 60e9375

File tree

7 files changed

+73
-25
lines changed

7 files changed

+73
-25
lines changed

frontend/src/api/contexts/config/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface Components {
2323
extraPage: ExtraPage
2424
groupselection: GroupSelection
2525
home: Home
26+
gallery: Gallery
2627
impressum: Impressum
2728
leaderboard: Leaderboard
2829
location: Location
@@ -108,6 +109,11 @@ export interface Home {
108109
youtubeVideoIds: string
109110
showEvents: boolean
110111
showNews: boolean
112+
showGalleryImages: boolean
113+
}
114+
115+
export interface Gallery {
116+
title: string
111117
}
112118

113119
export interface News {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { useQuery } from '@tanstack/react-query'
2+
import { QueryKeys } from '../queryKeys.ts'
3+
import axios from 'axios'
4+
import { ApiPaths } from '../../../util/paths.ts'
5+
import { GalleryView } from '../../../util/views/gallery.view.ts'
6+
7+
export const useHomeGallery = () => {
8+
return useQuery<GalleryView, Error>({
9+
queryKey: [QueryKeys.HOME_GALLERY],
10+
queryFn: async () => {
11+
const response = await axios.get<GalleryView>(ApiPaths.HOME_GALLERY)
12+
return response.data
13+
}
14+
})
15+
}

frontend/src/api/hooks/queryKeys.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ export enum QueryKeys {
2929
ORGANIZATION = 'ORGANIZATION',
3030
ACCESS_KEY = 'ACCESS_KEY',
3131
HOME_NEWS = 'HOME_NEWS',
32-
DEBTS = 'DEBTS'
32+
DEBTS = 'DEBTS',
33+
HOME_GALLERY = 'HOME_GALLERY'
3334
}
Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { ChevronLeftIcon, ChevronRightIcon } from '@chakra-ui/icons'
2-
import { Box, Button, ButtonGroup, Flex, Image, useColorModeValue } from '@chakra-ui/react'
2+
import { Box, Button, ButtonGroup, Flex, IconButton, Image } from '@chakra-ui/react'
33
import { useState } from 'react'
4-
import { MapImageView } from '../../../util/views/mapImage.view'
54

65
type ImageCarouselProps = {
7-
images: MapImageView[]
6+
images: string[]
87
}
98

109
export const ImageCarousel = ({ images }: ImageCarouselProps) => {
1110
const [currentImageIndex, setCurrentImageIndex] = useState<number>(0)
11+
1212
const previousImage = () => {
1313
const previousIndex = currentImageIndex - 1
1414
setCurrentImageIndex(previousIndex < 0 ? images.length - 1 : previousIndex)
@@ -18,28 +18,31 @@ export const ImageCarousel = ({ images }: ImageCarouselProps) => {
1818
setCurrentImageIndex(nextIndex > images.length - 1 ? 0 : nextIndex)
1919
}
2020
if (images.length === 0) return null
21+
2122
return (
22-
<Box marginTop={10}>
23-
{images.map((image, index) => (
24-
<Image
25-
key={index}
26-
src={useColorModeValue(image.light, image.dark)}
27-
w="100%"
28-
maxH="50rem"
29-
objectFit="contain"
30-
display={index === currentImageIndex ? 'block' : 'none'}
31-
/>
32-
))}
33-
<Flex marginTop={5} justify="space-between">
23+
<Flex flexDirection="column" marginTop={10} overflowX="clip">
24+
<Flex
25+
width={`${images.length * 100}%`}
26+
flexDirection="row"
27+
transform={`translateX(-${(currentImageIndex / images.length) * 100}%)`}
28+
transition="transform .5s"
29+
>
30+
{images.map((image) => (
31+
<Box flex={1} key={image} alignItems="center" display="flex">
32+
<Image src={image} w="100%" maxH="50rem" objectFit="contain" objectPosition="center" />
33+
</Box>
34+
))}
35+
</Flex>
36+
<Flex paddingTop={5} alignItems="center" justify="space-between">
3437
<DirectionButton direction={Directions.LEFT} onClick={previousImage} />
35-
<ButtonGroup>
38+
<ButtonGroup display="flex" alignItems="center">
3639
{images.map((_image, index) => (
3740
<CurrentImageIndicatorDot key={index} index={index} currentIndex={currentImageIndex} onClick={setCurrentImageIndex} />
3841
))}
3942
</ButtonGroup>
4043
<DirectionButton direction={Directions.RIGHT} onClick={nextImage} />
4144
</Flex>
42-
</Box>
45+
</Flex>
4346
)
4447
}
4548

@@ -51,17 +54,17 @@ type CurrentImageIndicatorDotProps = {
5154

5255
const CurrentImageIndicatorDot = ({ index, currentIndex, onClick }: CurrentImageIndicatorDotProps) => (
5356
<Button
54-
height={10}
55-
width={10}
57+
height="10px"
58+
width="10px"
5659
padding={0}
5760
borderWidth={2}
5861
borderStyle="solid"
59-
borderColor="gray.500"
62+
borderColor="brand.500"
6063
borderRadius="full"
6164
cursor="pointer"
6265
transition="border-width .1s"
6366
_hover={{ borderWidth: 10 }}
64-
backgroundColor={index === currentIndex ? 'gray.500' : 'transparent'}
67+
backgroundColor={index === currentIndex ? 'brand.500' : 'transparent'}
6568
onClick={() => {
6669
onClick(index)
6770
}}
@@ -78,7 +81,12 @@ enum Directions {
7881
}
7982

8083
const DirectionButton = ({ direction, onClick }: DirectionButtonProps) => (
81-
<Button onClick={onClick} fontSize="6xl" padding={0} variant="ghost" color="gray.500">
82-
{direction === Directions.LEFT ? <ChevronLeftIcon /> : <ChevronRightIcon />}
83-
</Button>
84+
<IconButton
85+
icon={direction === Directions.LEFT ? <ChevronLeftIcon /> : <ChevronRightIcon />}
86+
colorScheme="brand"
87+
onClick={onClick}
88+
padding={0}
89+
variant="ghost"
90+
aria-label={direction === Directions.LEFT ? 'Előző kép' : 'következő kép'}
91+
/>
8492
)

frontend/src/pages/home/home.page.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ import { NewsArticleView } from '../../util/views/news.view'
1414
import Clock from '../countdown/components/clock'
1515
import NewsListItem from '../news/components/NewsListItem'
1616
import { EmbeddedVideo } from './components/EmbeddedVideo'
17+
import { ImageCarousel } from './components/ImageCarousel.tsx'
1718
import { Schedule } from './components/Schedule'
19+
import { useHomeGallery } from '../../api/hooks/gallery/useHomeGallery.ts'
1820

1921
const HomePage = () => {
2022
const homeNews = useHomeNews()
2123
const eventList = useEventListQuery()
24+
const homeGallery = useHomeGallery()
2225
const config = useConfigContext()
2326
const countdownConfig = config?.components.countdown
2427
const homeConfig = config?.components.home
@@ -128,6 +131,10 @@ const HomePage = () => {
128131
</VStack>
129132
</VStack>
130133
)}
134+
135+
{homeConfig.showGalleryImages && config.components.gallery && homeGallery.data && (
136+
<ImageCarousel images={homeGallery.data?.photos?.map((item) => item.url) ?? []} />
137+
)}
131138
</CmschPage>
132139
)
133140
}

frontend/src/util/paths.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export enum ApiPaths {
8888
ORGANIZATION = '/api/organization',
8989
ACCESS_KEY = '/api/access-key',
9090
HOME_NEWS = '/api/home/news',
91+
HOME_GALLERY = '/api/gallery/home',
9192
ADD_PUSH_NOTIFICATION_TOKEN = '/api/pushnotification/add-token',
9293
DELETE_PUSH_NOTIFICATION_TOKEN = '/api/pushnotification/delete-token',
9394
MY_TEAM = '/api/team/my',
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export type GalleryView = {
2+
photos: GalleryItemView[]
3+
}
4+
5+
export type GalleryItemView = {
6+
title: string
7+
highlighted: boolean
8+
showOnHomePage: boolean
9+
url: string
10+
}

0 commit comments

Comments
 (0)