Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factorise pizza count #161

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/views/AdminPizza/AdminPizza.vue
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,24 @@ const handleWheel = (event: WheelEvent) => {
const target = event.target as HTMLInputElement;
target.blur();
};

const factorise = (pizzas: number[]) => {
const counts: Record<number, number> = {};
pizzas.forEach((pizza) => {
if (counts[pizza] === undefined) {
counts[pizza] = 1;
} else {
counts[pizza] += 1;
}
});
return Object.keys(counts).map((pizza) => {
const pizzaId = parseInt(pizza, 10);
if (counts[pizzaId] > 1) {
return `${pizzaList.value[pizzaId].name} x${counts[pizzaId]}`;
}
return pizzaList.value[pizzaId].name;
}).join(', ');
};
</script>
<template>
<div v-if="timeslotList && Object.keys(timeslotList).length > 0" class="flex flex-1 flex-col">
Expand Down Expand Up @@ -461,7 +479,7 @@ const handleWheel = (event: WheelEvent) => {
{{ order.user }}
</div>
<div class="flex-1 text-left">
{{ order.pizza?.map((pizzaId: number) => pizzaList[pizzaId]?.name).join(', ') }}
{{ factorise(order.pizza) }}
</div>
<div class="flex flex-1 flex-col items-center">
<label for="isTakenCheckbox-{{ order.id }}" class="flex flex-1 flex-col justify-center">
Expand Down
Loading