Skip to content

Commit 50ce3d7

Browse files
Share reading progress, and a native ⋯ menu on iPhone (#159)
Adds Share to the currently reading book's ⋯ menu: a progress card in the clipping and stats cards' style (cover, title, author, series, percent and bar, print pages, time left, time read, days reading, sessions, pace, moods), opened straight in the native share sheet where the platform allows. On iPhone the ⋯ menu is now a native menu from the glass button (tauri-plugin-system-components 6cb6956, which also fixes linking with Xcode 27); elsewhere the HTML menu remains, now below the navigation bar. Also keeps the CrossPaper reading-goals test off the network, and bumps iOS to 0.1.3 (38).
1 parent 298e8b7 commit 50ce3d7

16 files changed

Lines changed: 397 additions & 57 deletions

File tree

‎app/package-lock.json‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎app/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"@fontsource/caveat": "^5.3.0",
1919
"@fontsource/geist-mono": "^5.3.0",
2020
"@fontsource/lora": "^5.3.0",
21-
"@sosweetham/tauri-plugin-system-components-api": "git+https://github.com/itsthisjustin/tauri-plugin-system-components.git#4b4031f4ec6f4d206936ace57f26784ba3836272",
21+
"@sosweetham/tauri-plugin-system-components-api": "git+https://github.com/itsthisjustin/tauri-plugin-system-components.git#6cb6956da5e6471f4e23dd3356e8286305eb0e32",
2222
"@tauri-apps/api": "^2.12.4",
2323
"@tauri-apps/plugin-deep-link": "^2.6.1",
2424
"@tauri-apps/plugin-haptics": "^2.4.2",

‎app/src-tauri/Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎app/src-tauri/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ tauri-plugin-opener = "2"
3030
tauri-plugin-deep-link = "2"
3131
tauri-plugin-haptics = "2"
3232
# UIKit-managed iPhone/Duo navigation from our fork, pinned with the JS package.
33-
tauri-plugin-system-components = { git = "https://github.com/itsthisjustin/tauri-plugin-system-components", rev = "4b4031f4ec6f4d206936ace57f26784ba3836272" }
33+
tauri-plugin-system-components = { git = "https://github.com/itsthisjustin/tauri-plugin-system-components", rev = "6cb6956da5e6471f4e23dd3356e8286305eb0e32" }
3434

3535
[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
3636
block2 = "0.6"

‎app/src-tauri/gen/apple/CrossPointShare/Info.plist‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
<key>CFBundlePackageType</key>
1616
<string>XPC!</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>0.1.2</string>
18+
<string>0.1.3</string>
1919
<key>CFBundleVersion</key>
20-
<string>35</string>
20+
<string>38</string>
2121
<key>NSExtension</key>
2222
<dict>
2323
<key>NSExtensionPointIdentifier</key>

‎app/src-tauri/gen/apple/CrossPointWidget/Info.plist‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
<key>CFBundlePackageType</key>
1818
<string>XPC!</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>0.1.2</string>
20+
<string>0.1.3</string>
2121
<key>CFBundleVersion</key>
22-
<string>35</string>
22+
<string>38</string>
2323
<key>NSAppTransportSecurity</key>
2424
<dict>
2525
<key>NSAllowsLocalNetworking</key>

‎app/src-tauri/gen/apple/crosspoint-sync-app_iOS/Info.plist‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@
4141
<key>CFBundlePackageType</key>
4242
<string>APPL</string>
4343
<key>CFBundleShortVersionString</key>
44-
<string>0.1.2</string>
44+
<string>0.1.3</string>
4545
<key>CFBundleURLTypes</key>
4646
<array>
4747
<dict>
48-
<key>CFBundleURLName</key>
49-
<string>crosspointsync</string>
5048
<key>CFBundleURLSchemes</key>
5149
<array>
5250
<string>crosspointsync</string>
5351
</array>
52+
<key>CFBundleURLName</key>
53+
<string>crosspointsync</string>
5454
</dict>
5555
</array>
5656
<key>CFBundleVersion</key>
57-
<string>35</string>
57+
<string>38</string>
5858
<key>ITSAppUsesNonExemptEncryption</key>
5959
<false/>
6060
<key>LSRequiresIPhoneOS</key>

‎app/src-tauri/tauri.conf.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://schema.tauri.app/config/2",
33
"productName": "CrossPoint Sync",
4-
"version": "0.1.2",
4+
"version": "0.1.3",
55
"identifier": "com.crosspointreader.sync",
66
"build": {
77
"frontendDist": "../dist",
@@ -42,7 +42,7 @@
4242
"iOS": {
4343
"minimumSystemVersion": "16.0",
4444
"developmentTeam": "96247QW4R8",
45-
"bundleVersion": "35"
45+
"bundleVersion": "38"
4646
}
4747
},
4848
"plugins": {

‎app/src/Book.jsx‎

Lines changed: 105 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect, useRef, useState } from 'react'
22
import { ArrowLeft, CalendarDays, MoreHorizontal, PenLine, Split, Trash2, Image as ImageIcon, Loader2, Merge, Quote, Search, Star, X } from 'lucide-react'
33
import { api, isApp, untitled } from './api.js'
4-
import { renderCard } from './shareCard.js'
4+
import { renderCard, renderProgressCard } from './shareCard.js'
55
import { isPace, moodEmoji } from './moods.js'
66
import ShareSheet from './ShareSheet.jsx'
77
import { useNativeBack, useNativeButton } from './tabbar.js'
@@ -115,6 +115,65 @@ export function ClipShare({ session, book, clip, onClose }) {
115115
)
116116
}
117117

118+
// What the reading-progress card shows, from the book, its sync activity and its
119+
// device stats (`stats` is /stats/books/:document's answer, or null).
120+
export function progressCard(book, a, stats) {
121+
const c = stats?.combined
122+
const progress = book.percentage ?? 0
123+
const total = a?.page_count ?? book.page_count
124+
// From the shown percentage, not activity's pages_read (the furthest ever reached), so a reread matches.
125+
const read = total ? Math.round(progress * total) : null
126+
// The freshest device's own estimate of the time left.
127+
const eta = [...(stats?.devices ?? [])].sort((x, y) => y.updated_at - x.updated_at).find((d) => d.stats?.eta > 0)?.stats.eta
128+
const started = a?.start_manual ? a.started_at : c?.start_date || a?.started_at
129+
const days = started ? Math.max(1, Math.round((Date.now() / 1000 - started) / 86400)) : null
130+
const tiles = [
131+
c?.seconds > 0 && ['time read', duration(c.seconds)],
132+
days && ['days reading', days.toLocaleString()],
133+
c?.sessions > 0 && ['sessions', c.sessions.toLocaleString()],
134+
c?.avg_fwd > 0 && ['per page', c.avg_fwd < 60 ? `${c.avg_fwd}s` : duration(c.avg_fwd)],
135+
!c?.sessions && started && ['started', date(started, { year: undefined })],
136+
].filter(Boolean)
137+
return {
138+
title: book.title || book.filename || 'Untitled book',
139+
author: book.author,
140+
series: seriesLabel(book),
141+
progress,
142+
pages: total && read != null ? `Page ${Math.min(read, total).toLocaleString()} of ${total.toLocaleString()}` : null,
143+
left: eta ? `${duration(eta)} left` : null,
144+
tiles,
145+
moods: (book.moods ?? []).filter((m) => !isPace(m)).slice(0, 3),
146+
}
147+
}
148+
149+
// The currently reading book's progress card, straight to the native share sheet where it can.
150+
function ProgressShare({ session, book, activity, onClose }) {
151+
const title = book.title || book.filename || 'Untitled book'
152+
const meta = {
153+
title,
154+
author: book.author,
155+
postTitle: `Currently reading ${title}`,
156+
fileName: `${title} progress.png`,
157+
text: `${pct(book.percentage ?? 0)} through ${title}${book.author ? ` by ${book.author}` : ''}. Tracked with CrossPoint Sync.`,
158+
}
159+
return (
160+
<ShareSheet
161+
heading="Share your progress"
162+
meta={meta}
163+
renderKey={`${book.document}-${book.percentage}`}
164+
onClose={onClose}
165+
autoShare
166+
render={async () => {
167+
const [coverUrl, stats] = await Promise.all([
168+
book.cover_url ?? api.cover(session, book.document).then((r) => r.url, () => null),
169+
api.bookStats(session, book.document).catch(() => null),
170+
])
171+
return renderProgressCard({ ...progressCard(book, activity, stats), coverUrl })
172+
}}
173+
/>
174+
)
175+
}
176+
118177
// Touch: press and hold a clipping to delete it (desktop uses ClipMenu). One press at a time, so one timer.
119178
let holdTimer
120179
export function hold(fn) {
@@ -656,28 +715,41 @@ function EditDetailsSheet({ session, book: current, onDone, onClose }) {
656715

657716
function BookMenu({ session, book, books, activity, onChange }) {
658717
const [action, setAction] = useState(null)
659-
const [open, setOpen] = useState(null) // 'edit' | 'cover' | 'dates' | 'merge'
718+
const [open, setOpen] = useState(null) // 'share' | 'edit' | 'cover' | 'dates' | 'merge'
660719
const [menu, setMenu] = useState(false)
661-
useNativeButton('more', { sfSymbol: 'ellipsis', anchor: 'topTrailing' }, () => setMenu((m) => !m))
662720
const dupes = books.filter((b) => looksLikeSame(book, b)).length
721+
const separate = book.aliases?.length ?? 0
722+
// One list for the iPhone's native menu and the HTML menu elsewhere.
723+
const entries = [
724+
book.status === 'reading' && !book.history_only && { id: 'share', title: 'Share', Icon: ShareIcon, sfSymbol: 'square.and.arrow.up', run: () => setOpen('share') },
725+
{ id: 'edit', title: 'Edit details', Icon: PenLine, sfSymbol: 'pencil', run: () => setOpen('edit') },
726+
{ id: 'cover', title: 'Change cover', Icon: ImageIcon, sfSymbol: 'photo', run: () => setOpen('cover') },
727+
{ id: 'dates', title: 'Reading dates', Icon: CalendarDays, sfSymbol: 'calendar', run: () => setOpen('dates') },
728+
{ id: 'merge', title: 'Merge a duplicate', Icon: Merge, sfSymbol: 'arrow.triangle.merge', badge: dupes > 0 ? `${dupes} likely` : null, run: () => setOpen('merge') },
729+
separate > 0 && {
730+
id: 'separate',
731+
title: separate === 1 ? 'Separate merged copy' : `Separate ${separate} merged copies`,
732+
Icon: Split,
733+
sfSymbol: 'arrow.triangle.branch',
734+
run: () => setAction({ kind: 'separate', aliases: [...book.aliases] }),
735+
},
736+
{ id: 'remove', title: 'Remove from library', Icon: Trash2, sfSymbol: 'trash', destructive: true, run: () => setAction({ kind: 'remove', document: book.document, title: book.title }) },
737+
].filter(Boolean)
738+
useNativeButton(
739+
'more',
740+
{
741+
sfSymbol: 'ellipsis',
742+
anchor: 'topTrailing',
743+
label: 'More',
744+
menu: entries.map(({ id, title, sfSymbol, badge, destructive }) => ({ id, title, sfSymbol, ...(badge ? { subtitle: badge } : {}), ...(destructive ? { destructive } : {}) })),
745+
},
746+
() => setMenu((m) => !m),
747+
(id) => entries.find((e) => e.id === id)?.run()
748+
)
663749
const done = () => {
664750
setOpen(null)
665751
onChange()
666752
}
667-
const item = (Icon, label, run, extra = null, danger = false) => (
668-
<button
669-
type="button"
670-
role="menuitem"
671-
onClick={() => {
672-
setMenu(false)
673-
run()
674-
}}
675-
className={`flex w-full items-center gap-3 px-4 py-3 text-left text-sm font-medium active:bg-stone-50 md:hover:bg-stone-50 ${danger ? 'text-red-600' : 'text-stone-800'}`}
676-
>
677-
<Icon className={`size-4 ${danger ? '' : 'text-stone-400'}`} /> {label}
678-
{extra}
679-
</button>
680-
)
681753

682754
return (
683755
<div className="relative ml-auto">
@@ -695,18 +767,21 @@ function BookMenu({ session, book, books, activity, onChange }) {
695767
<>
696768
<div className="fixed inset-0 z-30" onClick={() => setMenu(false)} />
697769
<div role="menu" className="native-menu absolute top-12 right-0 z-30 w-64 divide-y divide-stone-100 overflow-hidden rounded-xl bg-surface shadow-lg ring-1 ring-stone-950/10">
698-
{item(PenLine, 'Edit details', () => setOpen('edit'))}
699-
{item(ImageIcon, 'Change cover', () => setOpen('cover'))}
700-
{item(CalendarDays, 'Reading dates', () => setOpen('dates'))}
701-
{item(
702-
Merge,
703-
'Merge a duplicate',
704-
() => setOpen('merge'),
705-
dupes > 0 && <span className="ml-auto rounded-full bg-brand-50 px-2 py-0.5 text-[0.65rem] font-semibold text-brand-700">{dupes} likely</span>
706-
)}
707-
{book.aliases?.length > 0 &&
708-
item(Split, book.aliases.length === 1 ? 'Separate merged copy' : `Separate ${book.aliases.length} merged copies`, () => setAction({ kind: 'separate', aliases: [...book.aliases] }))}
709-
{item(Trash2, 'Remove from library', () => setAction({ kind: 'remove', document: book.document, title: book.title }), null, true)}
770+
{entries.map(({ id, title, Icon, badge, destructive, run }) => (
771+
<button
772+
key={id}
773+
type="button"
774+
role="menuitem"
775+
onClick={() => {
776+
setMenu(false)
777+
run()
778+
}}
779+
className={`flex w-full items-center gap-3 px-4 py-3 text-left text-sm font-medium active:bg-stone-50 md:hover:bg-stone-50 ${destructive ? 'text-red-600' : 'text-stone-800'}`}
780+
>
781+
<Icon className={`size-4 ${destructive ? '' : 'text-stone-400'}`} /> {title}
782+
{badge && <span className="ml-auto rounded-full bg-brand-50 px-2 py-0.5 text-[0.65rem] font-semibold text-brand-700">{badge}</span>}
783+
</button>
784+
))}
710785
</div>
711786
</>
712787
)}
@@ -736,6 +811,7 @@ function BookMenu({ session, book, books, activity, onChange }) {
736811
: 'Its progress, clippings and stats are deleted. A reader that still has it will sync it again.'}
737812
</ActionSheet>
738813
)}
814+
{open === 'share' && <ProgressShare session={session} book={book} activity={activity} onClose={() => setOpen(null)} />}
739815
{open === 'cover' && <CoverPicker session={session} book={book} onDone={done} onClose={() => setOpen(null)} />}
740816
{open === 'dates' && <DatesSheet session={session} book={book} activity={activity} onDone={done} onClose={() => setOpen(null)} />}
741817
{open === 'merge' && <MergePicker session={session} book={book} books={books} onDone={done} onClose={() => setOpen(null)} />}

‎app/src/Book.test.jsx‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,34 @@ it('credits Hardcover only for a description it supplied', () => {
258258
expect(screen.queryByText('via Hardcover')).toBeNull()
259259
delete loads['about book']
260260
})
261+
262+
it('offers Share in the menu only while a book is being read', () => {
263+
render(<Book session={{}} book={book} books={[book]} onChange={vi.fn()} />)
264+
fireEvent.click(screen.getByRole('button', { name: 'More' }))
265+
expect(screen.getByRole('menuitem', { name: 'Share' })).toBeTruthy()
266+
cleanup()
267+
render(<Book session={{}} book={{ ...book, status: 'finished' }} books={[book]} onChange={vi.fn()} />)
268+
fireEvent.click(screen.getByRole('button', { name: 'More' }))
269+
expect(screen.queryByRole('menuitem', { name: 'Share' })).toBeNull()
270+
})
271+
272+
it('builds the progress card from the book, its activity and device stats', async () => {
273+
const { progressCard } = await import('./Book.jsx')
274+
vi.spyOn(Date, 'now').mockReturnValue(1_700_000_000_000 + 9 * 86400_000)
275+
const card = progressCard(
276+
{ ...book, author: 'George Eliot', series: 'Novels', series_position: 2, moods: ['Reflective', 'Slow-paced', 'Emotional'] },
277+
// A reread: activity's pages_read is the furthest ever reached; the card follows the current 62%.
278+
{ page_count: 880, pages_read: 880, started_at: 1_700_000_000 },
279+
{ combined: { seconds: 41_400, sessions: 23, avg_fwd: 48, start_date: 0 },
280+
devices: [{ updated_at: 1, stats: { eta: 99 } }, { updated_at: 2, stats: { eta: 25_200 } }] },
281+
)
282+
expect(card).toMatchObject({
283+
title: 'Middlemarch', author: 'George Eliot', series: 'Novels · Book 2', progress: 0.62,
284+
pages: 'Page 546 of 880', left: '7h left', moods: ['Reflective', 'Emotional'],
285+
tiles: [['time read', '11h 30m'], ['days reading', '9'], ['sessions', '23'], ['per page', '48s']],
286+
})
287+
// Sync history only: print pages from the percentage, and the start date.
288+
expect(progressCard({ ...book, page_count: 200 }, { started_at: 1_700_000_000 }, null)).toMatchObject({
289+
pages: 'Page 124 of 200', left: null, tiles: [['days reading', '9'], ['started', expect.any(String)]],
290+
})
291+
})

0 commit comments

Comments
 (0)