Skip to content

Commit

Permalink
chore(frontend): simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
Smrtnyk committed Dec 27, 2024
1 parent 9968d68 commit 731f589
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import { computed, ref } from "vue";
import { useI18n } from "vue-i18n";
import DrinkCardBuilderAddDragElementsDropdown from "src/components/admin/drink-cards/DrinkCardBuilderAddDragElementsDropdown.vue";
import { matchesProperty } from "es-toolkit/compat";
interface Props {
elements: DrinkCardElement[];
Expand Down Expand Up @@ -72,9 +73,7 @@ function emitUpdatedElements(): void {
function updateSectionItems(sectionId: string, items: DrinkCardItem[]): void {
const elements = [...draggableElements.value];
const rootSection = elements.filter(isSection).find(function ({ id }) {
return id === sectionId;
});
const rootSection = elements.filter(isSection).find(matchesProperty("id", sectionId));
if (rootSection) {
rootSection.items = items;
}
Expand Down
21 changes: 7 additions & 14 deletions packages/frontend/src/composables/useFloorEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import type { ShallowRef } from "vue";
import type { FloorDoc } from "@firetable/types";
import { FloorEditor, FloorElementTypes, extractAllTablesLabels } from "@firetable/floor-creator";
import { onBeforeUnmount, ref, shallowRef, nextTick } from "vue";
import { showErrorMessage } from "src/helpers/ui-helpers";
import { debounce } from "quasar";
import { AppLogger } from "src/logger/FTLogger.js";
import { isNumber, toNumber, isNaN } from "es-toolkit/compat";
import { toNumber, isNaN, toInteger } from "es-toolkit/compat";
import { negate } from "es-toolkit";

export const TABLE_EL_TO_ADD = [FloorElementTypes.RECT_TABLE, FloorElementTypes.ROUND_TABLE];
Expand All @@ -25,19 +24,13 @@ export function useFloorEditor(containerRef: ShallowRef<HTMLElement | null>) {
selectedElement.value = undefined;
}

function getNextTableLabel(): string {
if (!floorInstance.value) {
showErrorMessage("Floor instance is not defined");
return "";
}
let label: number;
const labels = extractAllTablesLabels(floorInstance.value);
function getNextTableLabel(floorEditor: FloorEditor): string {
let label = 0;
const labels = extractAllTablesLabels(floorEditor);
const numericLabels = labels.map(toNumber).filter(negate(isNaN));
if (numericLabels.length === 0) {
label = 0;
} else {
if (numericLabels.length > 0) {
const maxLabel = Math.max(...numericLabels);
label = isNumber(maxLabel) ? maxLabel : 0;
label = toInteger(maxLabel);
}
label += 1;
return String(label);
Expand All @@ -55,7 +48,7 @@ export function useFloorEditor(containerRef: ShallowRef<HTMLElement | null>) {
}

if (TABLE_EL_TO_ADD.includes(item)) {
const label = getNextTableLabel();
const label = getNextTableLabel(floorEditor);
floorEditor.addElement({ x, y, tag: item, label });
return;
}
Expand Down
4 changes: 1 addition & 3 deletions packages/frontend/src/stores/guests-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ export const useGuestsStore = defineStore("guests", function () {
}

hashedContactsToFetch = hashedContacts.filter(function (hashedContact) {
return !foundGuests.some(function (guest) {
return guest.hashedContact === hashedContact;
});
return !foundGuests.some(matchesProperty("hashedContact", hashedContact));
});
}

Expand Down

0 comments on commit 731f589

Please sign in to comment.