Compare commits

...
3 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
4 changed files with 95 additions and 21 deletions
Regular → Executable
View File
+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"
Regular → Executable
View File