feat(shows): redesign archive functionality and update delete show references

This commit is contained in:
Nik Afiq 2025-12-11 21:36:24 +09:00
parent 33ccef5142
commit c4ac2ed128
4 changed files with 21 additions and 10 deletions

View File

@ -7,5 +7,6 @@ export const API_ENDPOINT = {
TIME: buildApiUrl("/v1/time"),
DANIME: buildApiUrl("/v1/danime"),
OAUTH_FIREBASE: buildApiUrl("/v1/oauth/firebase"),
ARCHIVE: buildApiUrl("/v1/archive"),
},
} as const;

View File

@ -35,3 +35,12 @@ export type FirebaseAuthResponse = {
issuer?: string;
expires?: number;
};
export type ArchiveResult = {
moved_ids: number[];
deleted_ids: number[];
skipped_ids: number[];
inserted: number;
deleted: number;
skipped: number;
};

View File

@ -1,6 +1,6 @@
import { API_ENDPOINT } from "./endpoint";
import { ApiError, apiFetch } from "./client";
import type { DanimeEpisode, ScheduleResponse, ShowItem, TimeResponse } from "./types";
import type { ArchiveResult, DanimeEpisode, ScheduleResponse, ShowItem, TimeResponse } from "./types";
export type { DanimeEpisode, ScheduleResponse, ShowItem, TimeResponse } from "./types";
@ -137,18 +137,19 @@ export async function createShow(payload: {
});
}
export async function deleteShow(id: number, idToken: string) {
export async function archiveShow(id: number, idToken: string) {
if (!idToken) {
throw new ApiError("Missing auth token for delete");
throw new ApiError("Missing auth token for archive");
}
const url = `${API_ENDPOINT.v1.SHOWS}?id=${encodeURIComponent(id)}`;
await apiFetch<void>(url, {
method: "DELETE",
await apiFetch<ArchiveResult>(API_ENDPOINT.v1.ARCHIVE, {
method: "POST",
headers: {
"Authorization": `Bearer ${idToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ ids: [id] }),
timeoutMs: 10_000,
expect: "void",
logLabel: "delete show",
expect: "json",
logLabel: "archive show",
});
}

View File

@ -2,7 +2,7 @@ import React, { useEffect, useMemo, useState, useRef } from "react";
import { useNavigate } from "react-router-dom";
import { logApiError } from "../utils/logger";
import { toastError, toastInfo } from "../utils/toastBus";
import { createShow, deleteShow, fetchDanimeEpisode, fetchShows, postCurrentEpisode } from "../api/watchparty";
import { archiveShow, createShow, fetchDanimeEpisode, fetchShows, postCurrentEpisode } from "../api/watchparty";
import type { DanimeEpisode, ShowItem } from "../api/watchparty";
import { useAuth } from "../auth/AuthProvider";
@ -235,7 +235,7 @@ export default function ShowsPage() {
}
try {
setDeletingId(showId);
await deleteShow(showId, idToken);
await archiveShow(showId, idToken);
toastInfo("エピソードを削除しました");
if (selectedId === showId) {
setSelectedId(null);