root commited on
Commit
0cc5ace
·
1 Parent(s): c46ffbd

稿纸等正文载入后再回到上次位置;接着看卡片显示读到第几章

Browse files
fanqie/dist/index.html CHANGED
@@ -8,7 +8,7 @@
8
  <title>小说写作台</title>
9
  <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='12' fill='%23b8432f'/%3E%3Ctext x='32' y='44' font-size='34' text-anchor='middle' fill='%23fff' font-family='serif'%3E%E6%96%87%3C/text%3E%3C/svg%3E" />
10
  <script>try{var t=localStorage.getItem('xs_theme');if(t==='night')document.documentElement.dataset.theme='night'}catch(e){}</script>
11
- <script type="module" crossorigin src="/assets/index-DnLQfh19.js"></script>
12
  <link rel="stylesheet" crossorigin href="/assets/index-Ih3zuQhz.css">
13
  </head>
14
  <body>
 
8
  <title>小说写作台</title>
9
  <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='12' fill='%23b8432f'/%3E%3Ctext x='32' y='44' font-size='34' text-anchor='middle' fill='%23fff' font-family='serif'%3E%E6%96%87%3C/text%3E%3C/svg%3E" />
10
  <script>try{var t=localStorage.getItem('xs_theme');if(t==='night')document.documentElement.dataset.theme='night'}catch(e){}</script>
11
+ <script type="module" crossorigin src="/assets/index-CL3IWhr7.js"></script>
12
  <link rel="stylesheet" crossorigin href="/assets/index-Ih3zuQhz.css">
13
  </head>
14
  <body>
public/assets/{index-DnLQfh19.js → index-CL3IWhr7.js} RENAMED
The diff for this file is too large to render. See raw diff
 
public/index.html CHANGED
@@ -8,7 +8,7 @@
8
  <title>小说写作台</title>
9
  <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='12' fill='%23b8432f'/%3E%3Ctext x='32' y='44' font-size='34' text-anchor='middle' fill='%23fff' font-family='serif'%3E%E6%96%87%3C/text%3E%3C/svg%3E" />
10
  <script>try{var t=localStorage.getItem('xs_theme');if(t==='night')document.documentElement.dataset.theme='night'}catch(e){}</script>
11
- <script type="module" crossorigin src="/assets/index-DnLQfh19.js"></script>
12
  <link rel="stylesheet" crossorigin href="/assets/index-Ih3zuQhz.css">
13
  </head>
14
  <body>
 
8
  <title>小说写作台</title>
9
  <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='12' fill='%23b8432f'/%3E%3Ctext x='32' y='44' font-size='34' text-anchor='middle' fill='%23fff' font-family='serif'%3E%E6%96%87%3C/text%3E%3C/svg%3E" />
10
  <script>try{var t=localStorage.getItem('xs_theme');if(t==='night')document.documentElement.dataset.theme='night'}catch(e){}</script>
11
+ <script type="module" crossorigin src="/assets/index-CL3IWhr7.js"></script>
12
  <link rel="stylesheet" crossorigin href="/assets/index-Ih3zuQhz.css">
13
  </head>
14
  <body>
