Frontend support for mark all viewed and delete all
All checks were successful
Build Container / build (push) Successful in 3m48s
All checks were successful
Build Container / build (push) Successful in 3m48s
This commit is contained in:
@@ -245,6 +245,28 @@ export async function addSubscription(topic: string): Promise<Subscription> {
|
||||
return response.json();
|
||||
}
|
||||
|
||||
// Add a new notification to a specific subscription
|
||||
export async function markAllNotificationsAsViewed(subscriptionId: number): Promise<void> {
|
||||
const response = await fetch(`${API_URL}/subscriptions/${subscriptionId}/notifications`, {
|
||||
method: 'POST',
|
||||
headers: authHeaders()
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to mark all notifications as viewed for subscription');
|
||||
}
|
||||
}
|
||||
|
||||
// Delete all notifications for a specific subscription
|
||||
export async function deleteSubscriptionNotifications(subscriptionId: number): Promise<void> {
|
||||
const response = await fetch(`${API_URL}/subscriptions/${subscriptionId}/notifications`, {
|
||||
method: 'DELETE',
|
||||
headers: authHeaders()
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to delete notifications for subscription');
|
||||
}
|
||||
}
|
||||
|
||||
// Delete a subscription
|
||||
export async function deleteSubscription(subscriptionId: number): Promise<void> {
|
||||
const response = await fetch(`${API_URL}/subscriptions/${subscriptionId}`, {
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { deleteNotification, setViewed, fetchSubscriptionNotifications } from '$lib/api';
|
||||
import {
|
||||
deleteNotification,
|
||||
setViewed,
|
||||
fetchSubscriptionNotifications,
|
||||
deleteSubscriptionNotifications,
|
||||
markAllNotificationsAsViewed
|
||||
} from '$lib/api';
|
||||
import type { Notification, Subscription } from '$lib/api';
|
||||
let { data } = $props();
|
||||
|
||||
@@ -15,7 +21,7 @@
|
||||
);
|
||||
if (!confirmed) return;
|
||||
try {
|
||||
await Promise.all(notifications.map((notification) => deleteNotification(notification.id)));
|
||||
deleteSubscriptionNotifications(subscription!.id);
|
||||
notifications = [];
|
||||
window.showNotification('success', 'All notifications deleted successfully.');
|
||||
} catch (error) {
|
||||
@@ -58,11 +64,7 @@
|
||||
}
|
||||
async function markAllViewed() {
|
||||
try {
|
||||
await Promise.all(
|
||||
notifications
|
||||
.filter((notification) => !notification.viewed)
|
||||
.map((notification) => setViewed(notification.id))
|
||||
);
|
||||
markAllNotificationsAsViewed(subscription!.id);
|
||||
notifications = notifications.map((notification) =>
|
||||
notification.viewed ? notification : { ...notification, viewed: true }
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user