fix: upload image
This commit is contained in:
@@ -59,10 +59,11 @@ export default function CommentsPage() {
|
||||
}
|
||||
|
||||
async function confirmDelete() {
|
||||
if (!deleting || !query) return;
|
||||
if (!deleting || !query || deleting.id == null) return;
|
||||
setRemoving(true);
|
||||
try {
|
||||
await apiFetch(`/comments/${query.type}/${query.id}`, {
|
||||
// Delete targets the comment's own id: /comments/{type}/{id}/{commentId}
|
||||
await apiFetch(`/comments/${query.type}/${query.id}/${deleting.id}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
toast.success("نظر حذف شد.");
|
||||
|
||||
+117
-43
@@ -19,6 +19,7 @@ import {
|
||||
import { EditIcon, PlusIcon, TrashIcon } from "@/components/icons";
|
||||
import { formatDuration } from "@/lib/utils";
|
||||
import { MediaPreview } from "@/components/MediaPreview";
|
||||
import { ImagePicker } from "@/components/ImagePicker";
|
||||
import { pickUrl, SOUND_KEYS, VIDEO_KEYS, IMAGE_KEYS } from "@/lib/media";
|
||||
|
||||
interface Category {
|
||||
@@ -30,18 +31,58 @@ interface Media {
|
||||
id: number;
|
||||
title?: string;
|
||||
caption?: string;
|
||||
category_id?: number;
|
||||
category?: { id?: number; name?: string };
|
||||
// The API returns a `categories` array (many-to-many).
|
||||
categories?: Category[];
|
||||
subcategories?: Category[];
|
||||
subCategories?: Category[];
|
||||
type?: string;
|
||||
duration?: number;
|
||||
visibility?: string;
|
||||
is_premium?: boolean;
|
||||
external_url?: string | null;
|
||||
image_id?: number | null;
|
||||
}
|
||||
|
||||
// Compact multi-select rendered as toggle chips.
|
||||
function ChipMultiSelect({
|
||||
options,
|
||||
selected,
|
||||
onToggle,
|
||||
}: {
|
||||
options: Category[];
|
||||
selected: number[];
|
||||
onToggle: (id: number) => void;
|
||||
}) {
|
||||
if (!options.length)
|
||||
return <p className="text-xs text-muted">موردی برای انتخاب نیست.</p>;
|
||||
return (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{options.map((o) => {
|
||||
const on = selected.includes(o.id);
|
||||
return (
|
||||
<button
|
||||
key={o.id}
|
||||
type="button"
|
||||
onClick={() => onToggle(o.id)}
|
||||
className={`rounded-full border px-3 py-1 text-xs transition ${
|
||||
on
|
||||
? "border-primary bg-primary text-white"
|
||||
: "border-border bg-surface text-foreground hover:bg-surface-muted"
|
||||
}`}
|
||||
>
|
||||
{o.name ?? `#${o.id}`}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function MediaPage() {
|
||||
const [search, setSearch] = useState("");
|
||||
const { data, loading, error, reload } = useList<Media>("/media", { search });
|
||||
const { data: categories } = useList<Category>("/categories");
|
||||
const { data: subCategories } = useList<Category>("/sub-categories");
|
||||
const toast = useToast();
|
||||
|
||||
const [editing, setEditing] = useState<Media | null>(null);
|
||||
@@ -50,12 +91,16 @@ export default function MediaPage() {
|
||||
|
||||
const [title, setTitle] = useState("");
|
||||
const [caption, setCaption] = useState("");
|
||||
const [categoryId, setCategoryId] = useState("");
|
||||
const [categoryIds, setCategoryIds] = useState<number[]>([]);
|
||||
const [subcategoryIds, setSubcategoryIds] = useState<number[]>([]);
|
||||
const [type, setType] = useState("audio");
|
||||
const [duration, setDuration] = useState("");
|
||||
const [visibility, setVisibility] = useState("public");
|
||||
const [isPremium, setIsPremium] = useState(false);
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
const [externalUrl, setExternalUrl] = useState("");
|
||||
const [imageId, setImageId] = useState<number | null>(null);
|
||||
const [imageFile, setImageFile] = useState<File | null>(null);
|
||||
|
||||
const [deleting, setDeleting] = useState<Media | null>(null);
|
||||
const [removing, setRemoving] = useState(false);
|
||||
@@ -63,12 +108,16 @@ export default function MediaPage() {
|
||||
function resetForm() {
|
||||
setTitle("");
|
||||
setCaption("");
|
||||
setCategoryId("");
|
||||
setCategoryIds([]);
|
||||
setSubcategoryIds([]);
|
||||
setType("audio");
|
||||
setDuration("");
|
||||
setVisibility("public");
|
||||
setIsPremium(false);
|
||||
setFile(null);
|
||||
setExternalUrl("");
|
||||
setImageId(null);
|
||||
setImageFile(null);
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
@@ -81,21 +130,25 @@ export default function MediaPage() {
|
||||
setEditing(row);
|
||||
setTitle(row.title ?? "");
|
||||
setCaption(row.caption ?? "");
|
||||
setCategoryId(
|
||||
row.category_id != null
|
||||
? String(row.category_id)
|
||||
: row.category?.id != null
|
||||
? String(row.category.id)
|
||||
: "",
|
||||
setCategoryIds((row.categories ?? []).map((c) => c.id));
|
||||
setSubcategoryIds(
|
||||
(row.subcategories ?? row.subCategories ?? []).map((c) => c.id),
|
||||
);
|
||||
setType(row.type ?? "audio");
|
||||
setDuration(row.duration != null ? String(row.duration) : "");
|
||||
setVisibility(row.visibility ?? "public");
|
||||
setIsPremium(!!row.is_premium);
|
||||
setFile(null);
|
||||
setExternalUrl(row.external_url ?? "");
|
||||
setImageId(row.image_id ?? null);
|
||||
setImageFile(null);
|
||||
setOpen(true);
|
||||
}
|
||||
|
||||
function toggleId(list: number[], set: (v: number[]) => void, id: number) {
|
||||
set(list.includes(id) ? list.filter((x) => x !== id) : [...list, id]);
|
||||
}
|
||||
|
||||
async function save(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setSaving(true);
|
||||
@@ -103,12 +156,16 @@ export default function MediaPage() {
|
||||
const body = toFormData({
|
||||
title,
|
||||
caption,
|
||||
category_id: categoryId,
|
||||
category_ids: categoryIds,
|
||||
subcategory_ids: subcategoryIds,
|
||||
type,
|
||||
duration,
|
||||
visibility,
|
||||
is_premium: isPremium,
|
||||
file,
|
||||
external_url: externalUrl,
|
||||
image_id: imageId,
|
||||
image: imageFile,
|
||||
});
|
||||
if (editing) {
|
||||
// File-bearing update: POST /media/:id (multipart, file optional)
|
||||
@@ -165,9 +222,12 @@ export default function MediaPage() {
|
||||
},
|
||||
{ key: "title", header: "عنوان", render: (r) => r.title ?? "—" },
|
||||
{
|
||||
key: "category",
|
||||
key: "categories",
|
||||
header: "دستهبندی",
|
||||
render: (r) => r.category?.name ?? "—",
|
||||
render: (r) =>
|
||||
r.categories?.length
|
||||
? r.categories.map((c) => c.name).filter(Boolean).join("، ")
|
||||
: "—",
|
||||
},
|
||||
{
|
||||
key: "type",
|
||||
@@ -275,19 +335,30 @@ export default function MediaPage() {
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="دستهبندی" required>
|
||||
<Select
|
||||
value={categoryId}
|
||||
onChange={(e) => setCategoryId(e.target.value)}
|
||||
required
|
||||
>
|
||||
<option value="">انتخاب دستهبندی</option>
|
||||
{categories.map((c) => (
|
||||
<option key={c.id} value={c.id}>
|
||||
{c.name ?? `#${c.id}`}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
<Field label="تصویر شاخص" hint="انتخاب از کتابخانه یا بارگذاری تصویر جدید">
|
||||
<ImagePicker
|
||||
imageId={imageId}
|
||||
onPickId={setImageId}
|
||||
file={imageFile}
|
||||
onPickFile={setImageFile}
|
||||
existingUrl={editing ? pickUrl(editing, IMAGE_KEYS) : null}
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="دستهبندیها">
|
||||
<ChipMultiSelect
|
||||
options={categories}
|
||||
selected={categoryIds}
|
||||
onToggle={(id) => toggleId(categoryIds, setCategoryIds, id)}
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="زیردستهها">
|
||||
<ChipMultiSelect
|
||||
options={subCategories}
|
||||
selected={subcategoryIds}
|
||||
onToggle={(id) => toggleId(subcategoryIds, setSubcategoryIds, id)}
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="نوع" required>
|
||||
@@ -297,6 +368,26 @@ export default function MediaPage() {
|
||||
</Select>
|
||||
</Field>
|
||||
|
||||
<Field
|
||||
label={editing ? "فایل (در صورت تغییر)" : "فایل"}
|
||||
hint="فایل صوتی/تصویری را بارگذاری کنید یا از «لینک خارجی» استفاده کنید."
|
||||
>
|
||||
<Input
|
||||
type="file"
|
||||
accept="audio/*,video/*"
|
||||
onChange={(e) => setFile(e.target.files?.[0] ?? null)}
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="لینک خارجی" hint="اگر فایل آپلود نمیکنید، آدرس مستقیم فایل را وارد کنید.">
|
||||
<Input
|
||||
dir="ltr"
|
||||
value={externalUrl}
|
||||
onChange={(e) => setExternalUrl(e.target.value)}
|
||||
placeholder="https://..."
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="مدت (ثانیه)">
|
||||
<Input
|
||||
type="number"
|
||||
@@ -318,23 +409,6 @@ export default function MediaPage() {
|
||||
</Select>
|
||||
</Field>
|
||||
|
||||
<Field
|
||||
label={editing ? "فایل (در صورت تغییر)" : "فایل"}
|
||||
hint={
|
||||
editing
|
||||
? "در صورت خالی بودن، فایل قبلی حفظ میشود."
|
||||
: undefined
|
||||
}
|
||||
required={!editing}
|
||||
>
|
||||
<Input
|
||||
type="file"
|
||||
accept="audio/*,video/*"
|
||||
onChange={(e) => setFile(e.target.files?.[0] ?? null)}
|
||||
required={!editing}
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Switch
|
||||
checked={isPremium}
|
||||
onChange={setIsPremium}
|
||||
|
||||
@@ -15,8 +15,9 @@ import {
|
||||
PageHeader,
|
||||
} from "@/components/ui";
|
||||
import { EditIcon, PlusIcon, TrashIcon } from "@/components/icons";
|
||||
import { toFa, formatDuration } from "@/lib/utils";
|
||||
import { formatDuration } from "@/lib/utils";
|
||||
import { MediaPreview } from "@/components/MediaPreview";
|
||||
import { ImagePicker } from "@/components/ImagePicker";
|
||||
import { pickUrl, SOUND_KEYS, IMAGE_KEYS } from "@/lib/media";
|
||||
|
||||
interface Track {
|
||||
@@ -25,8 +26,8 @@ interface Track {
|
||||
artist?: string;
|
||||
duration?: number | null;
|
||||
type?: string;
|
||||
order?: number;
|
||||
playlist_id?: number;
|
||||
image_id?: number | null;
|
||||
}
|
||||
|
||||
interface Playlist {
|
||||
@@ -45,37 +46,41 @@ export default function MusicTracksPage() {
|
||||
|
||||
const [title, setTitle] = useState("");
|
||||
const [artist, setArtist] = useState("");
|
||||
const [type, setType] = useState("");
|
||||
const [type, setType] = useState("public");
|
||||
const [duration, setDuration] = useState("");
|
||||
const [playlistId, setPlaylistId] = useState("");
|
||||
const [imageId, setImageId] = useState("");
|
||||
const [order, setOrder] = useState("");
|
||||
const [imageId, setImageId] = useState<number | null>(null);
|
||||
const [imageFile, setImageFile] = useState<File | null>(null);
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
|
||||
const [deleting, setDeleting] = useState<Track | null>(null);
|
||||
const [removing, setRemoving] = useState(false);
|
||||
|
||||
function openCreate() {
|
||||
setEditing(null);
|
||||
function resetForm() {
|
||||
setTitle("");
|
||||
setArtist("");
|
||||
setType("");
|
||||
setType("public");
|
||||
setDuration("");
|
||||
setPlaylistId("");
|
||||
setImageId("");
|
||||
setOrder("");
|
||||
setImageId(null);
|
||||
setImageFile(null);
|
||||
setFile(null);
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
setEditing(null);
|
||||
resetForm();
|
||||
setOpen(true);
|
||||
}
|
||||
function openEdit(row: Track) {
|
||||
setEditing(row);
|
||||
setTitle(row.title ?? "");
|
||||
setArtist(row.artist ?? "");
|
||||
setType(row.type ?? "");
|
||||
setType(row.type ?? "public");
|
||||
setDuration(row.duration != null ? String(row.duration) : "");
|
||||
setPlaylistId(row.playlist_id != null ? String(row.playlist_id) : "");
|
||||
setImageId("");
|
||||
setOrder(row.order != null ? String(row.order) : "");
|
||||
setImageId(row.image_id ?? null);
|
||||
setImageFile(null);
|
||||
setFile(null);
|
||||
setOpen(true);
|
||||
}
|
||||
@@ -85,18 +90,21 @@ export default function MusicTracksPage() {
|
||||
setSaving(true);
|
||||
try {
|
||||
if (editing) {
|
||||
// Update is JSON on /music/:id
|
||||
await apiFetch(`/music/${editing.id}`, {
|
||||
method: "PUT",
|
||||
body: {
|
||||
title,
|
||||
artist,
|
||||
order: order === "" ? undefined : Number(order),
|
||||
},
|
||||
// The PUT /music/:id route can carry files, so we POST multipart with
|
||||
// Laravel method spoofing (_method=PUT).
|
||||
const body = toFormData({
|
||||
_method: "PUT",
|
||||
title,
|
||||
artist,
|
||||
type,
|
||||
duration,
|
||||
image_id: imageId,
|
||||
image: imageFile,
|
||||
file,
|
||||
});
|
||||
await apiFetch(`/music/${editing.id}`, { method: "POST", body });
|
||||
toast.success("آهنگ ویرایش شد.");
|
||||
} else {
|
||||
// Create is multipart on /music
|
||||
await apiFetch("/music", {
|
||||
method: "POST",
|
||||
body: toFormData({
|
||||
@@ -106,6 +114,7 @@ export default function MusicTracksPage() {
|
||||
duration,
|
||||
playlist_id: playlistId,
|
||||
image_id: imageId,
|
||||
image: imageFile,
|
||||
file,
|
||||
}),
|
||||
});
|
||||
@@ -159,7 +168,12 @@ export default function MusicTracksPage() {
|
||||
header: "مدت زمان",
|
||||
render: (r) => formatDuration(r.duration),
|
||||
},
|
||||
{ key: "type", header: "نوع", render: (r) => r.type ?? "—" },
|
||||
{
|
||||
key: "type",
|
||||
header: "نوع",
|
||||
render: (r) =>
|
||||
r.type === "private" ? "خصوصی" : r.type === "public" ? "عمومی" : (r.type ?? "—"),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
@@ -228,6 +242,7 @@ export default function MusicTracksPage() {
|
||||
autoFocus
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="هنرمند">
|
||||
<Input
|
||||
value={artist}
|
||||
@@ -236,63 +251,60 @@ export default function MusicTracksPage() {
|
||||
/>
|
||||
</Field>
|
||||
|
||||
{editing ? (
|
||||
<Field label="ترتیب">
|
||||
<Input
|
||||
type="number"
|
||||
value={order}
|
||||
onChange={(e) => setOrder(e.target.value)}
|
||||
dir="ltr"
|
||||
/>
|
||||
<Field label="تصویر جلد" hint="انتخاب از کتابخانه یا بارگذاری تصویر جدید">
|
||||
<ImagePicker
|
||||
imageId={imageId}
|
||||
onPickId={setImageId}
|
||||
file={imageFile}
|
||||
onPickFile={setImageFile}
|
||||
existingUrl={editing ? pickUrl(editing, IMAGE_KEYS) : null}
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="نوع">
|
||||
<Select value={type} onChange={(e) => setType(e.target.value)}>
|
||||
<option value="public">عمومی</option>
|
||||
<option value="private">خصوصی</option>
|
||||
</Select>
|
||||
</Field>
|
||||
|
||||
<Field label="مدت زمان (ثانیه)">
|
||||
<Input
|
||||
type="number"
|
||||
value={duration}
|
||||
onChange={(e) => setDuration(e.target.value)}
|
||||
dir="ltr"
|
||||
/>
|
||||
</Field>
|
||||
|
||||
{!editing && (
|
||||
<Field label="پلیلیست">
|
||||
<Select
|
||||
value={playlistId}
|
||||
onChange={(e) => setPlaylistId(e.target.value)}
|
||||
>
|
||||
<option value="">انتخاب کنید…</option>
|
||||
{playlists.map((p) => (
|
||||
<option key={p.id} value={p.id}>
|
||||
{p.name ?? `#${p.id}`}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
</Field>
|
||||
) : (
|
||||
<>
|
||||
<Field label="نوع">
|
||||
<Input
|
||||
value={type}
|
||||
onChange={(e) => setType(e.target.value)}
|
||||
placeholder="مثلاً music"
|
||||
/>
|
||||
</Field>
|
||||
<Field label="مدت زمان (ثانیه)">
|
||||
<Input
|
||||
type="number"
|
||||
value={duration}
|
||||
onChange={(e) => setDuration(e.target.value)}
|
||||
dir="ltr"
|
||||
/>
|
||||
</Field>
|
||||
<Field label="پلیلیست">
|
||||
<Select
|
||||
value={playlistId}
|
||||
onChange={(e) => setPlaylistId(e.target.value)}
|
||||
>
|
||||
<option value="">انتخاب کنید…</option>
|
||||
{playlists.map((p) => (
|
||||
<option key={p.id} value={p.id}>
|
||||
{p.name ?? `#${p.id}`}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
</Field>
|
||||
<Field label="شناسه تصویر">
|
||||
<Input
|
||||
value={imageId}
|
||||
onChange={(e) => setImageId(e.target.value)}
|
||||
dir="ltr"
|
||||
placeholder="image_id"
|
||||
/>
|
||||
</Field>
|
||||
<Field label="فایل صوتی" required>
|
||||
<Input
|
||||
type="file"
|
||||
accept="audio/*"
|
||||
onChange={(e) => setFile(e.target.files?.[0] ?? null)}
|
||||
required
|
||||
/>
|
||||
</Field>
|
||||
</>
|
||||
)}
|
||||
|
||||
<Field
|
||||
label={editing ? "فایل صوتی (در صورت تغییر)" : "فایل صوتی"}
|
||||
hint={editing ? "در صورت خالی بودن، فایل قبلی حفظ میشود." : undefined}
|
||||
required={!editing}
|
||||
>
|
||||
<Input
|
||||
type="file"
|
||||
accept="audio/*"
|
||||
onChange={(e) => setFile(e.target.files?.[0] ?? null)}
|
||||
required={!editing}
|
||||
/>
|
||||
</Field>
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
"use client";
|
||||
|
||||
// Image association control used by media, music, categories, etc.
|
||||
// Lets the user either (a) pick an existing image from the /images library
|
||||
// (sets `image_id`) or (b) upload a new image file (sets `image` File). Shows a
|
||||
// live thumbnail of the current choice.
|
||||
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useList } from "@/lib/useResource";
|
||||
import { pickUrl, IMAGE_KEYS } from "@/lib/media";
|
||||
import { Button, Modal, Spinner, EmptyState } from "./ui";
|
||||
import { ImageIcon, CloseIcon } from "./icons";
|
||||
|
||||
interface LibImage {
|
||||
id: number;
|
||||
title?: string | null;
|
||||
}
|
||||
|
||||
export function ImagePicker({
|
||||
imageId,
|
||||
onPickId,
|
||||
file,
|
||||
onPickFile,
|
||||
existingUrl,
|
||||
}: {
|
||||
imageId: number | null;
|
||||
onPickId: (id: number | null) => void;
|
||||
file: File | null;
|
||||
onPickFile: (f: File | null) => void;
|
||||
// URL of the already-saved image (edit mode) when no new choice is made.
|
||||
existingUrl?: string | null;
|
||||
}) {
|
||||
const [libOpen, setLibOpen] = useState(false);
|
||||
const { data: images, loading } = useList<LibImage>(
|
||||
libOpen ? "/images/all" : null,
|
||||
);
|
||||
|
||||
// Object URL preview for a freshly uploaded file.
|
||||
const [filePreview, setFilePreview] = useState<string | null>(null);
|
||||
useEffect(() => {
|
||||
if (!file) {
|
||||
setFilePreview(null);
|
||||
return;
|
||||
}
|
||||
const url = URL.createObjectURL(file);
|
||||
setFilePreview(url);
|
||||
return () => URL.revokeObjectURL(url);
|
||||
}, [file]);
|
||||
|
||||
// Resolve the thumbnail for the currently chosen library image (if loaded).
|
||||
const pickedLibUrl = useMemo(() => {
|
||||
if (!imageId || !images.length) return null;
|
||||
const found = images.find((i) => i.id === imageId);
|
||||
return found ? pickUrl(found, IMAGE_KEYS) : null;
|
||||
}, [imageId, images]);
|
||||
|
||||
const preview = filePreview ?? pickedLibUrl ?? existingUrl ?? null;
|
||||
|
||||
function clearAll() {
|
||||
onPickId(null);
|
||||
onPickFile(null);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="flex h-16 w-16 shrink-0 items-center justify-center overflow-hidden rounded-xl border border-border bg-surface-muted text-muted">
|
||||
{preview ? (
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
<img src={preview} alt="" className="h-full w-full object-cover" />
|
||||
) : (
|
||||
<ImageIcon className="h-6 w-6" />
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant="secondary"
|
||||
onClick={() => setLibOpen(true)}
|
||||
>
|
||||
انتخاب از کتابخانه
|
||||
</Button>
|
||||
|
||||
<label className="inline-flex cursor-pointer items-center justify-center gap-2 rounded-xl border border-border bg-surface-muted px-4 py-2 text-sm font-medium text-foreground transition hover:bg-[#e2e6f2]">
|
||||
بارگذاری تصویر
|
||||
<input
|
||||
type="file"
|
||||
accept="image/*"
|
||||
className="hidden"
|
||||
onChange={(e) => {
|
||||
const f = e.target.files?.[0] ?? null;
|
||||
onPickFile(f);
|
||||
if (f) onPickId(null); // a fresh upload supersedes a library pick
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
|
||||
{(preview || imageId || file) && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
className="text-danger"
|
||||
icon={<CloseIcon className="h-4 w-4" />}
|
||||
onClick={clearAll}
|
||||
>
|
||||
حذف
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Modal
|
||||
open={libOpen}
|
||||
onClose={() => setLibOpen(false)}
|
||||
title="انتخاب تصویر از کتابخانه"
|
||||
>
|
||||
{loading ? (
|
||||
<div className="flex justify-center py-10">
|
||||
<Spinner />
|
||||
</div>
|
||||
) : !images.length ? (
|
||||
<EmptyState
|
||||
title="تصویری موجود نیست"
|
||||
message="ابتدا از بخش «کتابخانه تصاویر» تصویر اضافه کنید."
|
||||
/>
|
||||
) : (
|
||||
<div className="grid grid-cols-3 gap-3 sm:grid-cols-4">
|
||||
{images.map((img) => {
|
||||
const url = pickUrl(img, IMAGE_KEYS);
|
||||
const selected = img.id === imageId;
|
||||
return (
|
||||
<button
|
||||
key={img.id}
|
||||
type="button"
|
||||
onClick={() => {
|
||||
onPickId(img.id);
|
||||
onPickFile(null);
|
||||
setLibOpen(false);
|
||||
}}
|
||||
className={`overflow-hidden rounded-xl border-2 transition ${
|
||||
selected
|
||||
? "border-primary"
|
||||
: "border-transparent hover:border-border"
|
||||
}`}
|
||||
title={img.title ?? String(img.id)}
|
||||
>
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img src={url ?? ""} alt={img.title ?? ""} className="aspect-square w-full object-cover" />
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+7
-8
@@ -17,12 +17,11 @@ All meditation calls send `Authorization: Bearer <meditationToken>` and `Accept:
|
||||
|
||||
## Endpoints (path is after the meditation base `/api`)
|
||||
|
||||
### Media
|
||||
- GET `/media` — list. query: `categories`, `tags`, `search`
|
||||
- GET `/media/filters`
|
||||
- GET `/media/:id`
|
||||
- POST `/media` — multipart: title, caption, category_id, subcategory_id, file, duration, visibility, type
|
||||
- POST `/media/:id` — update (multipart: is_premium; json: subcategory_ids[])
|
||||
### Media (verified against MediaController)
|
||||
- GET `/media` — list (returns `categories[]`, nested `image`). query: `categories`, `subcategories`, `durations`, `search`
|
||||
- GET `/media/filters`, `/media/:id`
|
||||
- POST `/media` — multipart: title, caption, type(audio|video), `category_ids[]`, `subcategory_ids[]`, `image_id` or `image`(file), file(mp3/wav/mp4/mov) **or** `external_url`, duration, is_premium, visibility, tags[]
|
||||
- POST `/media/:id` — update (same multipart fields). Playable URL is in **`external_url`**; thumbnail in nested **`image.url`**.
|
||||
- GET `/media/popular`, `/media/recently-played`, `/media/saved`
|
||||
- POST `/media/:id/play`, `/media/:id/save`, `/media/:id/note`, `/media/:id/feedback` (stars, content)
|
||||
- Categories: GET/POST/PUT/DELETE `/categories` (multipart name)
|
||||
@@ -31,7 +30,7 @@ All meditation calls send `Authorization: Bearer <meditationToken>` and `Accept:
|
||||
### Track (music)
|
||||
- Categories: GET `/music-categories/:id`, POST `/music-categories`, PUT/DELETE `/music-categories/:id` (name, description, order, image_id, is_active)
|
||||
- Sub-categories: GET `/music-subcategories`, POST `/music-subcategories`, PUT/DELETE `/music-subcategories/:id`
|
||||
- Music: GET `/music/:id`, POST `/music` (title, artist, file, playlist_id, type, duration, image_id), PUT/DELETE `/music/:id`
|
||||
- Music: GET `/music` (list, `{data:[]}`), GET `/music/:id`, POST `/music` (multipart: title, artist, file, type(public|private), `image_id` or `image`(file), playlist_id, duration), PUT/DELETE `/music/:id`. PUT with a file → POST + `_method=PUT`. Audio URL in `url`, cover in `image_url`.
|
||||
- POST `/music/update-order`, GET `/music/playlist/:id`, POST `/music/:musicId/add-to-playlist`, DELETE `/music/:musicId/remove-from-playlist`
|
||||
- Playlists: GET `/music-playlists/:id?`, POST `/music-playlists`, PUT/DELETE `/music-playlists/:id` (name, description, category_ids[], subcategory_ids[])
|
||||
|
||||
@@ -71,7 +70,7 @@ All meditation calls send `Authorization: Bearer <meditationToken>` and `Accept:
|
||||
- GET `/worries`, POST `/worries` (title, note), PUT/DELETE `/worries/:id`, PATCH `/worries/:id/toggle`
|
||||
|
||||
### Comments / Likes / Saves / Ratings (by type+id, e.g. type=media|music|playlist)
|
||||
- Comments: GET/POST/DELETE `/comments/:type/:id` (content)
|
||||
- Comments: GET/POST `/comments/:type/:id` (content); PUT/DELETE `/comments/:type/:id/:commentId`
|
||||
- Likes: POST `/likes/toggle`, `/likes/like` (type, id), GET `/likes/my-liked?type=`
|
||||
- Saves: POST `/saves/toggle`, `/saves/save`, `/saves/unsave`, `/saves/check` (type, id), GET `/saves/my-saved?type=`
|
||||
- Ratings: GET/POST/DELETE `/ratings/:type/:id` (stars), GET `/ratings/:type/:id/user`
|
||||
|
||||
Reference in New Issue
Block a user