Update guest PWA v2 UI and likes
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled

This commit is contained in:
Codex Agent
2026-02-05 15:09:19 +01:00
parent 6eafec2128
commit fa630e335d
22 changed files with 1288 additions and 200 deletions

View File

@@ -52,6 +52,50 @@ export async function likePhoto(id: number): Promise<number> {
return json.likes_count ?? json.data?.likes_count ?? 0;
}
export async function unlikePhoto(id: number): Promise<number> {
const headers = buildCsrfHeaders();
const res = await fetch(`/api/v1/photos/${id}/like`, {
method: 'DELETE',
credentials: 'include',
headers: {
...headers,
'Content-Type': 'application/json',
},
});
if (!res.ok) {
let payload: unknown = null;
try {
payload = await res.clone().json();
} catch (error) {
console.warn('Unlike photo: failed to parse error payload', error);
}
if (res.status === 419) {
const error: UploadError = new Error('CSRF token mismatch. Please refresh the page and try again.');
error.code = 'csrf_mismatch';
error.status = res.status;
throw error;
}
const error: UploadError = new Error(
(payload as { error?: { message?: string } } | null)?.error?.message ?? `Unlike failed: ${res.status}`
);
error.code = (payload as { error?: { code?: string } } | null)?.error?.code ?? 'unlike_failed';
error.status = res.status;
const meta = (payload as { error?: { meta?: Record<string, unknown> } } | null)?.error?.meta;
if (meta) {
error.meta = meta;
}
throw error;
}
const json = await res.json();
return json.likes_count ?? json.data?.likes_count ?? 0;
}
type UploadOptions = {
guestName?: string;
onProgress?: (percent: number) => void;