generated from taylorbryant/gatsby-starter-tailwind
-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: skeleton for gallery/topo page (#1128)
- Loading branch information
Showing
6 changed files
with
95 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
'use client' | ||
import { useState, Dispatch, SetStateAction } from 'react' | ||
import Image from 'next/image' | ||
import clx from 'classnames' | ||
import { AreaType, MediaWithTags } from '@/js/types' | ||
|
||
type GalleryThumbnailsProps = AreaType | ||
|
||
export const GalleryThumbnails: React.FC<GalleryThumbnailsProps> = ({ media }) => { | ||
const [currentPhoto, setCurrentPhoto] = useState<string | null>(media[0]?.id ?? null) | ||
const currentMedia = media.find(media => media.id === currentPhoto) | ||
return ( | ||
<div className='w-full'> | ||
<div className='flex flex-rows flex-wrap gap-4'> | ||
{media.map(media => | ||
<Thumbnail | ||
key={media.id} | ||
{...media} onClick={setCurrentPhoto} | ||
selected={currentPhoto === media.id} | ||
/>)} | ||
</div> | ||
<div className='mt-6'> | ||
{(currentMedia != null) && <ActivePhoto {...currentMedia} />} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
const IMAGE_MAX_WIDITH = 200 | ||
|
||
interface ThumbnailProps extends MediaWithTags { | ||
onClick: Dispatch<SetStateAction<string | null>> | ||
selected: boolean | ||
} | ||
|
||
const Thumbnail: React.FC<ThumbnailProps> = ({ id, mediaUrl, width, height, entityTags, onClick, selected }) => { | ||
const imageRatio = width / height | ||
return ( | ||
<div className={clx('relative block hover:cursor-pointer', selected && 'ring-2 ring-offset-1')} onClick={() => onClick(id)}> | ||
<Image | ||
src={mediaUrl} | ||
width={IMAGE_MAX_WIDITH} | ||
height={IMAGE_MAX_WIDITH / imageRatio} | ||
sizes='25vw' | ||
alt='' | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
const ActivePhoto: React.FC<MediaWithTags> = ({ mediaUrl, width, height, entityTags }) => { | ||
const imageRatio = width / height | ||
const WIDTH = 800 | ||
return ( | ||
<div className='relative block w-full'> | ||
<Image | ||
src={mediaUrl} | ||
width={WIDTH} | ||
height={WIDTH / imageRatio} | ||
sizes='25vw' | ||
alt='' | ||
/> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Loading (): JSX.Element { | ||
return <p>Loading...</p> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { notFound } from 'next/navigation' | ||
import { getArea } from '@/js/graphql/getArea' | ||
import { GalleryThumbnails } from './components/GalleryThumbnails' | ||
|
||
interface TopoPageParams { | ||
params: { id: string } | ||
} | ||
|
||
export default async function TopoPage ({ params: { id } }: TopoPageParams): Promise<JSX.Element> { | ||
const pageData = await getArea(id) | ||
if (pageData == null || pageData.area == null) { | ||
notFound() | ||
} | ||
const { area } = pageData | ||
return ( | ||
<article className='default-page-margins mt-6'> | ||
<h1 className='mt-4'>{area.areaName}</h1> | ||
<GalleryThumbnails {...area} /> | ||
</article> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Layout from '../../(default)/layout' | ||
|
||
export default Layout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters