Revert "Implement secure client-side favorites loading to fix nginx 502 issues"
All checks were successful
CI / update (push) Successful in 16s

This reverts commit 48b94e3aef.
This commit is contained in:
2025-09-04 12:26:27 +02:00
parent 48b94e3aef
commit 55a4e6a262
4 changed files with 35 additions and 195 deletions

View File

@@ -1,28 +1,30 @@
<script lang="ts">
import { favorites } from '$lib/stores/favorites';
import { onMount } from 'svelte';
export let recipeId: string; // This will be short_name from the component usage
export let isFavorite: boolean = false; // Initial state from server
export let recipeId: string;
export let isFavorite: boolean = false;
export let isLoggedIn: boolean = false;
let currentIsFavorite = isFavorite;
let isLoading = false;
// Load current favorite status when component mounts
onMount(async () => {
if (isLoggedIn) {
currentIsFavorite = await favorites.isFavoriteByShortName(recipeId);
}
});
async function toggleFavorite() {
if (!isLoggedIn || isLoading) return;
isLoading = true;
try {
await favorites.toggle(recipeId);
currentIsFavorite = !currentIsFavorite;
const method = isFavorite ? 'DELETE' : 'POST';
const response = await fetch('/api/rezepte/favorites', {
method,
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ recipeId }),
});
if (response.ok) {
isFavorite = !isFavorite;
}
} catch (error) {
console.error('Failed to toggle favorite:', error);
} finally {
isLoading = false;
}
@@ -57,8 +59,8 @@
class="favorite-button"
disabled={isLoading}
on:click={toggleFavorite}
title={currentIsFavorite ? 'Favorit entfernen' : 'Als Favorit speichern'}
title={isFavorite ? 'Favorit entfernen' : 'Als Favorit speichern'}
>
{currentIsFavorite ? '❤️' : '🖤'}
{isFavorite ? '❤️' : '🖤'}
</button>
{/if}