-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from hackerspace-ntnu/storage-shopping-cart
Add storage shopping cart, loan form and various improvements
- Loading branch information
Showing
55 changed files
with
1,866 additions
and
313 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
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
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...cale]/(default)/news/(header)/loading.tsx → ...locale]/(default)/news/(main)/loading.tsx
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
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,87 @@ | ||
import { CategorySelector } from '@/components/composites/CategorySelector'; | ||
import { SearchBar } from '@/components/composites/SearchBar'; | ||
import { SortSelector } from '@/components/composites/SortSelector'; | ||
import { SelectorsSkeleton } from '@/components/storage/SelectorsSkeleton'; | ||
import { ShoppingCartLink } from '@/components/storage/ShoppingCartLink'; | ||
import { useTranslations } from 'next-intl'; | ||
import { unstable_setRequestLocale } from 'next-intl/server'; | ||
import { Suspense } from 'react'; | ||
|
||
type StorageLayoutProps = { | ||
children: React.ReactNode; | ||
params: { locale: string }; | ||
}; | ||
|
||
export default function StorageLayout({ | ||
children, | ||
params: { locale }, | ||
}: StorageLayoutProps) { | ||
unstable_setRequestLocale(locale); | ||
const t = useTranslations('storage'); | ||
const tUi = useTranslations('ui'); | ||
|
||
// This does not make much sense with a backend, most likely the categories in the backend will have a name in both languages and an ID | ||
const categories = [ | ||
{ | ||
label: t('combobox.cables'), | ||
value: t('searchParams.cables'), | ||
}, | ||
{ | ||
label: t('combobox.sensors'), | ||
value: t('searchParams.sensors'), | ||
}, | ||
{ | ||
label: t('combobox.peripherals'), | ||
value: t('searchParams.peripherals'), | ||
}, | ||
{ | ||
label: t('combobox.miniPC'), | ||
value: t('searchParams.miniPC'), | ||
}, | ||
]; | ||
|
||
const filters = [ | ||
{ name: t('select.popularity'), urlName: t('searchParams.popularity') }, | ||
{ name: t('select.sortDescending'), urlName: t('searchParams.descending') }, | ||
{ name: t('select.sortAscending'), urlName: t('searchParams.ascending') }, | ||
{ name: t('select.name'), urlName: t('searchParams.name') }, | ||
]; | ||
|
||
return ( | ||
<> | ||
<div className='relative'> | ||
<h1 className='my-4 text-center'>{t('title')}</h1> | ||
<ShoppingCartLink | ||
t={{ viewShoppingCart: t('tooltips.viewShoppingCart') }} | ||
/> | ||
</div> | ||
<div className='my-4 flex flex-col justify-center gap-2 lg:flex-row'> | ||
<SearchBar | ||
className='lg:max-w-2xl' | ||
placeholder={t('searchPlaceholder')} | ||
/> | ||
<Suspense fallback={<SelectorsSkeleton />}> | ||
<SortSelector | ||
filters={filters} | ||
t={{ | ||
ariaLabel: t('select.ariaLabel'), | ||
sort: tUi('sort'), | ||
defaultValue: t('select.popularity'), | ||
defaultSorting: t('searchParams.popularity'), | ||
}} | ||
/> | ||
<CategorySelector | ||
categories={categories} | ||
t={{ | ||
category: tUi('category'), | ||
sort: tUi('sort'), | ||
defaultDescription: t('combobox.defaultDescription'), | ||
defaultPlaceholder: t('combobox.defaultPlaceholder'), | ||
}} | ||
/> | ||
</Suspense> | ||
</div> | ||
{children} | ||
</> | ||
); | ||
} |
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,16 @@ | ||
import { PaginationCarouselSkeleton } from '@/components/composites/PaginationCarouselSkeleton'; | ||
import { ItemCardSkeleton } from '@/components/storage/ItemCardSkeleton'; | ||
import { useId } from 'react'; | ||
|
||
export default function StorageSkeleton() { | ||
return ( | ||
<> | ||
<div className='grid grid-cols-1 gap-3 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4'> | ||
{Array.from({ length: 8 }).map(() => ( | ||
<ItemCardSkeleton key={useId()} /> | ||
))} | ||
</div> | ||
<PaginationCarouselSkeleton className='my-6' /> | ||
</> | ||
); | ||
} |
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,54 @@ | ||
import { items } from '@/mock-data/items'; | ||
import { useTranslations } from 'next-intl'; | ||
import { getTranslations, unstable_setRequestLocale } from 'next-intl/server'; | ||
import { createSearchParamsCache, parseAsInteger } from 'nuqs/server'; | ||
|
||
import { PaginationCarousel } from '@/components/composites/PaginationCarousel'; | ||
import { ItemCard } from '@/components/storage/ItemCard'; | ||
|
||
export async function generateMetadata({ | ||
params: { locale }, | ||
}: { | ||
params: { locale: string }; | ||
}) { | ||
const t = await getTranslations({ locale, namespace: 'layout' }); | ||
|
||
return { | ||
title: t('storage'), | ||
}; | ||
} | ||
|
||
export default function StoragePage({ | ||
params: { locale }, | ||
searchParams, | ||
}: { | ||
params: { locale: string }; | ||
searchParams: Record<string, string | string[] | undefined>; | ||
}) { | ||
unstable_setRequestLocale(locale); | ||
const t = useTranslations('ui'); | ||
|
||
const itemsPerPage = 12; | ||
|
||
const searchParamsCache = createSearchParamsCache({ | ||
[t('page')]: parseAsInteger.withDefault(1), | ||
}); | ||
|
||
const { [t('page')]: page = 1 } = searchParamsCache.parse(searchParams); | ||
|
||
return ( | ||
<> | ||
<div className='grid grid-cols-1 xs:grid-cols-2 gap-3 md:grid-cols-3 lg:grid-cols-4'> | ||
{items | ||
.slice((page - 1) * itemsPerPage, page * itemsPerPage) | ||
.map((item) => ( | ||
<ItemCard key={item.id} item={item} /> | ||
))} | ||
</div> | ||
<PaginationCarousel | ||
className='my-6' | ||
totalPages={Math.ceil(items.length / itemsPerPage)} | ||
/> | ||
</> | ||
); | ||
} |
Oops, something went wrong.