Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b2d2dec7d | ||
|
|
e374829358 | ||
|
|
7c6d16693c | ||
|
|
3cc1d1385c |
Regular → Executable
@@ -45,7 +45,7 @@ const TYPE_LABELS: Record<CategoryType, string> = Object.fromEntries(
|
||||
// The icon is a direct image-file field on the category (not an image_id ref).
|
||||
const ICON_KEYS = ["icon", "icon_url"];
|
||||
|
||||
export default function MediaCategoriesPage() {
|
||||
export default function CategoriesPage() {
|
||||
const [typeFilter, setTypeFilter] = useState<CategoryType>("media");
|
||||
const { data, loading, error, reload } = useList<Category>("/categories", {
|
||||
type: typeFilter,
|
||||
@@ -20,6 +20,14 @@ import { MediaPreview } from "@/components/MediaPreview";
|
||||
import { ImagePicker } from "@/components/ImagePicker";
|
||||
import { pickUrl, SOUND_KEYS, IMAGE_KEYS } from "@/lib/media";
|
||||
|
||||
interface Playlist {
|
||||
id: number;
|
||||
name?: string;
|
||||
// Some endpoints nest the playlist's sub-categories; key casing varies.
|
||||
subcategories?: Playlist[];
|
||||
subCategories?: Playlist[];
|
||||
}
|
||||
|
||||
interface Track {
|
||||
id: number;
|
||||
title?: string;
|
||||
@@ -28,11 +36,12 @@ interface Track {
|
||||
type?: string;
|
||||
playlist_id?: number;
|
||||
image_id?: number | null;
|
||||
}
|
||||
|
||||
interface Playlist {
|
||||
id: number;
|
||||
name?: string;
|
||||
// A track belongs to many playlists; the /music row embeds them as an array.
|
||||
playlists?: Playlist[];
|
||||
// Sub-categories may also be embedded directly on the track (key casing varies).
|
||||
subcategories?: Playlist[];
|
||||
subCategories?: Playlist[];
|
||||
sub_categories?: Playlist[];
|
||||
}
|
||||
|
||||
export default function MusicTracksPage() {
|
||||
@@ -56,6 +65,26 @@ export default function MusicTracksPage() {
|
||||
const [deleting, setDeleting] = useState<Track | null>(null);
|
||||
const [removing, setRemoving] = useState(false);
|
||||
|
||||
// A track belongs to many playlists — list their names.
|
||||
function playlistName(r: Track): string {
|
||||
const names = (r.playlists ?? []).map((p) => p.name).filter(Boolean);
|
||||
return names.length ? (names as string[]).join("، ") : "—";
|
||||
}
|
||||
|
||||
// Sub-categories may sit on the track directly or come through its playlists;
|
||||
// key casing varies between endpoints, so gather from every shape.
|
||||
function subCategoryNames(r: Track): string {
|
||||
const subs: Playlist[] = [
|
||||
...(r.subcategories ?? r.subCategories ?? r.sub_categories ?? []),
|
||||
...(r.playlists ?? []).flatMap(
|
||||
(p) => p.subcategories ?? p.subCategories ?? [],
|
||||
),
|
||||
];
|
||||
const names = subs.map((s) => s.name).filter(Boolean) as string[];
|
||||
const unique = Array.from(new Set(names));
|
||||
return unique.length ? unique.join("، ") : "—";
|
||||
}
|
||||
|
||||
function resetForm() {
|
||||
setTitle("");
|
||||
setArtist("");
|
||||
@@ -163,6 +192,16 @@ export default function MusicTracksPage() {
|
||||
},
|
||||
{ key: "title", header: "عنوان" },
|
||||
{ key: "artist", header: "هنرمند", render: (r) => r.artist ?? "—" },
|
||||
{
|
||||
key: "playlist",
|
||||
header: "پلیلیست",
|
||||
render: (r) => playlistName(r),
|
||||
},
|
||||
{
|
||||
key: "subcategory",
|
||||
header: "زیردسته",
|
||||
render: (r) => subCategoryNames(r),
|
||||
},
|
||||
{
|
||||
key: "duration",
|
||||
header: "مدت زمان",
|
||||
|
||||
@@ -20,9 +20,21 @@ import {
|
||||
import { EditIcon, PlusIcon, TrashIcon } from "@/components/icons";
|
||||
import { toFa } from "@/lib/utils";
|
||||
|
||||
interface SurveyTag {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface SurveyOption {
|
||||
id?: number;
|
||||
label?: string;
|
||||
tags?: SurveyTag[];
|
||||
}
|
||||
|
||||
// Form-side option: tags edited as a comma-separated string.
|
||||
interface OptionDraft {
|
||||
label: string;
|
||||
tags: string;
|
||||
}
|
||||
|
||||
interface SurveyQuestion {
|
||||
@@ -54,7 +66,9 @@ export default function SurveysPage() {
|
||||
const [type, setType] = useState("single");
|
||||
const [order, setOrder] = useState("0");
|
||||
const [isActive, setIsActive] = useState(true);
|
||||
const [options, setOptions] = useState<string[]>([""]);
|
||||
const [options, setOptions] = useState<OptionDraft[]>([
|
||||
{ label: "", tags: "" },
|
||||
]);
|
||||
|
||||
const [deleting, setDeleting] = useState<SurveyQuestion | null>(null);
|
||||
const [removing, setRemoving] = useState(false);
|
||||
@@ -66,7 +80,7 @@ export default function SurveysPage() {
|
||||
setType("single");
|
||||
setOrder("0");
|
||||
setIsActive(true);
|
||||
setOptions([""]);
|
||||
setOptions([{ label: "", tags: "" }]);
|
||||
setOpen(true);
|
||||
}
|
||||
|
||||
@@ -79,17 +93,22 @@ export default function SurveysPage() {
|
||||
setIsActive(row.is_active ?? true);
|
||||
setOptions(
|
||||
row.options && row.options.length
|
||||
? row.options.map((o) => o.label ?? "")
|
||||
: [""],
|
||||
? row.options.map((o) => ({
|
||||
label: o.label ?? "",
|
||||
tags: (o.tags ?? []).map((t) => t.name).join("، "),
|
||||
}))
|
||||
: [{ label: "", tags: "" }],
|
||||
);
|
||||
setOpen(true);
|
||||
}
|
||||
|
||||
function setOptionAt(index: number, value: string) {
|
||||
setOptions((prev) => prev.map((o, i) => (i === index ? value : o)));
|
||||
function setOptionAt(index: number, patch: Partial<OptionDraft>) {
|
||||
setOptions((prev) =>
|
||||
prev.map((o, i) => (i === index ? { ...o, ...patch } : o)),
|
||||
);
|
||||
}
|
||||
function addOption() {
|
||||
setOptions((prev) => [...prev, ""]);
|
||||
setOptions((prev) => [...prev, { label: "", tags: "" }]);
|
||||
}
|
||||
function removeOption(index: number) {
|
||||
setOptions((prev) =>
|
||||
@@ -108,9 +127,15 @@ export default function SurveysPage() {
|
||||
order: Number(order),
|
||||
is_active: isActive,
|
||||
options: options
|
||||
.map((label) => label.trim())
|
||||
.filter((label) => label !== "")
|
||||
.map((label) => ({ label })),
|
||||
.map((o) => ({ label: o.label.trim(), tagsRaw: o.tags }))
|
||||
.filter((o) => o.label !== "")
|
||||
.map((o) => ({
|
||||
label: o.label,
|
||||
tags: o.tagsRaw
|
||||
.split(/[,،]/)
|
||||
.map((t) => t.trim())
|
||||
.filter((t) => t !== ""),
|
||||
})),
|
||||
};
|
||||
if (editing) {
|
||||
await apiFetch(`/survey-questions/${editing.id}`, {
|
||||
@@ -283,12 +308,22 @@ export default function SurveysPage() {
|
||||
</Button>
|
||||
</div>
|
||||
{options.map((opt, i) => (
|
||||
<div key={i} className="flex items-center gap-2">
|
||||
<Input
|
||||
value={opt}
|
||||
onChange={(e) => setOptionAt(i, e.target.value)}
|
||||
placeholder={`گزینه ${toFa(i + 1)}`}
|
||||
/>
|
||||
<div
|
||||
key={i}
|
||||
className="flex items-start gap-2 rounded-lg border border-border p-2"
|
||||
>
|
||||
<div className="flex flex-1 flex-col gap-2">
|
||||
<Input
|
||||
value={opt.label}
|
||||
onChange={(e) => setOptionAt(i, { label: e.target.value })}
|
||||
placeholder={`گزینه ${toFa(i + 1)}`}
|
||||
/>
|
||||
<Input
|
||||
value={opt.tags}
|
||||
onChange={(e) => setOptionAt(i, { tags: e.target.value })}
|
||||
placeholder="برچسبها (با کاما جدا کنید) — برای پیشنهاد محتوا"
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
|
||||
+9
-5
@@ -33,14 +33,18 @@ export const NAV: NavSection[] = [
|
||||
icon: HomeIcon,
|
||||
items: [{ href: "/dashboard", label: "خانه" }],
|
||||
},
|
||||
{
|
||||
label: "عمومی",
|
||||
icon: TagIcon,
|
||||
items: [
|
||||
{ href: "/dashboard/categories", label: "دستهبندیها" },
|
||||
{ href: "/dashboard/sub-categories", label: "زیردستهها" },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "رسانهها",
|
||||
icon: MediaIcon,
|
||||
items: [
|
||||
{ href: "/dashboard/media", label: "فهرست رسانهها" },
|
||||
{ href: "/dashboard/media/categories", label: "دستهبندیها" },
|
||||
{ href: "/dashboard/media/sub-categories", label: "زیردستهها" },
|
||||
],
|
||||
items: [{ href: "/dashboard/media", label: "فهرست رسانهها" }],
|
||||
},
|
||||
{
|
||||
label: "موسیقی",
|
||||
|
||||
Generated
+1
-24
@@ -277,30 +277,6 @@
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@emnapi/core": {
|
||||
"version": "1.10.0",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.10.0.tgz",
|
||||
"integrity": "sha512-yq6OkJ4p82CAfPl0u9mQebQHKPJkY7WrIuk205cTYnYe+k2Z8YBh11FrbRG/H6ihirqcacOgl2BIO8oyMQLeXw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@emnapi/wasi-threads": "1.2.1",
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@emnapi/runtime": {
|
||||
"version": "1.10.0",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.10.0.tgz",
|
||||
"integrity": "sha512-ewvYlk86xUoGI0zQRNq/mC+16R1QeDlKQy21Ki3oSYXNgLb45GV1P6A0M+/s6nyCuNDqe5VpaY84BzXGwVbwFA==",
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@emnapi/wasi-threads": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.1.tgz",
|
||||
@@ -3312,6 +3288,7 @@
|
||||
"integrity": "sha512-whOE1HFo/qJDyX4SnXzP4N6zOWn79WhnCUY/iDR0mPfQZO8wcYE4JClzI2oZrhBnnMUCBCHZhO6VQyoBU95mZA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@rtsao/scc": "^1.1.0",
|
||||
"array-includes": "^3.1.9",
|
||||
|
||||
Regular → Executable
Reference in New Issue
Block a user