feat: fix recording save and add publish/unpublish support
- Fix broken fetch("/api/sexy/recordings") → use createRecording GraphQL service
- Round duration to integer before sending (GraphQL Int type)
- Add updateRecording mutation to services
- Add publish/unpublish buttons to RecordingCard (draft ↔ published)
- Remove "Go to Play" button from recordings page header
- Add publish/unpublish i18n keys
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import { _ } from "svelte-i18n";
|
||||
import { goto } from "$app/navigation";
|
||||
import { toast } from "svelte-sonner";
|
||||
import { deleteRecording } from "$lib/services";
|
||||
import { deleteRecording, updateRecording } from "$lib/services";
|
||||
import { Button } from "$lib/components/ui/button";
|
||||
import * as Empty from "$lib/components/ui/empty";
|
||||
import * as Dialog from "$lib/components/ui/dialog";
|
||||
@@ -38,6 +38,26 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function handlePublishRecording(id: string) {
|
||||
try {
|
||||
await updateRecording(id, { status: "published" });
|
||||
recordings = recordings.map((r) => (r.id === id ? { ...r, status: "published" } : r));
|
||||
toast.success($_("me.recordings.publish_success"));
|
||||
} catch {
|
||||
toast.error($_("me.recordings.publish_error"));
|
||||
}
|
||||
}
|
||||
|
||||
async function handleUnpublishRecording(id: string) {
|
||||
try {
|
||||
await updateRecording(id, { status: "draft" });
|
||||
recordings = recordings.map((r) => (r.id === id ? { ...r, status: "draft" } : r));
|
||||
toast.success($_("me.recordings.unpublish_success"));
|
||||
} catch {
|
||||
toast.error($_("me.recordings.unpublish_error"));
|
||||
}
|
||||
}
|
||||
|
||||
function handlePlayRecording(id: string) {
|
||||
goto(`/play?recording=${id}`);
|
||||
}
|
||||
@@ -46,15 +66,8 @@
|
||||
<Meta title={$_("me.recordings.title")} />
|
||||
|
||||
<div class="py-3 sm:py-6 lg:pl-6">
|
||||
<div class="flex items-center justify-between mb-6">
|
||||
<div class="mb-6">
|
||||
<h1 class="text-2xl font-bold">{$_("me.recordings.title")}</h1>
|
||||
<Button
|
||||
href="/play"
|
||||
class="cursor-pointer bg-gradient-to-r from-primary to-accent hover:from-primary/90 hover:to-accent/90"
|
||||
>
|
||||
<span class="icon-[ri--rocket-line] w-4 h-4 mr-2"></span>
|
||||
{$_("me.recordings.go_to_play")}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{#if recordings.length === 0}
|
||||
@@ -82,6 +95,8 @@
|
||||
<RecordingCard
|
||||
{recording}
|
||||
onPlay={handlePlayRecording}
|
||||
onPublish={handlePublishRecording}
|
||||
onUnpublish={handleUnpublishRecording}
|
||||
onDelete={handleDeleteRecording}
|
||||
/>
|
||||
{/each}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
import DeviceMappingDialog from "./components/device-mapping-dialog.svelte";
|
||||
import type { BluetoothDevice, RecordedEvent, DeviceInfo } from "$lib/types";
|
||||
import { toast } from "svelte-sonner";
|
||||
import { createRecording } from "$lib/services";
|
||||
import SexyBackground from "$lib/components/background/background.svelte";
|
||||
|
||||
// Runtime buttplug values — loaded dynamically from the buttplug nginx container
|
||||
@@ -173,26 +174,16 @@
|
||||
}));
|
||||
|
||||
try {
|
||||
const response = await fetch("/api/sexy/recordings", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
duration: recordingDuration,
|
||||
events: recordedEvents,
|
||||
device_info: deviceInfo,
|
||||
tags: data.tags,
|
||||
status: "draft",
|
||||
}),
|
||||
await createRecording({
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
duration: Math.round(recordingDuration),
|
||||
events: recordedEvents,
|
||||
device_info: deviceInfo,
|
||||
tags: data.tags,
|
||||
status: "draft",
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
toast.success("Recording saved successfully!");
|
||||
showSaveDialog = false;
|
||||
recordedEvents = [];
|
||||
|
||||
Reference in New Issue
Block a user