2023-04-09 15:57:25 +02:00
|
|
|
// Dependencies
|
|
|
|
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
|
2023-06-21 15:27:19 -05:00
|
|
|
import { sanityImage } from 'site/components/sanity/utils.mjs'
|
|
|
|
// Hooks
|
2023-06-19 16:27:13 -05:00
|
|
|
import { useTranslation } from 'next-i18next'
|
2023-06-21 15:27:19 -05:00
|
|
|
import { useSanityPagination } from 'site/hooks/use-sanity-pagination.mjs'
|
2023-04-09 15:57:25 +02:00
|
|
|
// Components
|
|
|
|
import { PageWrapper, ns as pageNs } from 'shared/components/wrappers/page.mjs'
|
2023-06-19 16:27:13 -05:00
|
|
|
import Link from 'next/link'
|
2023-06-21 15:27:19 -05:00
|
|
|
import { Pagination } from 'shared/components/navigation/pagination.mjs'
|
2023-04-09 15:57:25 +02:00
|
|
|
|
|
|
|
// Translation namespaces used on this page
|
2023-06-19 16:27:13 -05:00
|
|
|
const namespaces = [...new Set(['common', 'designs', ...pageNs])]
|
|
|
|
|
|
|
|
export const PreviewTile = ({ img, slug, title }) => (
|
|
|
|
<Link href={`/showcase/${slug}`} className="text-center">
|
|
|
|
<span
|
|
|
|
style={{ backgroundImage: `url(${img})`, backgroundSize: 'cover' }}
|
|
|
|
className={`
|
|
|
|
rounded-full inline-block border-base-100
|
|
|
|
w-40 h-40
|
|
|
|
md:w-56 md:h-56
|
|
|
|
`}
|
|
|
|
></span>
|
|
|
|
<p>{title}</p>
|
|
|
|
</Link>
|
|
|
|
)
|
|
|
|
|
|
|
|
// const DesignPosts = ({ design, posts }) => {
|
|
|
|
// const { t } = useTranslation(['patterns'])
|
|
|
|
// return (
|
|
|
|
// <div className='py-2'>
|
|
|
|
// <h2>
|
|
|
|
// <Link href={`/showcase/designs/${design}`}>
|
|
|
|
// <a className="hover:text-secondary-focus hover:underline">{t(`${design}.t`)}</a>
|
|
|
|
// </Link>
|
|
|
|
// </h2>
|
|
|
|
|
|
|
|
// </div>
|
|
|
|
// )
|
|
|
|
// }
|
|
|
|
|
2023-06-21 15:27:19 -05:00
|
|
|
const Posts = ({ posts, locale }) => {
|
|
|
|
posts.forEach((post) => {
|
|
|
|
// for (const design of post.designs) {
|
|
|
|
// if (typeof designs[design] === 'undefined') designs[design] = []
|
|
|
|
// designs[design].push(post)
|
|
|
|
// }
|
|
|
|
|
|
|
|
previews.push(
|
|
|
|
<PreviewTile
|
|
|
|
img={sanityImage(post.image[0]) + '?fit=clip&w=400'}
|
|
|
|
slug={post.slug.current}
|
|
|
|
title={post.title}
|
|
|
|
key={post.slug.current}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="grid grid-cols-1 gap-4 xl:gap-8 lg:grid-cols-2 xl:grid-cols-3 lg:pr-4 xl:pr-8">
|
|
|
|
{previews}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2023-04-09 15:57:25 +02:00
|
|
|
|
2023-06-19 16:27:13 -05:00
|
|
|
const ShowcaseIndexPage = (props) => {
|
|
|
|
const { t } = useTranslation()
|
2023-06-21 15:27:19 -05:00
|
|
|
const { posts, page, totalPages, setPage } = useSanityPagination('showcase', props.page.locale)
|
|
|
|
|
2023-06-19 16:27:13 -05:00
|
|
|
// const designKeys = useMemo(() => Object.keys(designs).sort(), [designs])
|
|
|
|
return (
|
|
|
|
<PageWrapper title={t('showcase')} {...props.page}>
|
2023-06-21 15:27:19 -05:00
|
|
|
<div className="text-center">
|
|
|
|
<Posts locale={props.page.locale} posts={posts} />
|
|
|
|
<Pagination {...{ current: page, total: totalPages, hrefBuilder, setPage }} />
|
|
|
|
</div>
|
2023-06-19 16:27:13 -05:00
|
|
|
</PageWrapper>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ShowcaseIndexPage
|
2023-04-09 15:57:25 +02:00
|
|
|
|
|
|
|
export async function getStaticProps({ locale }) {
|
|
|
|
return {
|
|
|
|
props: {
|
2023-06-21 15:27:19 -05:00
|
|
|
// posts: propPosts,
|
|
|
|
// designs,
|
2023-04-09 15:57:25 +02:00
|
|
|
...(await serverSideTranslations(locale, namespaces)),
|
|
|
|
page: {
|
2023-04-28 21:23:06 +02:00
|
|
|
locale,
|
2023-06-19 16:27:13 -05:00
|
|
|
// title: 'Freesewing Blog',
|
2023-04-09 15:57:25 +02:00
|
|
|
path: ['showcase'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|