diff --git a/src/app/components/SpreadSheet.vue b/src/app/components/SpreadSheet.vue index 8dd7c24..c9a5c1e 100644 --- a/src/app/components/SpreadSheet.vue +++ b/src/app/components/SpreadSheet.vue @@ -1,8 +1,8 @@ - - + + These metadata fields will be added to your crate, click 'Confirm' to continue - No metadata could be added, please check your spreadsheet + No metadata could be added, please check your + spreadsheet diff --git a/src/app/views/CrateoView.vue b/src/app/views/CrateoView.vue index b449802..0147c92 100644 --- a/src/app/views/CrateoView.vue +++ b/src/app/views/CrateoView.vue @@ -25,7 +25,7 @@ const navigate = handleRoute((entityId, propertyId) => { //const $router = useRouter(); const emit = defineEmits(['load:spreadsheet']); -const defaultProfile = undefined; +const defaultProfile = 0; const data = shallowReactive({ /** @type {?FileSystemDirectoryHandle} */ @@ -335,7 +335,18 @@ function ready(roc, refresh) { const conformsToCrate = roc.rootDataset['conformsTo'] || []; const profileIndex = data.profiles.findIndex(p => conformsToCrate.some(ct => (p?.conformsToUri || []).includes(ct['@id']))); - data.selectedProfile = profileIndex >= 0 ? profileIndex : 0; + console.log('Profile Index:', profileIndex); // Accessing profileIndex here + + if (profileIndex.value >= 0) { + const selectedProfile = profileOptions.value[profileIndex.value]; + data.selectedProfile = selectedProfile?.value || profileOptions.value[0]?.value; + } else { + // If profileIndex is invalid, fallback only if no savedProfileValue is found + if (!savedProfileValue.value) { + data.selectedProfile = profileOptions.value[0]?.value; // Fallback to the first profile if no saved profile exists + } + } + data.loading = false; console.log('ready'); editor.crate = roc; @@ -343,6 +354,45 @@ function ready(roc, refresh) { } const activeNames = ref(['1']); + +import { onMounted, watch } from 'vue'; + +const savedProfileValue = ref(null); // reactive reference for the saved profile value +const profileIndex = ref(-1); // default value for profileIndex, set to -1 initially + +onMounted(() => { + // Retrieve the saved profile from localStorage + savedProfileValue.value = localStorage.getItem('selectedProfile'); + + // Use the computed profileOptions value to get the options + const options = profileOptions.value; + // Try to load the saved profile from localStorage if it exists + if (savedProfileValue.value) { + const savedProfile = options.find(option => option.value === savedProfileValue.value); + if (savedProfile) { + // If a valid saved profile is found, set it as the selected profile + data.selectedProfile = savedProfile.value; + } else { + // If the saved profile is no longer valid, fallback to profileIndex or default to 0 + data.selectedProfile = profileIndex.value >= 0 ? options[profileIndex.value]?.value : options[0]?.value; + } + } else { + // No saved profile found in localStorage, fallback to profileIndex or default to 0 + data.selectedProfile = profileIndex.value >= 0 ? options[profileIndex.value]?.value : options[0]?.value; + } + // If no profile has been selected and no valid profile is found, default to the first profile + if (!data.selectedProfile) { + data.selectedProfile = options[0]?.value; // Default to the first profile in options + } +}); + +// Watch for changes in selectedProfile and update localStorage +watch(() => data.selectedProfile, (newValue) => { + if (newValue) { + localStorage.setItem('selectedProfile', newValue); + } +}); +
These metadata fields will be added to your crate, click 'Confirm' to continue
No metadata could be added, please check your spreadsheet
No metadata could be added, please check your + spreadsheet