Compare commits

..
4 Commits
Author SHA1 Message Date
Amirmahdi 1b2d2dec7d feat: add tags 2026-06-12 14:55:49 +03:30
Amirmahdi e374829358 feat: add playlist 2026-06-11 12:00:39 +03:30
Amirmahdi 7c6d16693c feat: update deploy 2026-06-11 10:59:26 +03:30
Amirmahdi 3cc1d1385c feat: add category 2026-06-11 10:28:19 +03:30
8 changed files with 106 additions and 51 deletions
Regular → Executable
View File
@@ -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). // The icon is a direct image-file field on the category (not an image_id ref).
const ICON_KEYS = ["icon", "icon_url"]; const ICON_KEYS = ["icon", "icon_url"];
export default function MediaCategoriesPage() { export default function CategoriesPage() {
const [typeFilter, setTypeFilter] = useState<CategoryType>("media"); const [typeFilter, setTypeFilter] = useState<CategoryType>("media");
const { data, loading, error, reload } = useList<Category>("/categories", { const { data, loading, error, reload } = useList<Category>("/categories", {
type: typeFilter, type: typeFilter,
+44 -5
View File
@@ -20,6 +20,14 @@ import { MediaPreview } from "@/components/MediaPreview";
import { ImagePicker } from "@/components/ImagePicker"; import { ImagePicker } from "@/components/ImagePicker";
import { pickUrl, SOUND_KEYS, IMAGE_KEYS } from "@/lib/media"; 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 { interface Track {
id: number; id: number;
title?: string; title?: string;
@@ -28,11 +36,12 @@ interface Track {
type?: string; type?: string;
playlist_id?: number; playlist_id?: number;
image_id?: number | null; image_id?: number | null;
} // A track belongs to many playlists; the /music row embeds them as an array.
playlists?: Playlist[];
interface Playlist { // Sub-categories may also be embedded directly on the track (key casing varies).
id: number; subcategories?: Playlist[];
name?: string; subCategories?: Playlist[];
sub_categories?: Playlist[];
} }
export default function MusicTracksPage() { export default function MusicTracksPage() {
@@ -56,6 +65,26 @@ export default function MusicTracksPage() {
const [deleting, setDeleting] = useState<Track | null>(null); const [deleting, setDeleting] = useState<Track | null>(null);
const [removing, setRemoving] = useState(false); 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() { function resetForm() {
setTitle(""); setTitle("");
setArtist(""); setArtist("");
@@ -163,6 +192,16 @@ export default function MusicTracksPage() {
}, },
{ key: "title", header: "عنوان" }, { key: "title", header: "عنوان" },
{ key: "artist", header: "هنرمند", render: (r) => r.artist ?? "—" }, { key: "artist", header: "هنرمند", render: (r) => r.artist ?? "—" },
{
key: "playlist",
header: "پلی‌لیست",
render: (r) => playlistName(r),
},
{
key: "subcategory",
header: "زیر‌دسته",
render: (r) => subCategoryNames(r),
},
{ {
key: "duration", key: "duration",
header: "مدت زمان", header: "مدت زمان",
+51 -16
View File
@@ -20,9 +20,21 @@ import {
import { EditIcon, PlusIcon, TrashIcon } from "@/components/icons"; import { EditIcon, PlusIcon, TrashIcon } from "@/components/icons";
import { toFa } from "@/lib/utils"; import { toFa } from "@/lib/utils";
interface SurveyTag {
id: number;
name: string;
}
interface SurveyOption { interface SurveyOption {
id?: number; id?: number;
label?: string; label?: string;
tags?: SurveyTag[];
}
// Form-side option: tags edited as a comma-separated string.
interface OptionDraft {
label: string;
tags: string;
} }
interface SurveyQuestion { interface SurveyQuestion {
@@ -54,7 +66,9 @@ export default function SurveysPage() {
const [type, setType] = useState("single"); const [type, setType] = useState("single");
const [order, setOrder] = useState("0"); const [order, setOrder] = useState("0");
const [isActive, setIsActive] = useState(true); 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 [deleting, setDeleting] = useState<SurveyQuestion | null>(null);
const [removing, setRemoving] = useState(false); const [removing, setRemoving] = useState(false);
@@ -66,7 +80,7 @@ export default function SurveysPage() {
setType("single"); setType("single");
setOrder("0"); setOrder("0");
setIsActive(true); setIsActive(true);
setOptions([""]); setOptions([{ label: "", tags: "" }]);
setOpen(true); setOpen(true);
} }
@@ -79,17 +93,22 @@ export default function SurveysPage() {
setIsActive(row.is_active ?? true); setIsActive(row.is_active ?? true);
setOptions( setOptions(
row.options && row.options.length 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); setOpen(true);
} }
function setOptionAt(index: number, value: string) { function setOptionAt(index: number, patch: Partial<OptionDraft>) {
setOptions((prev) => prev.map((o, i) => (i === index ? value : o))); setOptions((prev) =>
prev.map((o, i) => (i === index ? { ...o, ...patch } : o)),
);
} }
function addOption() { function addOption() {
setOptions((prev) => [...prev, ""]); setOptions((prev) => [...prev, { label: "", tags: "" }]);
} }
function removeOption(index: number) { function removeOption(index: number) {
setOptions((prev) => setOptions((prev) =>
@@ -108,9 +127,15 @@ export default function SurveysPage() {
order: Number(order), order: Number(order),
is_active: isActive, is_active: isActive,
options: options options: options
.map((label) => label.trim()) .map((o) => ({ label: o.label.trim(), tagsRaw: o.tags }))
.filter((label) => label !== "") .filter((o) => o.label !== "")
.map((label) => ({ label })), .map((o) => ({
label: o.label,
tags: o.tagsRaw
.split(/[,،]/)
.map((t) => t.trim())
.filter((t) => t !== ""),
})),
}; };
if (editing) { if (editing) {
await apiFetch(`/survey-questions/${editing.id}`, { await apiFetch(`/survey-questions/${editing.id}`, {
@@ -283,12 +308,22 @@ export default function SurveysPage() {
</Button> </Button>
</div> </div>
{options.map((opt, i) => ( {options.map((opt, i) => (
<div key={i} className="flex items-center gap-2"> <div
<Input key={i}
value={opt} className="flex items-start gap-2 rounded-lg border border-border p-2"
onChange={(e) => setOptionAt(i, e.target.value)} >
placeholder={`گزینه ${toFa(i + 1)}`} <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 <Button
type="button" type="button"
variant="ghost" variant="ghost"
+9 -5
View File
@@ -33,14 +33,18 @@ export const NAV: NavSection[] = [
icon: HomeIcon, icon: HomeIcon,
items: [{ href: "/dashboard", label: "خانه" }], items: [{ href: "/dashboard", label: "خانه" }],
}, },
{
label: "عمومی",
icon: TagIcon,
items: [
{ href: "/dashboard/categories", label: "دسته‌بندی‌ها" },
{ href: "/dashboard/sub-categories", label: "زیر‌دسته‌ها" },
],
},
{ {
label: "رسانه‌ها", label: "رسانه‌ها",
icon: MediaIcon, icon: MediaIcon,
items: [ items: [{ href: "/dashboard/media", label: "فهرست رسانه‌ها" }],
{ href: "/dashboard/media", label: "فهرست رسانه‌ها" },
{ href: "/dashboard/media/categories", label: "دسته‌بندی‌ها" },
{ href: "/dashboard/media/sub-categories", label: "زیر‌دسته‌ها" },
],
}, },
{ {
label: "موسیقی", label: "موسیقی",
+1 -24
View File
@@ -277,30 +277,6 @@
"node": ">=6.9.0" "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": { "node_modules/@emnapi/wasi-threads": {
"version": "1.2.1", "version": "1.2.1",
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.1.tgz", "resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.1.tgz",
@@ -3312,6 +3288,7 @@
"integrity": "sha512-whOE1HFo/qJDyX4SnXzP4N6zOWn79WhnCUY/iDR0mPfQZO8wcYE4JClzI2oZrhBnnMUCBCHZhO6VQyoBU95mZA==", "integrity": "sha512-whOE1HFo/qJDyX4SnXzP4N6zOWn79WhnCUY/iDR0mPfQZO8wcYE4JClzI2oZrhBnnMUCBCHZhO6VQyoBU95mZA==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"peer": true,
"dependencies": { "dependencies": {
"@rtsao/scc": "^1.1.0", "@rtsao/scc": "^1.1.0",
"array-includes": "^3.1.9", "array-includes": "^3.1.9",
Regular → Executable
View File