dsh-half-page 0.3.22 → 0.3.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.js +32 -4
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -167,6 +167,21 @@ window.__ModuleLoader__.load({
|
|
|
167
167
|
if (ch) { copy(ch.lines.join('\n')); setMsg('已复制这条读后感') } else setMsg('这条读后感已经不在了')
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
// 收藏页点一下就地展开:作品看正文,读后感看那一条
|
|
171
|
+
const openFav = async (f) => {
|
|
172
|
+
const key = 'fav:' + f
|
|
173
|
+
if (opened && opened.path === key) return setOpened(null)
|
|
174
|
+
if (String(f).startsWith('file:')) {
|
|
175
|
+
const p = f.slice(5)
|
|
176
|
+
const r = await getJson('/dsh-reading.file?path=' + encodeURIComponent(p))
|
|
177
|
+
return setOpened({ path: key, title: p, text: r && r.ok ? r.text : '读不到:' + (r && r.error) })
|
|
178
|
+
}
|
|
179
|
+
const parts = String(f).split('|')
|
|
180
|
+
const bk = notes.find((x) => x.book === parts[0])
|
|
181
|
+
const ch = bk && (bk.chapters || []).find((x) => x.title === parts[1])
|
|
182
|
+
setOpened({ path: key, title: parts.join(' · '), text: ch ? ch.lines.join('\n') : '这条读后感已经不在了' })
|
|
183
|
+
}
|
|
184
|
+
|
|
170
185
|
const saveCfg = async (patch) => {
|
|
171
186
|
const r = await getJson('/dsh-reading.config', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(patch) })
|
|
172
187
|
if (r && r.ok) { setCfg(r.config); setMsg('已保存') ; await load() } else setMsg('保存失败:' + (r && r.error))
|
|
@@ -187,7 +202,7 @@ window.__ModuleLoader__.load({
|
|
|
187
202
|
|
|
188
203
|
const tabs = h('div', { style: S.row },
|
|
189
204
|
['read', 'works', 'fav', 'set'].map((k) => h('div', {
|
|
190
|
-
key: k, style: S.tab(tab === k), onClick: () => { setTab(k); if (k === 'works' && !works) loadWorks() },
|
|
205
|
+
key: k, style: S.tab(tab === k), onClick: () => { setTab(k); if ((k === 'works' || k === 'fav') && !works) loadWorks() },
|
|
191
206
|
}, k === 'read' ? '读书' : k === 'works' ? '她的作品' : k === 'fav' ? '收藏' : '设置')),
|
|
192
207
|
h('div', { style: { flex: 1 } }),
|
|
193
208
|
msg ? h('div', { style: { ...S.dim, color: C.ok } }, msg) : null,
|
|
@@ -441,12 +456,25 @@ window.__ModuleLoader__.load({
|
|
|
441
456
|
const favTab = h('div', { style: { display: 'flex', flexDirection: 'column', gap: 10 } },
|
|
442
457
|
h('div', { style: S.card },
|
|
443
458
|
h('div', { style: { fontWeight: 600, marginBottom: 6 } }, '收藏'),
|
|
444
|
-
favs.length ? favs.map((f, i) =>
|
|
445
|
-
|
|
459
|
+
favs.length ? favs.map((f, i) => {
|
|
460
|
+
const isFile = String(f).startsWith('file:')
|
|
461
|
+
const fpath = isFile ? f.slice(5) : ''
|
|
462
|
+
const w = isFile && works && (works.files || []).find((x) => x.path === fpath)
|
|
463
|
+
const who = w ? w.author : ''
|
|
464
|
+
return h('div', { key: i, style: S.item },
|
|
465
|
+
h('div', {
|
|
466
|
+
style: { flex: 1, cursor: 'pointer', borderTop: i ? '1px solid ' + C.line : 'none', paddingTop: i ? 8 : 0 },
|
|
467
|
+
onClick: () => openFav(f),
|
|
468
|
+
}, String(f).startsWith('file:') ? f.slice(5) : f.replace('|', ' · ')),
|
|
469
|
+
isFile ? h('div', { style: who ? S.dim : { ...S.dim, color: C.warn } }, who ? ('署名 · ' + who) : '未署名') : null,
|
|
446
470
|
h('button', { style: S.btn, onClick: () => copyFav(f) }, '复制'),
|
|
447
471
|
h('button', { style: S.btn, onClick: () => toggleFav(f) }, '取消收藏'),
|
|
448
|
-
|
|
472
|
+
)
|
|
473
|
+
}) : h('div', { style: S.dim }, '在读后感或作品上点 ☆,收藏的东西会出现在这儿。'),
|
|
449
474
|
),
|
|
475
|
+
opened && String(opened.path || '').startsWith('fav:')
|
|
476
|
+
? h('div', { style: { ...S.text, marginTop: 0 } }, (opened.title ? opened.title + '\n\n' : '') + opened.text)
|
|
477
|
+
: null,
|
|
450
478
|
)
|
|
451
479
|
|
|
452
480
|
return h('div', { style: S.wrap },
|