'feat:暗色模式样式修改'
This commit is contained in:
1 parent
ee8e2b3225
commit
372d4f7933
23 files changed
+594
-269
No files matched your search
@@ -2,6 +2,8 @@
|
||||
|
||||
import { useState } from "react";
|
||||
import {
|
||||
AlertCircle,
|
||||
CheckCircle2,
|
||||
GripVerticalIcon,
|
||||
Loader2Icon,
|
||||
PencilIcon,
|
||||
@@ -11,6 +13,7 @@ import {
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useTheme } from "@/contexts/ThemeContext";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
@@ -34,7 +37,30 @@ type DialogState =
|
||||
| { mode: "edit"; question: RecommendedQuestion }
|
||||
| null;
|
||||
|
||||
/** 成功 toast:仅暗色模式,浅色走 Sonner 默认 */
|
||||
const successToastDarkOptions = {
|
||||
classNames: {
|
||||
toast:
|
||||
"!rounded-[2px] !border !border-[#106455] !bg-[#052934] !text-[#FFFFFF] shadow-md",
|
||||
title: "!text-[#FFFFFF]",
|
||||
description: "!text-[#FFFFFF]",
|
||||
},
|
||||
icon: <CheckCircle2 className="size-4 shrink-0 text-[#2FD69A]" />,
|
||||
} as const;
|
||||
|
||||
/** 失败 toast:仅暗色模式,浅色走 Sonner 默认 */
|
||||
const errorToastDarkOptions = {
|
||||
classNames: {
|
||||
toast:
|
||||
"!rounded-[2px] !border !border-[#7F1A2A] !bg-[#311629] !text-[#FFFFFF] shadow-md",
|
||||
title: "!text-[#FFFFFF]",
|
||||
description: "!text-[#FFFFFF]",
|
||||
},
|
||||
icon: <AlertCircle className="size-4 shrink-0 text-[#F5222D]" />,
|
||||
} as const;
|
||||
|
||||
export default function RecommendedQuestionsPage() {
|
||||
const { theme } = useTheme();
|
||||
const { questions, isLoading, error } = useRecommendedQuestions();
|
||||
const createMutation = useCreateRecommendedQuestion();
|
||||
const updateMutation = useUpdateRecommendedQuestion();
|
||||
@@ -70,7 +96,7 @@ export default function RecommendedQuestionsPage() {
|
||||
const title = formTitle.trim();
|
||||
const content = formContent.trim();
|
||||
if (!title || !content) {
|
||||
toast.error("标题和内容不能为空");
|
||||
toast.error("标题和内容不能为空", darkToastOpts.error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -81,17 +107,20 @@ export default function RecommendedQuestionsPage() {
|
||||
content,
|
||||
sort_order: questions.length,
|
||||
});
|
||||
toast.success("问题已添加");
|
||||
toast.success("问题已添加", darkToastOpts.success);
|
||||
} else if (dialog?.mode === "edit") {
|
||||
await updateMutation.mutateAsync({
|
||||
id: dialog.question.id,
|
||||
body: { title, content },
|
||||
});
|
||||
toast.success("问题已更新");
|
||||
toast.success("问题已更新", darkToastOpts.success);
|
||||
}
|
||||
closeDialog();
|
||||
} catch (e) {
|
||||
toast.error(e instanceof Error ? e.message : "操作失败");
|
||||
toast.error(
|
||||
e instanceof Error ? e.message : "操作失败",
|
||||
darkToastOpts.error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,9 +128,12 @@ export default function RecommendedQuestionsPage() {
|
||||
try {
|
||||
await deleteMutation.mutateAsync(q.id);
|
||||
setDeleteTarget(null);
|
||||
toast.success("问题已删除");
|
||||
toast.success("问题已删除", darkToastOpts.success);
|
||||
} catch (e) {
|
||||
toast.error(e instanceof Error ? e.message : "删除失败");
|
||||
toast.error(
|
||||
e instanceof Error ? e.message : "删除失败",
|
||||
darkToastOpts.error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +160,7 @@ export default function RecommendedQuestionsPage() {
|
||||
try {
|
||||
await reorderMutation.mutateAsync(next.map((q) => q.id));
|
||||
} catch {
|
||||
toast.error("排序保存失败");
|
||||
toast.error("排序保存失败", darkToastOpts.error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,6 +170,11 @@ export default function RecommendedQuestionsPage() {
|
||||
deleteMutation.isPending ||
|
||||
reorderMutation.isPending;
|
||||
|
||||
const darkToastOpts =
|
||||
theme === "dark"
|
||||
? { success: successToastDarkOptions, error: errorToastDarkOptions }
|
||||
: { success: undefined, error: undefined };
|
||||
|
||||
return (
|
||||
<div className="mx-auto flex w-full max-w-2xl flex-col gap-6 px-6 py-10">
|
||||
<div className="flex items-center justify-between">
|
||||
@@ -162,15 +199,15 @@ export default function RecommendedQuestionsPage() {
|
||||
<p>加载失败:{error.message}</p>
|
||||
</div>
|
||||
) : questions.length === 0 ? (
|
||||
<div className="text-muted-foreground flex flex-col items-center gap-3 rounded-xl border border-dashed py-16 text-sm">
|
||||
<div className="text-muted-foreground flex flex-col items-center gap-3 rounded-xl border border-dashed py-16 text-sm dark:text-[#7FACF2] dark:!border-[#213F62]">
|
||||
<p>暂无推荐问题</p>
|
||||
<Button variant="outline" size="sm" onClick={openAdd}>
|
||||
<Button size="sm" onClick={openAdd}>
|
||||
<PlusIcon className="mr-1.5 size-4" />
|
||||
添加第一个问题
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex flex-col gap-2 ">
|
||||
{questions.map((q, index) => (
|
||||
<div
|
||||
key={q.id}
|
||||
@@ -182,18 +219,18 @@ export default function RecommendedQuestionsPage() {
|
||||
setDragIndex(null);
|
||||
setDragOverIndex(null);
|
||||
}}
|
||||
className={`flex items-start gap-3 rounded-xl border bg-white px-4 py-3.5 transition-colors ${
|
||||
className={`flex items-start gap-3 rounded-xl border bg-white px-4 py-3.5 transition-colors dark:bg-[#022248] dark:!border-[#213D5E] ${
|
||||
dragOverIndex === index && dragIndex !== index
|
||||
? "border-blue-400 bg-blue-50"
|
||||
? "border-blue-400 bg-blue-50 dark:border-[#2580FF] dark:bg-[#0D2D54]"
|
||||
: "border-[#e4e4e7]"
|
||||
}`}
|
||||
>
|
||||
<GripVerticalIcon className="text-muted-foreground/40 mt-0.5 size-4 shrink-0 cursor-grab active:cursor-grabbing" />
|
||||
<GripVerticalIcon className="text-muted-foreground/40 mt-0.5 size-4 shrink-0 cursor-grab active:cursor-grabbing dark:text-[#566B7F]" />
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="truncate text-sm font-medium text-[#18181b]">
|
||||
<div className="truncate text-sm font-medium text-[#18181b] dark:text-white">
|
||||
{q.title}
|
||||
</div>
|
||||
<div className="text-muted-foreground mt-0.5 line-clamp-2 text-xs">
|
||||
<div className="text-muted-foreground mt-0.5 line-clamp-2 text-xs dark:text-[#7FACF2]">
|
||||
{q.content}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user