Bläddra i källkod

feat(dashboard-v6): 工作台「最近访问」跳转时还原记录时的 channel 与 mode

recent.param(记录时的查询参数 JSON)还原成 ?channel=...&mode=...;book / para 已在路径里,
v4 写入的 mode=reading 不是 v6 的取值,丢掉走默认。RecentList 的 onClick 改为传整条记录。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
visuddhinanda 6 timmar sedan
förälder
incheckning
c379624ed9

+ 3 - 0
dashboard-v6/src/api/workspace.ts

@@ -30,6 +30,8 @@ export type RecentItem = {
   time: string;
   type: ArticleType;
   emoji: string;
+  /** 记录时 URL 的查询参数(JSON 字符串),跳转时还原成 ?channel=... */
+  param: string | null;
 };
 
 // 静态配置写在前端
@@ -97,5 +99,6 @@ export async function fetchRecentItems(userId: string): Promise<RecentItem[]> {
     time: item.updated_at,
     type: item.type,
     emoji: "📜",
+    param: item.param,
   }));
 }

+ 2 - 3
dashboard-v6/src/components/workspace/home/RecentList.tsx

@@ -2,11 +2,10 @@ import type { CSSProperties } from "react";
 import { theme } from "antd";
 import type { RecentItem as RecentItemType } from "../../../api/workspace";
 import RecentItem from "./RecentItem";
-import type { ArticleType } from "../../../api/article";
 
 type RecentListProps = {
   items: RecentItemType[];
-  onClick?: (type: ArticleType, id: string) => void;
+  onClick?: (item: RecentItemType) => void;
 };
 
 export default function RecentList({ items, onClick }: RecentListProps) {
@@ -28,7 +27,7 @@ export default function RecentList({ items, onClick }: RecentListProps) {
           key={item.id}
           {...item}
           onClick={() => {
-            onClick?.(item.type, item.id);
+            onClick?.(item);
           }}
         />
       ))}

+ 33 - 2
dashboard-v6/src/pages/workspace/home.tsx

@@ -10,6 +10,7 @@ import type { ModuleItem, RecentItem } from "../../api/workspace";
 import { useAppSelector } from "../../hooks";
 import { currentUser } from "../../reducers/current-user";
 import { useNavigate } from "react-router";
+import type { ArticleMode } from "../../api/article";
 
 export default function WorkspaceHome() {
   const [modules, setModules] = useState<ModuleItem[]>([]);
@@ -39,9 +40,12 @@ export default function WorkspaceHome() {
         <SectionPanel title="最近访问">
           <RecentList
             items={recentItems}
-            onClick={(type, id) => {
+            onClick={(item) => {
+              const { type, id } = item;
               if (type === "chapter" || type === "para" || type === "cs-para") {
-                navigate(`/workspace/tipitaka/${type}/${id}`);
+                navigate(
+                  `/workspace/tipitaka/${type}/${id}${recentSearch(item.param)}`,
+                );
               }
             }}
           />
@@ -51,6 +55,33 @@ export default function WorkspaceHome() {
   );
 }
 
+const ARTICLE_MODES: ArticleMode[] = ["read", "edit", "wbw", "auto"];
+
+/**
+ * 把 recent.param(记录时的查询参数 JSON)还原成 `?channel=...&mode=...`。
+ * 只还原 channel 与 mode:book/para 已在路径里;v4 写入的 mode=reading 不是
+ * v6 的取值,丢掉走默认。
+ */
+function recentSearch(param: string | null): string {
+  if (!param) return "";
+  let obj: Record<string, unknown>;
+  try {
+    obj = JSON.parse(param);
+  } catch {
+    return "";
+  }
+  if (!obj || typeof obj !== "object") return "";
+  const query = new URLSearchParams();
+  if (typeof obj.channel === "string" && obj.channel) {
+    query.set("channel", obj.channel);
+  }
+  if (ARTICLE_MODES.includes(obj.mode as ArticleMode)) {
+    query.set("mode", obj.mode as string);
+  }
+  const q = query.toString();
+  return q ? `?${q}` : "";
+}
+
 const styles: Record<string, CSSProperties> = {
   page: {
     minHeight: "100vh",