From b6c839d99f9476aabdbd7f315bacfccb047fc3e8 Mon Sep 17 00:00:00 2001 From: ebby Date: Mon, 5 Oct 2026 15:45:38 +0200 Subject: [PATCH] fixed shit --- blog/src/islands/ToggleSubscription.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/blog/src/islands/ToggleSubscription.tsx b/blog/src/islands/ToggleSubscription.tsx index 1086d78..29a4bcf 100644 --- a/blog/src/islands/ToggleSubscription.tsx +++ b/blog/src/islands/ToggleSubscription.tsx @@ -1,7 +1,7 @@ import { useEffect, useState } from 'preact/hooks'; import { api, type User } from '../lib/api'; import React from 'preact/compat'; -import { getUser } from './Util'; +import { getUser, saveUser } from './Util'; export default function ToggleSubscription() { const [subscription, setSubscription] = React.useState(false); @@ -11,6 +11,7 @@ export default function ToggleSubscription() { useEffect(() => { user = getUser() if (!user) navigation.back() + else setSubscription(user.subscription) }, []); const handleSubscription = async () => { @@ -20,10 +21,16 @@ export default function ToggleSubscription() { try { api.toggleSubscription(subscription) } catch (err) { - setError(err instanceof Error ? err.message : 'Update'); + setError(err instanceof Error ? err.message : 'Update fehlgeschlagen'); hasError = true + console.log(hasError); } finally { - // if (!hasError) // TODO: snackbar + if (!hasError) { + if (user) { + user = {...user, subscription: false } + saveUser(user) + } + } } }; @@ -35,7 +42,7 @@ export default function ToggleSubscription() { return (