feat: Implement push subscription event handling in AddToCartButton and ProductFilters components; enhance article and category unsubscribe functionality with optional identifiers

This commit is contained in:
sebseb7
2026-03-26 21:28:49 +01:00
parent ba66b82b2b
commit 188c883450
4 changed files with 75 additions and 6 deletions

View File

@@ -3,6 +3,8 @@
*/
export {
PUSH_SUBSCRIPTIONS_CHANGED_EVENT,
emitPushSubscriptionsChanged,
fetchPushConfiguration,
registerPushServiceWorker,
ensurePushSubscription,
@@ -44,13 +46,26 @@ export async function categoryPushSubscribe(kKategorie, subscription) {
}
/**
* POST /api/category/push/unsubscribe — same contract as article: optional `kKategorie` for scoped delete.
*
* @param {string} endpoint
* @param {number|string} [kKategorie]
*/
export async function categoryPushUnsubscribe(endpoint) {
export async function categoryPushUnsubscribe(endpoint, kKategorie) {
const parsed =
kKategorie != null && kKategorie !== ""
? typeof kKategorie === "number"
? kKategorie
: parseInt(String(kKategorie), 10)
: NaN;
const body =
Number.isFinite(parsed) && parsed > 0
? { endpoint, kKategorie: parsed }
: { endpoint };
const res = await fetch("/api/category/push/unsubscribe", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ endpoint }),
body: JSON.stringify(body),
});
const data = await res.json().catch(() => ({}));
return { ...data, httpOk: res.ok };