diff --git a/src/features/settings/components/settings-page.tsx b/src/features/settings/components/settings-page.tsx index bee6cc9..866f4d3 100644 --- a/src/features/settings/components/settings-page.tsx +++ b/src/features/settings/components/settings-page.tsx @@ -25,7 +25,7 @@ export function SettingsPage() { const deviceId = useDeviceId() const { needRefresh, checkForUpdate, applyUpdate } = usePwaUpdate() const push = usePush() - const { follows, follow, unfollowAll } = useFollows() + const { follow, unfollowAllTopics, unfollowAllPoliticians } = useFollows() const [checking, setChecking] = useState(false) const [loading, setLoading] = useState(false) const [result, setResult] = useState(null) @@ -93,18 +93,16 @@ export function SettingsPage() { return (
- {/* --- Notifications --- */} - {VAPID_PUBLIC_KEY && ( -
-

- Benachrichtigungen -

- - - {push.permission === "denied" ? ( + {/* --- Permissions: Push + Location --- */} +
+

Berechtigungen

+ + + {VAPID_PUBLIC_KEY && + (push.permission === "denied" ? (
- Benachrichtigungen sind blockiert. Bitte in den Systemeinstellungen aktivieren. + Push blockiert — bitte in den Systemeinstellungen aktivieren.
) : ( @@ -122,80 +120,57 @@ export function SettingsPage() { }} />
- )} - {!standalone && ( - - )} - - - - )} - - {/* --- Location --- */} -
-

Standort

- - {loading && ( -
-
- {hasLocation ? "Aktualisiere…" : "Erkenne…"} -
- )} - - {errorMsg && ( -
- {errorMsg} -
- )} - -
- {!hasLocation && !loading && ( - - )} - {hasLocation && ( - <> - - - - )} -
+ + + + )} + +
- {/* --- Follows --- */} - {follows.length > 0 && ( -
-

Follows

-
- -
-
- )} - {/* --- App Update --- */}

App-Update

@@ -325,6 +300,12 @@ export function SettingsPage() { +
+ Allen Themen entfolgen + +
Alle Abgeordnete folgen
@@ -349,6 +330,18 @@ export function SettingsPage() {
+
+ Allen Abgeordneten entfolgen + +
+
+ Abgeordnete neu laden + +
diff --git a/src/shared/db/follows.ts b/src/shared/db/follows.ts index 33e171d..90ccda5 100644 --- a/src/shared/db/follows.ts +++ b/src/shared/db/follows.ts @@ -28,7 +28,10 @@ export async function removeFollow(db: PGlite, type: "topic" | "politician", ent await db.query("DELETE FROM follows WHERE type = $1 AND entity_id = $2", [type, entityId]) } -export async function removeAllFollows(db: PGlite): Promise { - const res = await db.query("DELETE FROM follows") - return res.affectedRows ?? 0 +export async function removeAllFollows(db: PGlite): Promise { + await db.query("DELETE FROM follows") +} + +export async function removeFollowsByType(db: PGlite, type: "topic" | "politician"): Promise { + await db.query("DELETE FROM follows WHERE type = $1", [type]) } diff --git a/src/shared/hooks/use-follows.ts b/src/shared/hooks/use-follows.ts index 14bcc09..f594bb0 100644 --- a/src/shared/hooks/use-follows.ts +++ b/src/shared/hooks/use-follows.ts @@ -1,4 +1,11 @@ -import { type Follow, addFollow, getFollows, removeAllFollows, removeFollow } from "@/shared/db/follows" +import { + type Follow, + addFollow, + getFollows, + removeAllFollows, + removeFollow, + removeFollowsByType, +} from "@/shared/db/follows" import { useDb } from "@/shared/db/provider" import { useCallback, useEffect, useState } from "react" @@ -54,5 +61,15 @@ export function useFollows() { emitChange() }, [db]) - return { follows, isFollowing, follow, unfollow, unfollowAll } + const unfollowAllTopics = useCallback(async () => { + await removeFollowsByType(db, "topic") + emitChange() + }, [db]) + + const unfollowAllPoliticians = useCallback(async () => { + await removeFollowsByType(db, "politician") + emitChange() + }, [db]) + + return { follows, isFollowing, follow, unfollow, unfollowAll, unfollowAllTopics, unfollowAllPoliticians } }