Skip to content

Commit

Permalink
fixed several typing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Ruf committed Jul 31, 2024
1 parent 74e69fd commit a180878
Show file tree
Hide file tree
Showing 47 changed files with 130 additions and 116 deletions.
2 changes: 1 addition & 1 deletion src/Resources/src/api/getTimeSlotData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export async function useTimeSlotData() {
loaded.value = true;
}

const timeslots = ref<TimeSlots>(convertResponseToTimeSlots(timeslotsResponse.value));
const timeslots = ref<TimeSlots>(convertResponseToTimeSlots(timeslotsResponse.value as ITimeSlotResponse[]));

return { timeslots, error };
}
4 changes: 2 additions & 2 deletions src/Resources/src/api/postCreateDish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export interface CreateDishDTO {
titleDe: string;
titleEn: string;
oneServingSize: boolean;
descriptionDe?: string;
descriptionEn?: string;
descriptionDe: string;
descriptionEn: string;
category?: number;
diet?: Diet;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/src/api/putSlotUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function useUpdateSlot() {
* @param slot The slot as it should look after updating
*/
async function updateTimeSlot(slot: TimeSlot) {
return putUpdateSlot(slot.slug, JSON.stringify({ title: slot.title, limit: slot.limit, order: slot.order }));
return putUpdateSlot(slot.slug ?? '', JSON.stringify({ title: slot.title, limit: slot.limit, order: slot.order }));
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class="focus-visible:ring-offset-orange-300 flex w-full items-center border-[#CAD6E1] bg-white px-4 py-2 text-left text-[14px] font-medium text-[#B4C1CE] focus:outline-none focus-visible:border-indigo-500 focus-visible:ring-2 focus-visible:ring-white/75 focus-visible:ring-offset-2"
>
<span class="w-full truncate text-[#9CA3AF]">
{{ locale === 'en' ? selectedCategory.titleEn : selectedCategory.titleDe }}
{{ locale === 'en' ? selectedCategory?.titleEn : selectedCategory?.titleDe }}
</span>
<ChevronDownIcon
class="h-full w-5 justify-self-end text-[#9CA3AF]"
Expand Down Expand Up @@ -62,14 +62,14 @@ const props = withDefaults(
categoryId?: number;
}>(),
{
categoryId: null
categoryId: undefined
}
);
const initialCategory = computed(() =>
props.categoryId ? getCategoryById(props.categoryId) : CategoriesState.categories[0]
);
const selectedCategory: Ref<Category> = ref(initialCategory.value);
const selectedCategory: Ref<Category | undefined> = ref(initialCategory.value);
defineExpose({ selectedCategory });
</script>
4 changes: 2 additions & 2 deletions src/Resources/src/components/dishes/DishActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
:edit="true"
:title-de="dish.titleDe"
:title-en="dish.titleEn"
:description-de="dish.descriptionDe"
:description-en="dish.descriptionEn"
:description-de="dish.descriptionDe ?? ''"
:description-en="dish.descriptionEn ?? ''"
:dish-id="dish.id"
:category-id="dish.categoryId"
:one-size-serving="dish.oneServingSize"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const props = withDefaults(
{
titleDe: '',
titleEn: '',
slug: null,
slug: undefined,
edit: false,
diet: Diet.MEAT
}
Expand Down
22 changes: 12 additions & 10 deletions src/Resources/src/components/dishes/DishesCreationPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ const props = withDefaults(
defineProps<{
titleDe?: string;
titleEn?: string;
descriptionDe?: string | null;
descriptionEn?: string | null;
categoryId?: number | null;
descriptionDe?: string;
descriptionEn?: string;
categoryId?: number;
oneSizeServing?: boolean;
diet?: Diet;
dishId?: number | null;
Expand All @@ -93,9 +93,9 @@ const props = withDefaults(
{
titleDe: '',
titleEn: '',
descriptionDe: null,
descriptionEn: null,
categoryId: null,
descriptionDe: '',
descriptionEn: '',
categoryId: undefined,
oneSizeServing: false,
diet: Diet.MEAT,
dishId: null,
Expand Down Expand Up @@ -133,13 +133,15 @@ const dishInput = reactive<CreateDishDTO>({
descriptionEn: props.descriptionEn,
oneServingSize: props.oneSizeServing,
diet: props.diet,
category: null
category: undefined
});
watch(
() => categoryDropDown.value?.selectedCategory.id,
() => categoryDropDown.value?.selectedCategory?.id,
() => {
dishInput.category = categoryDropDown.value?.selectedCategory.id;
if (categoryDropDown.value?.selectedCategory?.id !== undefined) {
dishInput.category = categoryDropDown.value.selectedCategory.id;
}
}
);
Expand All @@ -155,7 +157,7 @@ async function onSubmit() {
if (dishInput.titleDe === '' || dishInput.titleEn === '') {
return;
}
if (props.edit === true) {
if (props.edit === true && props.dishId !== null) {
await updateDish(props.dishId, dishInput);
} else {
await createDish(dishInput);
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/src/components/guest/GuestMeal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const mealCSS = computed(() => {
});
const participationDisplayString = computed(() => {
const fixedCount = Math.ceil(parseFloat(meal.value.participations.toFixed(1)));
return meal.value.limit > 0 ? `${fixedCount}/${meal.value.limit}` : fixedCount;
const fixedCount = Math.ceil(parseFloat((meal.value.participations ?? 0).toFixed(1)));
return (meal.value.limit ?? 0) > 0 ? `${fixedCount}/${meal.value.limit}` : fixedCount;
});
</script>
8 changes: 4 additions & 4 deletions src/Resources/src/components/guest/GuestVariation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
class="text-align-last flex flex-auto basis-1/12 flex-row justify-end gap-1 min-[380px]:flex-row min-[380px]:items-center"
>
<ParticipationCounter
:limit="variation.limit"
:mealCSS="mealCSS.get(String(variationID))"
:limit="variation.limit ?? 0"
:mealCSS="mealCSS.get(String(variationID)) ?? ''"
>
{{ getParticipationDisplayString(variation) }}
</ParticipationCounter>
Expand Down Expand Up @@ -69,7 +69,7 @@ const parentTitle = computed(() => (locale.value.substring(0, 2) === 'en' ? prop
const mealCSS = computed(() => {
const css: Map<string, string> = new Map();
for (const [variationId, variation] of Object.entries(props.meal.variations)) {
for (const [variationId, variation] of Object.entries(props.meal.variations ?? {})) {
let cssStr = 'grid grid-cols-2 content-center rounded-md h-[30px] xl:h-[20px] mr-[15px] ';
switch (generateMealState(variation as Meal)) {
case (MealState.OFFERABLE, MealState.DISABLED):
Expand All @@ -88,6 +88,6 @@ const mealCSS = computed(() => {
const getParticipationDisplayString = (variation: Meal) => {
const fixedCount = Math.ceil(parseFloat((variation.participations ?? 0).toFixed(1)));
return variation.limit > 0 ? `${fixedCount}/${variation.limit}` : fixedCount;
return (variation.limit ?? 0) > 0 ? `${fixedCount}/${variation.limit}` : fixedCount;
};
</script>
4 changes: 2 additions & 2 deletions src/Resources/src/components/menu/MealParticipationInput.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<label class="flex flex-row">
<span class="w-[70%] self-center truncate text-left text-xs font-medium text-[#173D7A]">
{{ locale === 'en' ? getDishBySlug(meal.dishSlug)?.titleEn : getDishBySlug(meal.dishSlug)?.titleDe }}
{{ locale === 'en' ? getDishBySlug(meal.dishSlug ?? '')?.titleEn : getDishBySlug(meal.dishSlug ?? '')?.titleDe }}
</span>
<input
v-model.number="meal.participationLimit"
Expand All @@ -14,7 +14,7 @@
</template>

<script setup lang="ts">
import { MealDTO } from '@/interfaces/DayDTO';
import { type MealDTO } from '@/interfaces/DayDTO';
import { useDishes } from '@/stores/dishesStore';
import { useI18n } from 'vue-i18n';
Expand Down
24 changes: 12 additions & 12 deletions src/Resources/src/components/menu/MenuDay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@

<script setup lang="ts">
import MenuInput from '@/components/menu/MenuInput.vue';
import { Ref, computed, onMounted, ref, watch } from 'vue';
import { Dish } from '@/stores/dishesStore';
import { MealDTO, DayDTO } from '@/interfaces/DayDTO';
import { type Ref, computed, onMounted, ref, watch } from 'vue';
import { type Dish } from '@/stores/dishesStore';
import type { MealDTO, DayDTO } from '@/interfaces/DayDTO';
import { useDishes } from '@/stores/dishesStore';
import { translateWeekdayWithoutRef } from '@/tools/localeHelper';
import { useI18n } from 'vue-i18n';
Expand All @@ -72,9 +72,9 @@ import Popover from '../misc/Popover.vue';
import MenuParticipationPanel from './MenuParticipationPanel.vue';
import MenuLockDatePicker from './MenuLockDatePicker.vue';
import EventInput from './EventInput.vue';
import { Event, useEvents } from '@/stores/eventsStore';
import { DateTime } from '@/api/getDashboardData';
import { Dictionary } from '@/types/types';
import { type Event, useEvents } from '@/stores/eventsStore';
import { type DateTime } from '@/api/getDashboardData';
import { type Dictionary } from '@/types/types';
const { getDishArrayBySlugs, getDishBySlug } = useDishes();
const { locale, t } = useI18n();
Expand Down Expand Up @@ -121,7 +121,7 @@ const selectedDishes = computed({
const isStandardLockDate = computed(() => {
const dayIds = props.lockDates !== null && props.lockDates !== undefined ? Object.keys(props.lockDates) : [];
if (dayIds.length > 0 && dayIds.map((id) => String(id)).includes(String(props.modelValue.id))) {
if (props.lockDates !== null && dayIds.length > 0 && dayIds.map((id) => String(id)).includes(String(props.modelValue.id))) {
return props.lockDates[props.modelValue.id].date === props.modelValue.lockDate.date;
}
return true;
Expand All @@ -138,7 +138,7 @@ watch(selectedDishOne, () => {
dishSlug: dishSlug,
mealId: mealIds.length > 0 ? mealIds.shift() : null,
participationLimit: getParticipationLimitFromModel(dishSlug, mealKeys.value[0])
};
} as MealDTO;
});
});
Expand All @@ -153,7 +153,7 @@ watch(selectedDishTwo, () => {
dishSlug: dishSlug,
mealId: mealIds.length > 0 ? mealIds.shift() : null,
participationLimit: getParticipationLimitFromModel(dishSlug, mealKeys.value[1])
};
} as MealDTO;
});
});
Expand All @@ -168,14 +168,14 @@ watch(selectedEvent, () => {
onMounted(() => {
// get mealKeys
selectedDishOne.value = getDishArrayBySlugs(
props.modelValue.meals[mealKeys.value[0]].map((meal: MealDTO) => meal.dishSlug)
props.modelValue.meals[mealKeys.value[0]].map((meal: MealDTO) => meal.dishSlug).filter(slug => slug !== null) as string[]
);
selectedDishTwo.value = getDishArrayBySlugs(
props.modelValue.meals[mealKeys.value[1]].map((meal: MealDTO) => meal.dishSlug)
props.modelValue.meals[mealKeys.value[1]].map((meal: MealDTO) => meal.dishSlug).filter(slug => slug !== null) as string[]
);
// set Event from modelValue to be the initial value of the selectedEvent
selectedEvent.value = getEventById(props.modelValue.event);
selectedEvent.value = getEventById(props.modelValue.event ?? -1) ?? null;
});
/**
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/src/components/menu/MenuHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</template>

<script setup lang="ts">
import { WeekDTO } from '@/interfaces/DayDTO';
import { type WeekDTO } from '@/interfaces/DayDTO';
import NotifyButton from '@/components/menu/NotifyButton.vue';
import EnableWeek from '@/components/menu/EnableWeek.vue';
import { useI18n } from 'vue-i18n';
Expand Down
23 changes: 10 additions & 13 deletions src/Resources/src/components/menu/MenuInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
:fill-colour="'fill-[#9CA3AF]'"
/>
<ComboboxInput
:displayValue="
// @ts-ignore
(dish) => titleStringRepr
"
:displayValue="(dish) => titleStringRepr"
class="w-full truncate border-none px-4 py-2 text-[#9CA3AF] focus:outline-none"
@change="setFilter($event.target.value)"
/>
Expand Down Expand Up @@ -102,10 +99,10 @@

<script setup lang="ts">
import { Combobox, ComboboxInput, ComboboxOptions, ComboboxOption } from '@headlessui/vue';
import { Dish, useDishes } from '@/stores/dishesStore';
import { type Dish, useDishes } from '@/stores/dishesStore';
import { useWeeks } from '@/stores/weeksStore';
import { useI18n } from 'vue-i18n';
import { WatchStopHandle, computed, onMounted, onUnmounted, ref, watch } from 'vue';
import { type WatchStopHandle, computed, onMounted, onUnmounted, ref, watch } from 'vue';
import { XIcon } from '@heroicons/vue/solid';
import useDetectClickOutside from '@/services/useDetectClickOutside';
import MenuDishVariationsCombobox from './MenuDishVariationsCombobox.vue';
Expand All @@ -131,18 +128,18 @@ const openProp = ref(false);
const selectedVariations = ref<Dish[]>([]);
const selectedDish = ref<Dish | null>(null);
const loadingFinished = ref<boolean>(false);
let unwatch: WatchStopHandle = null;
let unwatch: WatchStopHandle;
onMounted(() => {
// set initial value for dish
if (props.modelValue?.length > 0) {
props.modelValue.forEach((dish) => {
if (props.modelValue?.length ?? 0 > 0) {
props.modelValue?.forEach((dish) => {
if (dish.parentId === null) {
selectedDish.value = dish;
}
});
// set initial value for variations (after dish is set, otherwise the watcher empties the array)
props.modelValue.forEach((dish) => {
props.modelValue?.forEach((dish) => {
if (dish.parentId !== null) {
selectedVariations.value.push(dish);
}
Expand Down Expand Up @@ -179,6 +176,7 @@ const value = computed({
watch(selectedVariations, (newSelctedVariations, oldSelectedVariations) => {
if (
selectedDish.value !== null &&
loadingFinished.value !== null &&
loadingFinished.value !== undefined &&
newSelctedVariations.length !== oldSelectedVariations.length
Expand All @@ -188,14 +186,13 @@ watch(selectedVariations, (newSelctedVariations, oldSelectedVariations) => {
});
const titleStringRepr = computed(() => {
return value.value
.map((dish) => {
return value.value?.map((dish) => {
if (dish !== null && dish !== undefined) {
return locale.value === 'en' ? dish.titleEn : dish.titleDe;
}
return '';
})
.join(', ');
.join(', ') ?? '';
});
function handleClick() {
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/src/components/menu/MenuLockDatePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import Popover from '../misc/Popover.vue';
import { CalendarIcon } from '@heroicons/vue/solid';
import { useI18n } from 'vue-i18n';
import { DateTime } from '@/api/getDashboardData';
import { type DateTime } from '@/api/getDashboardData';
import { XCircleIcon } from '@heroicons/vue/solid';
import VueDatePicker from '@vuepic/vue-datepicker';
import { computed } from 'vue';
Expand Down Expand Up @@ -74,6 +74,6 @@ function getLockDateAsStrRepr(date: Date) {
// output format: 2023-07-13 16:00:00.000000
function convertDateReprToLockDayFormat(date: string) {
return date.replaceAll(' ', 'T') + ':00.000000';
return date.replace(' ', 'T') + ':00.000000';
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</div>
<MealParticipationInput
v-for="meal in mealList"
:key="meal.dishSlug"
:key="meal.dishSlug ?? ''"
:meal="meal"
class="max-w-[300px] px-2"
/>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/src/components/menu/NotifyButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</template>

<script setup lang="ts">
import { WeekDTO } from '@/interfaces/DayDTO';
import { type WeekDTO } from '@/interfaces/DayDTO';
import Switch from '../misc/Switch.vue';
import { useI18n } from 'vue-i18n';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@

<script setup lang="ts">
import useDetectClickOutside from '@/services/useDetectClickOutside';
import { IProfile, useProfiles } from '@/stores/profilesStore';
import { type IProfile, useProfiles } from '@/stores/profilesStore';
import { Combobox, ComboboxInput, ComboboxOptions, ComboboxOption, ComboboxLabel } from '@headlessui/vue';
import { computed, onMounted, ref, useSlots } from 'vue';
import { XIcon } from '@heroicons/vue/solid';
Expand Down
Loading

0 comments on commit a180878

Please sign in to comment.