Skip to content

Commit

Permalink
Fix license loading logic and improve reactivity
Browse files Browse the repository at this point in the history
Changes initial licensesLoading state to false
Uses watchImmediate for immediate reactivity on inputLicense
Ensures licenses are fetched only when not already loading
  • Loading branch information
itisAliRH committed Nov 17, 2024
1 parent 8bb73a3 commit 37b4fa4
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions client/src/components/License/LicenseSelector.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { watchImmediate } from "@vueuse/core";
import { BAlert } from "bootstrap-vue";
import { computed, ref, watch } from "vue";
import { computed, ref } from "vue";
import Multiselect from "vue-multiselect";
import { GalaxyApi } from "@/api";
Expand Down Expand Up @@ -31,7 +32,7 @@ const emit = defineEmits<{
(e: "onLicense", license: string | null): void;
}>();
const licensesLoading = ref(true);
const licensesLoading = ref(false);
const errorMessage = ref<string>("");
const currentLicense = ref<LicenseType>();
const licenses = ref<LicenseMetadataModel[] | undefined>([]);
Expand Down Expand Up @@ -70,7 +71,9 @@ async function fetchLicenses() {
}
async function setCurrentLicense() {
if (!licenses.value?.length) {
if (!licenses.value?.length && !licensesLoading.value) {
licensesLoading.value = true;
await fetchLicenses();
}
Expand All @@ -79,14 +82,12 @@ async function setCurrentLicense() {
currentLicense.value = (licenses.value || []).find((l) => l.licenseId == inputLicense) || defaultLicense;
}
watch(
watchImmediate(
() => props.inputLicense,
() => {
setCurrentLicense();
}
);
setCurrentLicense();
</script>

<template>
Expand Down

0 comments on commit 37b4fa4

Please sign in to comment.