|
| 1 | +/** |
| 2 | + * NoteListRow — 笔记列表行(v0.15 自 NoteListView 拆出——树态/平铺共用)。 |
| 3 | + * |
| 4 | + * @ai-context: 行 id=`note-row-{id}` 供 focusNoteId 跨页直达滚动定位; |
| 5 | + * 拖拽源(组行为 drop target,move_note_to_group 命令); |
| 6 | + * 勾选/固定/标签/来源会话跳转保持 v0.12.x 语义不变。 |
| 7 | + */ |
| 8 | +import { useMemo } from "react"; |
| 9 | +import type { Note } from "../types"; |
| 10 | +import { paletteHex } from "../utils/colorPalette"; |
| 11 | +import type { ThemeMode } from "../utils/colorPalette"; |
| 12 | +import { fmtDate, parseTags } from "../utils/noteHelpers"; |
| 13 | + |
| 14 | +interface Props { |
| 15 | + note: Note; |
| 16 | + /** 行左侧色条(父层 resolveNoteColor 解析结果) */ |
| 17 | + accent: string; |
| 18 | + selectedId: number | null; |
| 19 | + checked: boolean; |
| 20 | + tagColors?: Record<string, string>; |
| 21 | + onSelect: (note: Note) => void; |
| 22 | + onToggleSelect: (id: number) => void; |
| 23 | + onOpenSession: (sessionId: number) => void; |
| 24 | +} |
| 25 | + |
| 26 | +export default function NoteListRow({ |
| 27 | + note, accent, selectedId, checked, tagColors, onSelect, onToggleSelect, onOpenSession, |
| 28 | +}: Props) { |
| 29 | + const tags = parseTags(note); |
| 30 | + // v0.14 B:当前主题(跟随 prefers-color-scheme;jsdom 无 matchMedia 回退 light) |
| 31 | + const theme: ThemeMode = useMemo( |
| 32 | + () => (typeof window !== "undefined" && window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light"), |
| 33 | + [], |
| 34 | + ); |
| 35 | + return ( |
| 36 | + <div |
| 37 | + id={`note-row-${note.id}`} |
| 38 | + draggable |
| 39 | + onDragStart={(e) => { |
| 40 | + // v0.14 C1:拖拽归组——笔记卡片为 drag source(组行为 drop target) |
| 41 | + e.dataTransfer.setData("text/note-id", String(note.id)); |
| 42 | + e.dataTransfer.effectAllowed = "move"; |
| 43 | + }} |
| 44 | + onClick={() => onSelect(note)} |
| 45 | + style={{ |
| 46 | + padding: "10px 14px", |
| 47 | + borderBottom: "1px solid #f3f4f6", |
| 48 | + borderLeft: `4px solid ${accent}`, |
| 49 | + cursor: "pointer", |
| 50 | + background: selectedId === note.id ? "#f0fdfa" : "transparent", |
| 51 | + }} |
| 52 | + > |
| 53 | + <div style={{ display: "flex", alignItems: "center", gap: 6 }}> |
| 54 | + <input |
| 55 | + type="checkbox" |
| 56 | + checked={checked} |
| 57 | + onClick={(e) => e.stopPropagation()} |
| 58 | + onChange={() => onToggleSelect(note.id)} |
| 59 | + style={{ cursor: "pointer", flexShrink: 0 }} |
| 60 | + title="勾选后可批量删除" |
| 61 | + /> |
| 62 | + {note.pin ? <span style={{ fontSize: 11, color: "#b45309" }}>📌</span> : null} |
| 63 | + <div style={{ fontSize: 13, fontWeight: 500, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis", flex: 1 }}> |
| 64 | + {note.title} |
| 65 | + </div> |
| 66 | + </div> |
| 67 | + <div style={{ fontSize: 11, color: "#9ca3af", marginTop: 2, display: "flex", flexWrap: "wrap", alignItems: "center", gap: 4 }}> |
| 68 | + <span>{note.source === "classroom" ? "📡 课堂" : "✍ 手动"} · {fmtDate(note.updated_at)}</span> |
| 69 | + {tags.slice(0, 3).map((t) => ( |
| 70 | + <span |
| 71 | + key={t} |
| 72 | + style={{ |
| 73 | + fontSize: 10, color: "#6b7280", borderRadius: 8, padding: "0 4px", |
| 74 | + // v0.14 B:标签色徽标底色(tagColors 命中用色板色 13% 透明底;否则默认灰底) |
| 75 | + background: tagColors?.[t] ? `${paletteHex(tagColors[t], theme)}22` : "#f3f4f6", |
| 76 | + }} |
| 77 | + > |
| 78 | + {t} |
| 79 | + </span> |
| 80 | + ))} |
| 81 | + {tags.length > 3 && <span style={{ fontSize: 10, color: "#9ca3af" }}>+{tags.length - 3}</span>} |
| 82 | + {note.session_id != null && ( |
| 83 | + <span |
| 84 | + onClick={(e) => { e.stopPropagation(); onOpenSession(note.session_id as number); }} |
| 85 | + style={{ fontSize: 11, color: "#0f766e", cursor: "pointer", fontWeight: 600 }} |
| 86 | + title="跳转到来源会话" |
| 87 | + > |
| 88 | + 来源会话 → |
| 89 | + </span> |
| 90 | + )} |
| 91 | + </div> |
| 92 | + </div> |
| 93 | + ); |
| 94 | +} |
0 commit comments