diff --git a/messages/en.json b/messages/en.json
index 2cc988a..5eb56c5 100644
--- a/messages/en.json
+++ b/messages/en.json
@@ -9,7 +9,9 @@
"next": "Next",
"goToNextPage": "Go to next page",
"morePages": "More pages",
- "page": "page"
+ "page": "page",
+ "category": "category",
+ "sort": "sort"
},
"layout": {
"hackerspaceHome": "Hackerspace homepage",
diff --git a/messages/no.json b/messages/no.json
index 829331a..3c91dcd 100644
--- a/messages/no.json
+++ b/messages/no.json
@@ -9,7 +9,9 @@
"next": "Neste",
"goToNextPage": "Gå til neste side",
"morePages": "Flere sider",
- "page": "side"
+ "page": "side",
+ "category": "kategori",
+ "sort": "sortering"
},
"layout": {
"hackerspaceHome": "Hackerspace hjemmeside",
diff --git a/src/app/[locale]/(default)/storage/page.tsx b/src/app/[locale]/(default)/storage/page.tsx
index e4b7409..6fba8ca 100644
--- a/src/app/[locale]/(default)/storage/page.tsx
+++ b/src/app/[locale]/(default)/storage/page.tsx
@@ -24,6 +24,7 @@ import {
import { ShoppingCart } from 'lucide-react';
import { Link } from '@/lib/navigation';
+import { CategorySelector } from '@/components/storage/CategorySelector';
export async function generateMetadata({
params: { locale },
@@ -117,12 +118,14 @@ export default function StoragePage({
-
diff --git a/src/components/storage/CategorySelector.tsx b/src/components/storage/CategorySelector.tsx
new file mode 100644
index 0000000..05d8718
--- /dev/null
+++ b/src/components/storage/CategorySelector.tsx
@@ -0,0 +1,43 @@
+'use client';
+import { useTranslations } from 'next-intl';
+import { useQueryState } from 'nuqs';
+import { createSearchParamsCache, parseAsString } from 'nuqs/parsers';
+import { Combobox } from '../ui/Combobox';
+
+type CategorySelectorProps = {
+ categories: {
+ value: string;
+ label: string;
+ }[];
+ t: {
+ category: string;
+ sort: string;
+ defaultDescription: string;
+ defaultPlaceholder: string;
+ };
+};
+
+function CategorySelector({ categories, t }: CategorySelectorProps) {
+ const [category, setCategory] = useQueryState(
+ t.category,
+ parseAsString.withDefault(''),
+ );
+ const [sort, setSort] = useQueryState(t.sort, parseAsString.withDefault(''));
+
+ function valueCallback(category: string | null) {
+ setCategory(category);
+ }
+
+ return (
+
+ );
+}
+
+export { CategorySelector };
diff --git a/src/components/storage/ShoppingCartClearButton.tsx b/src/components/storage/ShoppingCartClearButton.tsx
index 7674993..0ad7aae 100644
--- a/src/components/storage/ShoppingCartClearButton.tsx
+++ b/src/components/storage/ShoppingCartClearButton.tsx
@@ -3,7 +3,7 @@ import { Button } from '@/components/ui/Button';
import { X } from 'lucide-react';
import { useLocalStorage } from 'usehooks-ts';
-function ShoppingCartClearButton({ caption }: { caption: string }) {
+async function ShoppingCartClearButton({ caption }: { caption: string }) {
const [cart, setCart] = useLocalStorage
('shopping-cart', []);
function clearCart() {
diff --git a/src/components/ui/Combobox.tsx b/src/components/ui/Combobox.tsx
index 9fe99fe..c0738d7 100644
--- a/src/components/ui/Combobox.tsx
+++ b/src/components/ui/Combobox.tsx
@@ -29,6 +29,7 @@ type ComboboxProps = {
defaultPlaceholder: string;
buttonClassName?: string;
contentClassName?: string;
+ valueCallback?: (value: string | null) => void;
};
function Combobox({
@@ -37,9 +38,10 @@ function Combobox({
defaultPlaceholder,
buttonClassName,
contentClassName,
+ valueCallback,
}: ComboboxProps) {
const [open, setOpen] = React.useState(false);
- const [value, setValue] = React.useState('');
+ const [value, setValue] = React.useState(null);
return (
@@ -67,8 +69,14 @@ function Combobox({
key={choice.value}
value={choice.value}
onSelect={(currentValue) => {
- setValue(currentValue === value ? '' : currentValue);
+ // Set newValue to null if user selects the same value twice
+ const newValue =
+ currentValue === value ? null : currentValue;
+ setValue(newValue);
setOpen(false);
+ if (valueCallback) {
+ valueCallback(newValue);
+ }
}}
>