Ver Fonte

Merge pull request #2500 from visuddhinanda/development

Development
visuddhinanda há 5 dias atrás
pai
commit
ceac6a0831

+ 12 - 23
api-test/cases/10_tipitaka_chapter_channels.php

@@ -5,25 +5,18 @@ use \WikipaliApi\Api\TipitakaChapterChannelsApi;
 /*
 /*
  * 一章有哪些 channel 及完成度:GET /v3/tipitaka-chapter-channels/{book}/{para}
  * 一章有哪些 channel 及完成度:GET /v3/tipitaka-chapter-channels/{book}/{para}
  *
  *
- * 只读、无写操作。章节坐标从 fixture channel 自己的进度里取(各服务器数据不同),
- * 再核对这一章的列表里有它。fixture channel 是公开的,匿名就看得到。
+ * 只读、无写操作。章节坐标取 fixtures.php 的 chapter_channels_book / chapter_channels_para
+ * (与 server 无关),核对这一章能匿名列出版本、行的形状与排序对。
  * 可见性矩阵(私有 / 共享 / 群组)、排序、N+1 由 api-v13 的 TipitakaChapterChannelV3Test 覆盖。
  * 可见性矩阵(私有 / 共享 / 群组)、排序、N+1 由 api-v13 的 TipitakaChapterChannelV3Test 覆盖。
  */
  */
 
 
-/** fixture channel 有进度的某一章的 [book, para] */
+/** 有若干译文版本的某一章的 [book, para] */
 function chapter_channel_coord(): array
 function chapter_channel_coord(): array
 {
 {
-    $res = raw('GET', '/v3/progress', ['channels' => fixtures()['channel'], 'per_page' => 1]);
-    assert_status(200, $res, '取 fixture channel 的章节进度');
-    $row = $res['body']['data'][0] ?? null;
-    if (! $row) {
-        skip('fixture channel 在这台服务器上没有章节进度');
-    }
-
-    return [(int) $row['book'], (int) $row['para']];
+    return [(int) fixtures()['chapter_channels_book'], (int) fixtures()['chapter_channels_para']];
 }
 }
 
 
