Redesign settings from scratch

This commit is contained in:
2025-11-03 11:21:08 +03:00
Unverified
parent 1c38bc39ec
commit dca0d319e9
10 changed files with 606 additions and 273 deletions
+11
View File
@@ -22,4 +22,15 @@ export async function changePassword(
if (!res.ok) throw new Error("Failed to change password");
}
export async function deleteAccount(token: string): Promise<void> {
const res = await fetch(`${API_BASE_URL}/account/delete`, {
method: "POST",
headers: getAuthHeaders(token)
});
if (!res.ok) {
const error = await res.json().catch(() => ({ detail: "Failed to delete account" }));
throw new Error(error.detail || "Failed to delete account");
}
}
@@ -183,6 +183,21 @@ export async function subscribe(token: string): Promise<boolean> {
return true;
}
// If subscription doesn't exist, try to get it from the push manager or create a new one
if (!subscription && registration) {
try {
// Try to get existing subscription first
subscription = await registration.pushManager.getSubscription();
// If no existing subscription, create a new one
if (!subscription) {
subscription = await subscribeToWebPush();
}
} catch (error) {
console.error("Failed to get or create subscription:", error);
subscription = await subscribeToWebPush();
}
}
return await sendSubscriptionToServer(token);
}