Skip to content

Commit

Permalink
Fix map tooltip style, add media carousel commented
Browse files Browse the repository at this point in the history
  • Loading branch information
barbara-chaves committed Dec 11, 2023
1 parent 20fe943 commit 6614108
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 8 deletions.
2 changes: 1 addition & 1 deletion client/src/components/map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const MapMapbox: FC<CustomMapProps> = ({
if (!bounds) return undefined;

const { options } = bounds;
const animationDuration = options?.duration || 0;
const animationDuration = options?.duration || 1000;
let timeoutId: number;

if (isFlying) {
Expand Down
9 changes: 6 additions & 3 deletions client/src/components/map/layers/marker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Marker = (props: MarkerProps) => {
const { properties, onClick } = props;
return (
<RMarker {...props}>
<Tooltip delayDuration={0}>
<Tooltip open delayDuration={0}>
<TooltipTrigger asChild>
<div
className={cn({
Expand All @@ -36,7 +36,10 @@ const Marker = (props: MarkerProps) => {
</div>
</div>
</TooltipTrigger>
<TooltipContent asChild>
<TooltipContent
className="bg-[rgba(51, 94, 111, 0.50)] max-w-[230px] p-4 text-white backdrop-blur-lg"
asChild
>
<div onMouseMove={(e) => e.stopPropagation()}>
<div className="mb-2 flex items-center space-x-4">
<CategoryIcon
Expand All @@ -50,7 +53,7 @@ const Marker = (props: MarkerProps) => {

<Button
variant="secondary"
className="h-8 w-full rounded-3xl bg-teal-500 py-2 text-xs text-white"
className="h-8 w-full rounded-3xl bg-teal-500 py-2 text-xs text-white hover:bg-teal-500/50"
onClick={onClick}
>
Discover story
Expand Down
143 changes: 143 additions & 0 deletions client/src/containers/map/markers/story-markers/carousel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { useState } from 'react';

import Image from 'next/image';

import { motion } from 'framer-motion';

const medias = [
{
id: 0,
img: `${process.env.NEXT_PUBLIC_BASE_PATH}/images/mock/carousel.png`,
legend: 'Summary of GDA Urban EO Information and Use Cases 1',
},
{
id: 1,
video: 'https://youtu.be/vCzmxg9y7gA?si=JLwAHz3sPJzNR3DM',
legend: 'Summary of GDA Urban EO Information and Use Cases 2',
},
{
id: 2,
img: `${process.env.NEXT_PUBLIC_BASE_PATH}/images/mock/carousel.png`,
legend: 'Summary of GDA Urban EO Information and Use Cases 3',
},
];

type CarouselMediaProps = {
media: any;
isCurrentMedia?: boolean;
};

const CarouselMedia = ({ media, isCurrentMedia }: CarouselMediaProps) => {
if (media?.type === 'video') {
return (
<video
width="100%"
height="100%"
src={media?.url}
muted={!isCurrentMedia}
loop
controls={isCurrentMedia}
autoPlay={isCurrentMedia}
className=""
>
<source src={media.url} type={media.mime} />
</video>
);
}
return (
<Image
src={media?.url}
className="h-full w-full object-cover"
height={1200}
width={500}
alt="mock"
/>
);
};

type CarouselProps = {
medias: any[];
currentMedia: number;
setCurrentMedia: (currentMedia: number) => void;
};

const Carousel = ({ medias, currentMedia, setCurrentMedia }: CarouselProps) => {
const setPrevImage = () => {
setCurrentMedia(currentMedia - 1);
};

const setNextImage = () => {
setCurrentMedia(currentMedia + 1);
};

const variants = {
show: {
opacity: 1,
transition: {
ease: 'easeOut',
duration: 0.3,
},
},
hide: {
opacity: 0,
},
};

return (
<div className="mb-24 flex h-screen flex-col">
<p className="flex-0 font-notes mt-10 text-center text-2xl text-white">
{currentMedia} of {medias.length}
</p>
<div className="flex h-full w-screen flex-1 items-center justify-center">
<motion.div
key={currentMedia - 1}
className="relative flex h-3/6 w-2/12 items-center"
style={{
transform: 'translateX(-40%)',
}}
>
{currentMedia - 1 && (
<button onClick={setPrevImage} className="h-full w-full">
<CarouselMedia media={medias[currentMedia - 1]} />
</button>
)}
</motion.div>
<motion.div
key={currentMedia}
className="flex w-8/12 flex-col items-center space-y-3"
variants={variants}
animate={'show'}
initial="hide"
>
<CarouselMedia media={medias[currentMedia]} isCurrentMedia />
</motion.div>
<motion.div
className="relative flex h-3/6 w-2/12 items-center"
key={currentMedia + 1}
variants={variants}
animate={'show'}
initial="hide"
style={{
transform: 'translateX(40%)',
}}
>
{currentMedia + 1 && (
<button
onClick={setNextImage}
className="h-full"
style={{
position: 'absolute',
top: 0,
right: '60%',
}}
>
<CarouselMedia media={medias[currentMedia + 1]} />
</button>
)}
</motion.div>
</div>
</div>
);
};

export default Carousel;
36 changes: 33 additions & 3 deletions client/src/containers/map/markers/story-markers/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useMemo } from 'react';
'use client';

import { useMemo, useState } from 'react';

import { useParams } from 'next/navigation';

Expand All @@ -9,6 +11,8 @@ import { stepAtom } from '@/store/stories';
import { useGetStoriesId } from '@/types/generated/story';

import StoryMarkerMedia from './marker';
// import Carousel from './carousel';
// import { Dialog, DialogContent } from '@/components/ui/dialog';

type StoryMarker = {
id: number;
Expand All @@ -28,18 +32,44 @@ const StoryMarkers = () => {
const { data: storyData } = useGetStoriesId(+id, {
populate: 'deep',
});
// const [currentMedia, setCurrentMedia] = useState<number>();

const markers: StoryMarker[] = useMemo(() => {
return (
storyData?.data?.attributes?.steps?.data?.[step]?.attributes?.layout[0].map?.markers || []
);
}, [step, storyData?.data?.attributes?.steps?.data]);

// const medias = useMemo(() => {
// return markers?.map((marker) => ({
// id: marker?.id,
// url: marker?.media?.url,
// mime: marker?.media?.mime,
// type: marker?.media?.mime?.includes('video') ? 'video' : 'image',
// }));
// }, [markers]);

// const handleClickMarker = (markerIndex: number) => {
// setCurrentMedia(markerIndex);
// };

return (
<>
{markers?.map((marker) => (
<StoryMarkerMedia key={marker.id} marker={marker} />
{markers?.map((marker, index) => (
<StoryMarkerMedia
key={marker.id}
marker={marker}
// onClick={() => handleClickMarker(index)}
/>
))}
{/* <Dialog
onOpenChange={() => setCurrentMedia(undefined)}
open={typeof currentMedia === 'number'}
>
<DialogContent className="bg-transparent">
<Carousel medias={medias} currentMedia={currentMedia} setCurrentMedia={setCurrentMedia} />
</DialogContent>
</Dialog> */}
</>
);
};
Expand Down
2 changes: 1 addition & 1 deletion client/src/containers/map/markers/story-markers/media.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const StoryMarker = ({ media, name, isFullScreen, onClickExpand }: StoryMarkerMe
height="100%"
src={mediaSrc}
ref={videoRef}
muted
muted={!isFullScreen}
loop
controls={isFullScreen}
autoPlay={isFullScreen}
Expand Down

0 comments on commit 6614108

Please sign in to comment.