save functions updated
This commit is contained in:
@@ -102,12 +102,16 @@ const saveToCollection = async () => {
|
|||||||
saving.value = true
|
saving.value = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await $fetch(`${config.public.apiBase}api/recipe/save`, {
|
const response = await $fetch(`${config.public.apiBase}api/recipe/save`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
body: recipe.value
|
body: recipe.value
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (response && response.id) {
|
||||||
|
recipe.value.id = response.id
|
||||||
|
}
|
||||||
|
|
||||||
hasSaved.value = true
|
hasSaved.value = true
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Save failed:", error)
|
console.error("Save failed:", error)
|
||||||
|
|||||||
@@ -147,14 +147,6 @@ const saveToCollection = async () => {
|
|||||||
saving.value = false;
|
saving.value = false;
|
||||||
localStorage.setItem('pending_recipe', JSON.stringify(recipe.value))
|
localStorage.setItem('pending_recipe', JSON.stringify(recipe.value))
|
||||||
|
|
||||||
snackbar.value = {
|
|
||||||
show: true,
|
|
||||||
message: 'Please sign in to preserve this recipe in your archives.',
|
|
||||||
color: '#efe5e3',
|
|
||||||
icon: 'mdi-account-key',
|
|
||||||
iconColor: '#8c4a32',
|
|
||||||
textColor: '#5d4037'
|
|
||||||
};
|
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
router.push('/login')
|
router.push('/login')
|
||||||
@@ -163,45 +155,25 @@ const saveToCollection = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await $fetch(`${config.public.apiBase}api/recipe/save`, {
|
const response = await $fetch(`${config.public.apiBase}api/recipe/save`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
body: recipe.value
|
body: recipe.value
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (response && response.id) {
|
||||||
|
recipe.value.id = response.id
|
||||||
|
}
|
||||||
|
|
||||||
hasSaved.value = true;
|
hasSaved.value = true;
|
||||||
snackbar.value = {
|
|
||||||
show: true,
|
|
||||||
message: 'Recipe added to your collection.',
|
|
||||||
color: '#f4ede1',
|
|
||||||
icon: 'mdi-check-decagram',
|
|
||||||
iconColor: '#556b2f',
|
|
||||||
textColor: '#5d4037'
|
|
||||||
};
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Save failed:", error);
|
console.error("Save failed:", error);
|
||||||
snackbar.value = {
|
|
||||||
show: true,
|
|
||||||
message: 'Failure to save recipe.',
|
|
||||||
color: '#f8d7da',
|
|
||||||
icon: 'mdi-alert-rhombus',
|
|
||||||
iconColor: '#8c4a32',
|
|
||||||
textColor: '#5d4037'
|
|
||||||
};
|
|
||||||
} finally {
|
} finally {
|
||||||
saving.value = false;
|
saving.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const snackbar = ref({
|
|
||||||
show: false,
|
|
||||||
message: '',
|
|
||||||
color: '#f4ede1',
|
|
||||||
icon: 'mdi-check-decagram',
|
|
||||||
iconColor: '#556b2f',
|
|
||||||
textColor: '#5d4037'
|
|
||||||
})
|
|
||||||
|
|
||||||
const clearAll = () => {
|
const clearAll = () => {
|
||||||
files.value = null
|
files.value = null
|
||||||
recipe.value = null
|
recipe.value = null
|
||||||
|
|||||||
Reference in New Issue
Block a user