1
0
Fork 0
freesewing/sites/lab/page-templates/design-list.js

86 lines
3 KiB
JavaScript
Raw Normal View History

import Page from 'site/components/wrappers/page.js'
import useApp from 'site/hooks/useApp.js'
import Link from 'next/link'
2022-02-06 19:16:49 +01:00
import { useTranslation } from 'next-i18next'
2022-07-12 20:31:53 +02:00
import { formatVersionTitle } from 'site/components/version-picker.js'
import Layout from 'site/components/layouts/bare'
2022-07-15 16:30:40 -04:00
import { PageTitle } from 'shared/components/layouts/default'
import availableVersions from 'site/available-versions.json' assert { type: 'json' }
2022-06-22 13:54:53 +02:00
const DesignLinks = ({ list, prefix='', version=false }) => {
const { t } = useTranslation(['patterns'])
2022-06-22 13:54:53 +02:00
return (
<ul className="flex flex-col flex-wrap gap-2">
{list.map( d => (
<li key={d} className="p-2">
<Link href={`${prefix}/${d}`}>
<a className="capitalize text-xl p-4 font-bold text-secondary hover:text-secondary-focus hover:underline">
{t(`patterns:${d}.t`)}
<br />
<span className="text-lg font-normal p-4 text-base-content">{t(`patterns:${d}.d`)}</span>
</a>
</Link>
</li>
))}
</ul>
)
}
2022-06-22 13:54:53 +02:00
const PatternListPageTemplate = ({ section=false, version=false }) => {
const app = useApp()
const { t } = useTranslation(['app'])
const title = section
? app.navigation[section].__title
: t('designs')
2022-06-22 13:54:53 +02:00
const sectionDesigns = (section=false, version=false) => {
if (!section) {
const all = []
if (!version || version === 'next') {
for (const section in app.designs) all.push(...app.designs[section])
return all
}
else if (availableVersions[version]) return availableVersions[version]
} else {
if (!version || version === 'next') return app.designs[section]
else if (availableVersions[version]) return availableVersions[version]
}
return []
}
return (
<Page app={app} title={`FreeSewing Lab: ${formatVersionTitle(version)}`} layout={Layout}>
<div className="max-w-7xl m-auto py-20 md:py-36 min-h-screen">
<section className="px-8">
<PageTitle app={app} slug={section ? app.navigation[section].__slug : '/' } title={title} />
2022-06-22 13:54:53 +02:00
{version && version !== 'next'
? (
2022-06-22 13:54:53 +02:00
<ul className="flex flex-col flex-wrap gap-2">
{availableVersions[version].map( d => (
<li key={d} className="p-2">
<Link href={`/v/${version}/${d}`}>
<a className="capitalize text-xl p-4 font-bold text-secondary hover:text-secondary-focus hover:underline">
{t(`patterns:${d}.t`)}
<br />
<span className="text-lg font-normal p-4 text-base-content">{t(`patterns:${d}.d`)}</span>
</a>
</Link>
</li>
))}
</ul>
)
2022-06-22 13:54:53 +02:00
: <DesignLinks list={sectionDesigns(section)} />
}
</section>
</div>
</Page>
)
}
export default PatternListPageTemplate