feat: add chat topic
This commit is contained in:
@@ -20,10 +20,17 @@ import { toFa } from "@/lib/utils";
|
||||
interface Question {
|
||||
id: number;
|
||||
title?: string;
|
||||
category?: string;
|
||||
// Submitted as a string (name); returned by the API as a related object.
|
||||
category?: { id?: number; name?: string } | string | null;
|
||||
tags?: string[] | string;
|
||||
}
|
||||
|
||||
function categoryName(c: Question["category"]): string {
|
||||
if (!c) return "";
|
||||
if (typeof c === "string") return c;
|
||||
return c.name ?? "";
|
||||
}
|
||||
|
||||
function asTags(value: Question["tags"]): string[] {
|
||||
if (Array.isArray(value)) return value.map((t) => String(t));
|
||||
if (typeof value === "string" && value.trim() !== "") {
|
||||
@@ -73,7 +80,7 @@ export default function QuestionsPage() {
|
||||
function openEdit(row: Question) {
|
||||
setEditing(row);
|
||||
setTitle(row.title ?? "");
|
||||
setCategory(row.category ?? "");
|
||||
setCategory(categoryName(row.category));
|
||||
setTagsInput(asTags(row.tags).join("، "));
|
||||
setOpen(true);
|
||||
}
|
||||
@@ -125,7 +132,7 @@ export default function QuestionsPage() {
|
||||
const columns: Column<Question>[] = [
|
||||
{ key: "id", header: "شناسه", render: (r) => toFa(r.id), className: "w-20" },
|
||||
{ key: "title", header: "عنوان", render: (r) => r.title ?? "—" },
|
||||
{ key: "category", header: "دسته", render: (r) => r.category ?? "—" },
|
||||
{ key: "category", header: "دسته", render: (r) => categoryName(r.category) || "—" },
|
||||
{
|
||||
key: "tags",
|
||||
header: "برچسبها",
|
||||
|
||||
Reference in New Issue
Block a user