-test('GET /v3/tipitaka-chapter-channels/{book}/{para} → 200,含 fixture channel', function () {
+test('GET /v3/tipitaka-chapter-channels/{book}/{para} → 200,列出版本', function () {
     [$book, $para] = chapter_channel_coord();
     [$book, $para] = chapter_channel_coord();
     $res = request(fn () => api(TipitakaChapterChannelsApi::class)
     $res = request(fn () => api(TipitakaChapterChannelsApi::class)
         ->getApiV3TipitakaChapterChannelsBookParaWithHttpInfo($book, $para, 200));
         ->getApiV3TipitakaChapterChannelsBookParaWithHttpInfo($book, $para, 200));
@@ -31,20 +24,16 @@ test('GET /v3/tipitaka-chapter-channels/{book}/{para} → 200,含 fixture chan
     assert_has_key('data', $res['body'], 'tipitaka-chapter-channels');
     assert_has_key('data', $res['body'], 'tipitaka-chapter-channels');
     assert_has_key('meta', $res['body'], 'tipitaka-chapter-channels');
     assert_has_key('meta', $res['body'], 'tipitaka-chapter-channels');
 
 
-    $hit = null;
+    if ($res['body']['data'] === []) {
+        fail('tipitaka-chapter-channels:应返回至少一个版本');
+    }
     foreach ($res['body']['data'] as $row) {
     foreach ($res['body']['data'] as $row) {
-        if (($row['channel']['id'] ?? null) === fixtures()['channel']) {
-            $hit = $row;
+        assert_eq($book, $row['book'] ?? null, 'book');
+        assert_eq($para, $row['para'] ?? null, 'para');
+        foreach (['id', 'progress', 'views', 'updated_at', 'channel', 'studio'] as $key) {
+            assert_has_key($key, $row, 'tipitaka-chapter-channels 行');
         }
         }
     }
     }
-    if (! $hit) {
-        fail('tipitaka-chapter-channels:应包含 fixture channel');
-    }
-    assert_eq($book, $hit['book'] ?? null, 'book');
-    assert_eq($para, $hit['para'] ?? null, 'para');
-    foreach (['id', 'progress', 'views', 'updated_at', 'studio'] as $key) {
-        assert_has_key($key, $hit, 'tipitaka-chapter-channels 行');
-    }
 
 
     // 按完成度降序
     // 按完成度降序
     $progress = array_column($res['body']['data'], 'progress');
     $progress = array_column($res['body']['data'], 'progress');

+ 4 - 0
api-test/fixtures.php

@@ -12,6 +12,10 @@ return [
     // 一个 translation 类型、有翻译进度与译文数据的 channel
     // 一个 translation 类型、有翻译进度与译文数据的 channel
     'channel' => '4414c96e-4903-11ef-af72-571c3fee08e6',
     'channel' => '4414c96e-4903-11ef-af72-571c3fee08e6',
 
 
+    // tipitaka-chapter-channels 用的章节坐标:一章有若干译文版本即可,与 server 无关
+    'chapter_channels_book' => 93,
+    'chapter_channels_para' => 5,
+
     // reactions / reactions/tally 用的 target(collection)
     // reactions / reactions/tally 用的 target(collection)
     'target_id' => '5b4511c1-c99f-47e7-9798-97b9e5229e18',
     'target_id' => '5b4511c1-c99f-47e7-9798-97b9e5229e18',
 
 

+ 2 - 1
dashboard-v6/src/api/pali-text.ts

@@ -172,7 +172,8 @@ export interface IParagraphNode {
   para: number;
   para: number;
   mode?: ArticleMode;
   mode?: ArticleMode;
   channels?: string[];
   channels?: string[];
-  sentenceIds: string[];
+  /** 段落内的句子坐标 [book, para, wordStart, wordEnd] */
+  sentences: [number, number, number, number][];
   children?: IWidgetSentEditInner[];
   children?: IWidgetSentEditInner[];
 }
 }
 
 

+ 2 - 0
dashboard-v6/src/components/editor/Editor.tsx

@@ -18,6 +18,7 @@ import type { IChannel } from "../../api/channel";
 import { useAppSelector } from "../../hooks";
 import { useAppSelector } from "../../hooks";
 import { openPanel, rightPanel } from "../../reducers/right-panel";
 import { openPanel, rightPanel } from "../../reducers/right-panel";
 import store from "../../store";
 import store from "../../store";
+import { WORKSPACE_STICKY_TOP } from "../../layouts/workspace/constants";
 
 
 /**
 /**
  * redux openPanel 面板名 → 右边栏 tab key。
  * redux openPanel 面板名 → 右边栏 tab key。
@@ -174,6 +175,7 @@ export default function Editor({
       sidebar={sidebar}
       sidebar={sidebar}
       rightTabs={rightTabs}
       rightTabs={rightTabs}
       openRequest={openRequest}
       openRequest={openRequest}
+      stickyTop={WORKSPACE_STICKY_TOP}
     >
     >
       {({ expandButton }) => children({ expandButton })}
       {({ expandButton }) => children({ expandButton })}
     </SplitLayout>
     </SplitLayout>

+ 4 - 3
dashboard-v6/src/components/general/SplitLayout/RightToolbar.module.css

@@ -7,7 +7,8 @@
 .container {
 .container {
   display: flex;
   display: flex;
   flex-direction: row;
   flex-direction: row;
-  height: 100vh;
+  /* 吸顶时让出外层顶部工具栏的高度(由 RightToolbar 的 stickyTop 设置) */
+  height: calc(100vh - var(--right-toolbar-top, 0px));
   overflow: hidden;
   overflow: hidden;
 }
 }
 
 
@@ -53,7 +54,7 @@
 .panelBody {
 .panelBody {
   overflow-y: scroll;
   overflow-y: scroll;
   overflow-x: hidden;
   overflow-x: hidden;
-  height: calc(100vh - 40px);
+  height: calc(100vh - var(--right-toolbar-top, 0px) - 40px);
   /* display:contents 的子项可直接撑满 */
   /* display:contents 的子项可直接撑满 */
   display: flex;
   display: flex;
   flex-direction: column;
   flex-direction: column;
@@ -61,7 +62,7 @@
 
 
 /* 面板自带顶栏(hideHeader)时占满整个高度 */
 /* 面板自带顶栏(hideHeader)时占满整个高度 */
 .panelBodyFull {
 .panelBodyFull {
-  height: 100vh;
+  height: calc(100vh - var(--right-toolbar-top, 0px));
 }
 }
 
 
 /* ── 纵向图标工具栏 ── */
 /* ── 纵向图标工具栏 ── */

+ 7 - 1
dashboard-v6/src/components/general/SplitLayout/RightToolbar.tsx

@@ -29,6 +29,8 @@ interface RightToolbarProps {
   activeKey: string | null;
   activeKey: string | null;
   onTabClick: (key: string) => void;
   onTabClick: (key: string) => void;
   onClose: () => void;
   onClose: () => void;
+  /** 吸顶时距视口顶部的距离(px),面板高度相应减去它 */
+  stickyTop?: number;
 }
 }
 
 
 export default function RightToolbar({
 export default function RightToolbar({
@@ -36,6 +38,7 @@ export default function RightToolbar({
   activeKey,
   activeKey,
   onTabClick,
   onTabClick,
   onClose,
   onClose,
+  stickyTop = 0,
 }: RightToolbarProps) {
 }: RightToolbarProps) {
   // 记录哪些 tab 曾经被打开过(懒创建:首次点击后才挂载 DOM)
   // 记录哪些 tab 曾经被打开过(懒创建:首次点击后才挂载 DOM)
   // 使用模块级 WeakMap 不行,用组件内 Set ref 也可以,
   // 使用模块级 WeakMap 不行,用组件内 Set ref 也可以,
@@ -56,7 +59,10 @@ export default function RightToolbar({
   const panelOpen = activeKey !== null && !!activeTab?.content;
   const panelOpen = activeKey !== null && !!activeTab?.content;
 
 
   return (
   return (
-    <div className={styles.container}>
+    <div
+      className={styles.container}
+      style={{ "--right-toolbar-top": `${stickyTop}px` } as React.CSSProperties}
+    >
       {/* ── 面板内容区 ── */}
       {/* ── 面板内容区 ── */}
       {panelOpen && (
       {panelOpen && (
         <div className={styles.panel}>
         <div className={styles.panel}>

+ 9 - 1
dashboard-v6/src/components/general/SplitLayout/SplitLayout.tsx

@@ -84,6 +84,12 @@ export interface SplitLayoutProps {
    * 传 0 或负数表示不限制(占满可用宽度)。
    * 传 0 或负数表示不限制(占满可用宽度)。
    */
    */
   contentMaxWidth?: number;
   contentMaxWidth?: number;
+
+  /**
+   * 右边栏吸顶时距视口顶部的距离(px),默认 0。
+   * 外层布局有吸顶的顶部工具栏时传它的高度,右边栏停在工具栏下面。
+   */
+  stickyTop?: number;
 }
 }
 
 
 // ─────────────────────────────────────────────
 // ─────────────────────────────────────────────
@@ -100,6 +106,7 @@ export default function SplitLayout({
   minRightSize = 280,
   minRightSize = 280,
   maxRightSize = 800,
   maxRightSize = 800,
   contentMaxWidth = 1000,
   contentMaxWidth = 1000,
+  stickyTop = 0,
 }: SplitLayoutProps) {
 }: SplitLayoutProps) {
   // ── 左侧收起状态(持久化)──
   // ── 左侧收起状态(持久化)──
   const [collapsed, setCollapsed] = useState<boolean>(() => {
   const [collapsed, setCollapsed] = useState<boolean>(() => {
@@ -270,8 +277,9 @@ export default function SplitLayout({
                 resizable={rightOpen}
                 resizable={rightOpen}
                 className={styles.rightAreaPanel}
                 className={styles.rightAreaPanel}
               >
               >
-                <Affix offsetTop={0}>
+                <Affix offsetTop={stickyTop}>
                   <RightToolbar
                   <RightToolbar
+                    stickyTop={stickyTop}
                     tabs={rightTabs!}
                     tabs={rightTabs!}
                     activeKey={rightActiveKey}
                     activeKey={rightActiveKey}
                     onTabClick={onRightTabClick}
                     onTabClick={onRightTabClick}

+ 8 - 8
dashboard-v6/src/components/sentence/SentCart.tsx

@@ -23,10 +23,12 @@ const SentCartWidget = () => {
   // Derive count directly — no need for a separate state
   // Derive count directly — no need for a separate state
   const count = sentences.length || undefined;
   const count = sentences.length || undefined;
 
 
-  // Sync sentences → localStorage whenever it changes
-  useEffect(() => {
-    localStorage.setItem("cart/text", JSON.stringify(sentences));
-  }, [sentences]);
+  // 只在用户清空 / 删除时写回 localStorage。不能用「sentences 变了就写」的 effect:
+  // 挂载时它先于下面的读取执行,会用初始的空数组把购物车覆盖掉(刷新即清空)
+  const save = (next: ISentCart[]) => {
+    localStorage.setItem("cart/text", JSON.stringify(next));
+    setSentences(next);
+  };
 
 
   // Poll localStorage for external changes (e.g. another tab / component)
   // Poll localStorage for external changes (e.g. another tab / component)
   useEffect(() => {
   useEffect(() => {
@@ -68,7 +70,7 @@ const SentCartWidget = () => {
                     type="link"
                     type="link"
                     danger
                     danger
                     icon={<DeleteOutlined />}
                     icon={<DeleteOutlined />}
-                    onClick={() => setSentences([])}
+                    onClick={() => save([])}
                   />
                   />
                 </Tooltip>
                 </Tooltip>
               </div>
               </div>
@@ -86,9 +88,7 @@ const SentCartWidget = () => {
                       danger
                       danger
                       icon={<DeleteOutlined />}
                       icon={<DeleteOutlined />}
                       onClick={() => {
                       onClick={() => {
-                        setSentences((prev) =>
-                          prev.filter((_, i) => i !== index)
-                        );
+                        save(sentences.filter((_, i) => i !== index));
                       }}
                       }}
                     />
                     />
                   </List.Item>
                   </List.Item>

+ 6 - 1
dashboard-v6/src/components/tipitaka/components/Paragraph.tsx

@@ -22,7 +22,7 @@ const Paragraph = ({
   para,
   para,
   mode,
   mode,
   channels,
   channels,
-  sentenceIds,
+  sentences,
   children,
   children,
   loading,
   loading,
   onModeChange,
   onModeChange,
@@ -53,6 +53,11 @@ const Paragraph = ({
     }
     }
   }, [book, focus, para]);
   }, [book, focus, para]);
 
 
+  const sentenceIds = useMemo(
+    () => (sentences ?? []).map((item) => item.join("-")),
+    [sentences]
+  );
+
   const borderColor = isFocus ? "#e35f00bd " : "rgba(128, 128, 128, 0.3)";
   const borderColor = isFocus ? "#e35f00bd " : "rgba(128, 128, 128, 0.3)";
 
 
   const border = mode === "read" ? "" : "2px solid " + borderColor;
   const border = mode === "read" ? "" : "2px solid " + borderColor;

+ 12 - 0
dashboard-v6/src/layouts/workspace/constants.ts

@@ -0,0 +1,12 @@
+/** 工作区顶部工具栏高度(px) */
+export const WORKSPACE_HEADER_HEIGHT = 56;
+
+/** 工作区内容区(Content)的内边距(px) */
+export const WORKSPACE_CONTENT_PADDING = 12;
+
+/**
+ * 内容区顶部到视口顶部的距离(px):工具栏 + 内容区上内边距。
+ * 吸顶元素(如右边栏)用它做偏移,吸顶位置与初始位置一致,滚动时不会跳动。
+ */
+export const WORKSPACE_STICKY_TOP =
+  WORKSPACE_HEADER_HEIGHT + WORKSPACE_CONTENT_PADDING;

+ 45 - 8
dashboard-v6/src/layouts/workspace/index.tsx

@@ -1,6 +1,6 @@
-import { Button, Layout, Space } from "antd";
+import { Button, Layout, Space, theme } from "antd";
 import { Navigate, Outlet } from "react-router";
 import { Navigate, Outlet } from "react-router";
-import { useState } from "react";
+import { useCallback, useState } from "react";
 import { MenuFoldOutlined, MenuUnfoldOutlined } from "@ant-design/icons";
 import { MenuFoldOutlined, MenuUnfoldOutlined } from "@ant-design/icons";
 import MainMenu from "../../components/navigation/MainMenu";
 import MainMenu from "../../components/navigation/MainMenu";
 import SignInAvatar from "../../components/auth/SignInAvatar";
 import SignInAvatar from "../../components/auth/SignInAvatar";
@@ -13,10 +13,36 @@ import SentCart from "../../components/sentence/SentCart";
 import NotificationIcon from "../../components/notification/NotificationIcon";
 import NotificationIcon from "../../components/notification/NotificationIcon";
 import TeamspaceBadge from "../../features/teamspace/TeamspaceBadge";
 import TeamspaceBadge from "../../features/teamspace/TeamspaceBadge";
 import TeamspaceGuard from "../../features/teamspace/TeamspaceGuard";
 import TeamspaceGuard from "../../features/teamspace/TeamspaceGuard";
+import {
+  WORKSPACE_CONTENT_PADDING,
+  WORKSPACE_HEADER_HEIGHT,
+} from "./constants";
 
 
 const { Sider, Content } = Layout;
 const { Sider, Content } = Layout;
+
+/** 主导航折叠状态的 localStorage 键 */
+const COLLAPSED_KEY = "workspace:main-menu-collapsed";
+
 const Widget = () => {
 const Widget = () => {
-  const [collapsed, setCollapsed] = useState(false);
+  const [collapsed, setCollapsed] = useState<boolean>(() => {
+    try {
+      return localStorage.getItem(COLLAPSED_KEY) === "true";
+    } catch {
+      return false;
+    }
+  });
+  const toggleCollapsed = useCallback(() => {
+    setCollapsed((v) => {
+      const next = !v;
+      try {
+        localStorage.setItem(COLLAPSED_KEY, String(next));
+      } catch {
+        /* 静默降级 */
+      }
+      return next;
+    });
+  }, []);
+  const { token } = theme.useToken();
   const { isAuthenticated } = useAuth();
   const { isAuthenticated } = useAuth();
 
 
   if (!isAuthenticated) {
   if (!isAuthenticated) {
@@ -26,7 +52,13 @@ const Widget = () => {
   return (
   return (
     <Layout style={{ minHeight: "100vh" }}>
     <Layout style={{ minHeight: "100vh" }}>
       <Sider
       <Sider
-        style={{ backgroundColor: "unset" }}
+        style={{
+          backgroundColor: "unset",
+          position: "sticky",
+          top: 0,
+          height: "100vh",
+          overflowY: "auto",
+        }}
         trigger={null}
         trigger={null}
         collapsible
         collapsible
         collapsed={collapsed}
         collapsed={collapsed}
@@ -42,7 +74,7 @@ const Widget = () => {
           <Button
           <Button
             type="text"
             type="text"
             icon={collapsed ? <MenuUnfoldOutlined /> : <MenuFoldOutlined />}
             icon={collapsed ? <MenuUnfoldOutlined /> : <MenuFoldOutlined />}
-            onClick={() => setCollapsed(!collapsed)}
+            onClick={toggleCollapsed}
           />
           />
         </div>
         </div>
         <MainMenu />
         <MainMenu />
@@ -50,10 +82,15 @@ const Widget = () => {
       <Layout>
       <Layout>
         <div
         <div
           style={{
           style={{
-            padding: 16, // 建议保留左右内边距,否则内容会贴边
+            position: "sticky",
+            top: 0,
+            zIndex: 10,
+            background: token.colorBgLayout,
+            padding: "0 16px", // 保留左右内边距,否则内容会贴边
             display: "flex",
             display: "flex",
             alignItems: "center", // 垂直居中
             alignItems: "center", // 垂直居中
-            height: 24,
+            boxSizing: "border-box",
+            height: WORKSPACE_HEADER_HEIGHT,
             justifyContent: "space-between", // 如果需要左右分布(如左侧面包屑,右侧头像)可开启
             justifyContent: "space-between", // 如果需要左右分布(如左侧面包屑,右侧头像)可开启
           }}
           }}
         >
         >
@@ -68,7 +105,7 @@ const Widget = () => {
           </Space>
           </Space>
         </div>
         </div>
 
 
-        <Content style={{ padding: 12 }}>
+        <Content style={{ padding: WORKSPACE_CONTENT_PADDING }}>
           <TeamspaceGuard>
           <TeamspaceGuard>
             <Outlet />
             <Outlet />
           </TeamspaceGuard>
           </TeamspaceGuard>