Compare commits

...
2 Commits
Author SHA1 Message Date
Amirmahdi 638d1dad52 fix 2026-06-27 10:28:37 +03:30
Amirmahdi dec17b537e feat: add order 2026-06-27 10:21:43 +03:30
+39 -3
View File
@@ -26,6 +26,7 @@ interface Category {
id: number; id: number;
name: string; name: string;
type: CategoryType; type: CategoryType;
order?: number;
description?: string | null; description?: string | null;
icon?: string | null; icon?: string | null;
subcategories_count?: number; subcategories_count?: number;
@@ -56,6 +57,7 @@ export default function CategoriesPage() {
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [name, setName] = useState(""); const [name, setName] = useState("");
const [type, setType] = useState<CategoryType>("media"); const [type, setType] = useState<CategoryType>("media");
const [order, setOrder] = useState("0");
const [description, setDescription] = useState(""); const [description, setDescription] = useState("");
const [icon, setIcon] = useState<File | null>(null); const [icon, setIcon] = useState<File | null>(null);
const [saving, setSaving] = useState(false); const [saving, setSaving] = useState(false);
@@ -67,6 +69,7 @@ export default function CategoriesPage() {
setEditing(null); setEditing(null);
setName(""); setName("");
setType(typeFilter); setType(typeFilter);
setOrder("0");
setDescription(""); setDescription("");
setIcon(null); setIcon(null);
setOpen(true); setOpen(true);
@@ -75,6 +78,7 @@ export default function CategoriesPage() {
setEditing(row); setEditing(row);
setName(row.name ?? ""); setName(row.name ?? "");
setType(row.type ?? "media"); setType(row.type ?? "media");
setOrder(String(row.order ?? 0));
setDescription(row.description ?? ""); setDescription(row.description ?? "");
setIcon(null); setIcon(null);
setOpen(true); setOpen(true);
@@ -84,12 +88,25 @@ export default function CategoriesPage() {
e.preventDefault(); e.preventDefault();
setSaving(true); setSaving(true);
try { try {
if (editing) { // Playlist categories live in the music_categories table, so their writes
// go to /music-categories (image is the `image` field, not `icon`).
const targetType = editing ? editing.type : type;
if (targetType === "playlist") {
const body = toFormData({ name, description, order, image: icon });
if (editing) {
await apiFetch(`/music-categories/${editing.id}`, { method: "POST", body });
toast.success("دسته‌بندی ویرایش شد.");
} else {
await apiFetch("/music-categories", { method: "POST", body });
toast.success("دسته‌بندی افزوده شد.");
}
} else if (editing) {
// Icon is a file, so update goes through POST + Laravel method spoofing. // Icon is a file, so update goes through POST + Laravel method spoofing.
const body = toFormData({ const body = toFormData({
_method: "PUT", _method: "PUT",
name, name,
type, type,
order,
description, description,
icon, icon,
}); });
@@ -98,7 +115,7 @@ export default function CategoriesPage() {
} else { } else {
await apiFetch("/categories", { await apiFetch("/categories", {
method: "POST", method: "POST",
body: toFormData({ name, type, description, icon }), body: toFormData({ name, type, order, description, icon }),
}); });
toast.success("دسته‌بندی افزوده شد."); toast.success("دسته‌بندی افزوده شد.");
} }
@@ -115,7 +132,11 @@ export default function CategoriesPage() {
if (!deleting) return; if (!deleting) return;
setRemoving(true); setRemoving(true);
try { try {
await apiFetch(`/categories/${deleting.id}`, { method: "DELETE" }); const path =
deleting.type === "playlist"
? `/music-categories/${deleting.id}`
: `/categories/${deleting.id}`;
await apiFetch(path, { method: "DELETE" });
toast.success("دسته‌بندی حذف شد."); toast.success("دسته‌بندی حذف شد.");
setDeleting(null); setDeleting(null);
reload(); reload();
@@ -135,6 +156,12 @@ export default function CategoriesPage() {
<MediaPreview kind="image" src={pickUrl(r, ICON_KEYS)} label={r.name} /> <MediaPreview kind="image" src={pickUrl(r, ICON_KEYS)} label={r.name} />
), ),
}, },
{
key: "order",
header: "ترتیب",
render: (r) => toFa(r.order ?? 0),
className: "w-20",
},
{ key: "name", header: "نام دسته‌بندی" }, { key: "name", header: "نام دسته‌بندی" },
{ {
key: "type", key: "type",
@@ -249,6 +276,15 @@ export default function CategoriesPage() {
/> />
</Field> </Field>
<Field label="ترتیب" hint="عدد کوچک‌تر بالاتر نمایش داده می‌شود.">
<Input
type="number"
value={order}
onChange={(e) => setOrder(e.target.value)}
dir="ltr"
/>
</Field>
<Field label="توضیحات"> <Field label="توضیحات">
<Textarea <Textarea
value={description} value={description}