ui-src/src/rooms/Book.tsx CHANGED
@@ -173,7 +173,7 @@ function ContinueCard({ pid, chapters, current, big }: { pid: string; chapters:
173
  let target = sorted[at], r = last.r, label = '接着看'
174
  if (isDone(r) && sorted[at + 1]) { target = sorted[at + 1]; r = prog.chapters[target.chapter_id]?.r || 0; label = '上一章看完了,下一章' }
175
  else if (isDone(r)) label = '最新一章看完了'
176
- const done = sorted.filter(c => isDone(prog.chapters[c.chapter_id]?.max || 0)).length
177
  const here = current === target.chapter_id || (current === 'read' && last.mode === 'read')
178
  if (here && !big) return null
179
  const href = last.mode === 'read' ? `book/${pid}/read/${target.chapter_id}` : `book/${pid}/${target.chapter_id}`
@@ -181,7 +181,7 @@ function ContinueCard({ pid, chapters, current, big }: { pid: string; chapters:
181
  <button className={cx('continue-card', big && 'big')} onClick={() => go(href)} title={last.mode === 'read' ? '回到通读' : '回到正文稿纸'}>
182
  <span className="cc-k">{label}<em>{fmtAgo(new Date(last.at).toISOString())}</em></span>
183
  <span className="cc-t">第{target.number}章 {target.title}</span>
184
- <span className="cc-m">{r > 0.01 && !isDone(r) ? `看到 ${pct(r)}` : isDone(r) ? '已看完' : '从开头看'} · 全书看完 {done}/{sorted.length} 章</span>
185
  <i className="cc-bar"><b style={{ width: pct(r) }} /></i>
186
  </button>
187
  )
 
173
  let target = sorted[at], r = last.r, label = '接着看'
174
  if (isDone(r) && sorted[at + 1]) { target = sorted[at + 1]; r = prog.chapters[target.chapter_id]?.r || 0; label = '上一章看完了,下一章' }
175
  else if (isDone(r)) label = '最新一章看完了'
176
+ const far = sorted.reduce((n, c) => isDone(prog.chapters[c.chapter_id]?.max || 0) ? Math.max(n, c.number) : n, 0)
177
  const here = current === target.chapter_id || (current === 'read' && last.mode === 'read')
178
  if (here && !big) return null
179
  const href = last.mode === 'read' ? `book/${pid}/read/${target.chapter_id}` : `book/${pid}/${target.chapter_id}`
 
181
  <button className={cx('continue-card', big && 'big')} onClick={() => go(href)} title={last.mode === 'read' ? '回到通读' : '回到正文稿纸'}>
182
  <span className="cc-k">{label}<em>{fmtAgo(new Date(last.at).toISOString())}</em></span>
183
  <span className="cc-t">第{target.number}章 {target.title}</span>
184
+ <span className="cc-m">{r > 0.01 && !isDone(r) ? `看到 ${pct(r)}` : isDone(r) ? '已看完' : '从开头看'} {far ? ` · 已看到第${far}章,共${sorted.length}章` : ''}</span>
185
  <i className="cc-bar"><b style={{ width: pct(r) }} /></i>
186
  </button>
187
  )
ui-src/src/rooms/Editor.tsx CHANGED
@@ -68,6 +68,7 @@ export default function ChapterEditor({ ctx, chapter }: { ctx: BookCtx; chapter:
68
  }
69
 
70
  /* 载入章节和当前版本 */
 
71
  const load = useCallback(async () => {
72
  setLoadErr('')
73
  try {
@@ -86,6 +87,7 @@ export default function ChapterEditor({ ctx, chapter }: { ctx: BookCtx; chapter:
86
  if (draft && draft.text !== base && draft.text.trim()) { setText(draft.text); setRestored(draft) }
87
  else { setText(base); if (draft) localStorage.removeItem(draftKey(cid)) }
88
  startWords.current = countWords(draft && draft.text !== base ? draft.text : base)
 
89
  } catch (e: any) { setLoadErr(e.message) }
90
  }, [pid, cid])
91
  useEffect(() => { load() }, [load])
@@ -99,19 +101,21 @@ export default function ChapterEditor({ ctx, chapter }: { ctx: BookCtx; chapter:
99
  const lastRatio = useRef(0)
100
  useEffect(() => { if (resumed == null) return; const t = setTimeout(() => setResumed(null), 7000); return () => clearTimeout(t) }, [resumed])
101
  useEffect(() => {
102
- if (!detail || restoredFor.current === cid) return
103
  restoredFor.current = cid
104
  const local = Number(localStorage.getItem(`xs_epos_${cid}`) || 'NaN')
105
  const apply = (r: number) => requestAnimationFrame(() => requestAnimationFrame(() => {
106
  const el = scrollRef.current
107
  if (!el || !(r > 0.01)) return
 
 
108
  lastRatio.current = r
109
  el.scrollTop = r * (el.scrollHeight - el.clientHeight)
110
  if (r > 0.03 && r < 0.97) setResumed(r)
111
  }))
112
  if (!isNaN(local)) apply(local)
113
  else projectsApi.progress(pid).then(p => { const r = p.chapters?.[cid]?.edit_ratio; if (r != null) apply(r) }, () => {})
114
- }, [detail, cid, pid])
115
  const onScroll = () => {
116
  const el = scrollRef.current
117
  if (!el) return
 
68
  }
69
 
70
  /* 载入章节和当前版本 */
71
+ const [ready, setReady] = useState(false)
72
  const load = useCallback(async () => {
73
  setLoadErr('')
74
  try {
 
87
  if (draft && draft.text !== base && draft.text.trim()) { setText(draft.text); setRestored(draft) }
88
  else { setText(base); if (draft) localStorage.removeItem(draftKey(cid)) }
89
  startWords.current = countWords(draft && draft.text !== base ? draft.text : base)
90
+ setReady(true)
91
  } catch (e: any) { setLoadErr(e.message) }
92
  }, [pid, cid])
93
  useEffect(() => { load() }, [load])
 
101
  const lastRatio = useRef(0)
102
  useEffect(() => { if (resumed == null) return; const t = setTimeout(() => setResumed(null), 7000); return () => clearTimeout(t) }, [resumed])
103
  useEffect(() => {
104
+ if (!detail || !ready || restoredFor.current === cid) return
105
  restoredFor.current = cid
106
  const local = Number(localStorage.getItem(`xs_epos_${cid}`) || 'NaN')
107
  const apply = (r: number) => requestAnimationFrame(() => requestAnimationFrame(() => {
108
  const el = scrollRef.current
109
  if (!el || !(r > 0.01)) return
110
+ const ta = taRef.current
111
+ if (ta) { ta.style.height = 'auto'; ta.style.height = `${ta.scrollHeight}px` }
112
  lastRatio.current = r
113
  el.scrollTop = r * (el.scrollHeight - el.clientHeight)
114
  if (r > 0.03 && r < 0.97) setResumed(r)
115
  }))
116
  if (!isNaN(local)) apply(local)
117
  else projectsApi.progress(pid).then(p => { const r = p.chapters?.[cid]?.edit_ratio; if (r != null) apply(r) }, () => {})
118
+ }, [detail, ready, cid, pid])
119
  const onScroll = () => {
120
  const el = scrollRef.current
121
  if (!el) return