Skip to content

Commit

Permalink
feat: multicategories views on preparation
Browse files Browse the repository at this point in the history
  • Loading branch information
tuturd committed Sep 11, 2024
1 parent ca8480b commit a9f0cbf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React from 'react';
import 'moment/locale/fr';
import moment from 'moment';
import { useDispatch, useSelector } from "react-redux";
import { useDispatch, useSelector } from 'react-redux';
import Navbar from '@/components/navbar';
import FontAwesome from 'react-fontawesome';
import { logout } from '@/reducers/login';
Expand Down Expand Up @@ -35,7 +35,7 @@ const App = () => {
<div onClick={() => router.push('/preparation?only=pizzas')}>
<FontAwesome name="pizza-slice" /> Pizzas
</div>
<div onClick={() => router.push('/preparation?only=crepes')}>
<div onClick={() => router.push('/preparation?only=crepes,galettes')}>
<FontAwesome name="stroopwafel" /> Crêpes
</div>
<div onClick={() => router.push('/preparation?only=croques')}>
Expand All @@ -52,7 +52,7 @@ const App = () => {
<div onClick={() => router.push('/preparation?only=pizzas&by=item')}>
<FontAwesome name="pizza-slice" /> Pizzas
</div>
<div onClick={() => router.push('/preparation?only=crepes&by=item')}>
<div onClick={() => router.push('/preparation?only=crepes,galettes&by=item')}>
<FontAwesome name="stroopwafel" /> Crêpes
</div>
<div onClick={() => router.push('/preparation?only=croques&by=item')}>
Expand Down
10 changes: 8 additions & 2 deletions src/app/preparation/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ const Page = () => {

// Renvoie les commandes contenant au moins un item dans la catégory du paramètre
if (searchParams.has("only")) {
const categoriesToDisplay = searchParams.get("only").split(",");
orders = orders.filter((order) =>
order.orderItems.some((orderItem) => orderItem.item.category.key == searchParams.get("only"))
order.orderItems.some((orderItem) => categoriesToDisplay.includes(orderItem.item.category.key))
);
if (searchParams.has("by") && searchParams.get("by") == "item") {
orders.forEach((order) => {
order.orderItems = order.orderItems.filter((orderItem) => categoriesToDisplay.includes(orderItem.item.category.key));
});
}
}

// used only to refresh the component every minute
Expand Down Expand Up @@ -65,7 +71,7 @@ const Page = () => {
}
};

const separate_by: string = searchParams.has('by') ? searchParams.get('by') : 'order';
const separate_by: string = searchParams.get('by') ?? 'order';

const displayOrders = (orders: Array<Order>) => {

Expand Down

0 comments on commit a9f0cbf

Please sign in to comment.