mirror of
https://github.com/dergigi/boris.git
synced 2026-02-16 20:45:01 +01:00
Compare commits
420 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
104332fd94 | ||
|
|
e736c9f5b9 | ||
|
|
103e104cb2 | ||
|
|
5389397e9b | ||
|
|
54cba2beed | ||
|
|
da76cb247c | ||
|
|
9b4a7b6263 | ||
|
|
e6f98d69e7 | ||
|
|
3785d34e8f | ||
|
|
a30943686e | ||
|
|
d4b78d9484 | ||
|
|
66de230f66 | ||
|
|
8cb77864bc | ||
|
|
ea3c130cc3 | ||
|
|
f417ed8210 | ||
|
|
945b9502bc | ||
|
|
4a432bac8d | ||
|
|
541d30764e | ||
|
|
7c2b373254 | ||
|
|
0bf33f1a7d | ||
|
|
1eca19154d | ||
|
|
fd2d4d106f | ||
|
|
d41cbb5305 | ||
|
|
f57a4d4f1b | ||
|
|
4b03f32d21 | ||
|
|
8f1288b1a2 | ||
|
|
7ec87b66d8 | ||
|
|
27dde5afa2 | ||
|
|
3b2732681d | ||
|
|
51a4b545e9 | ||
|
|
7e5972a6e2 | ||
|
|
156cf31625 | ||
|
|
ee7df54d87 | ||
|
|
15c016ad5e | ||
|
|
b0574d3f8e | ||
|
|
4fd6605666 | ||
|
|
76a117cdda | ||
|
|
d4c6747d98 | ||
|
|
6b221e4d13 | ||
|
|
7ec2ddcceb | ||
|
|
5ce13c667d | ||
|
|
c1877a40e9 | ||
|
|
18a38d054f | ||
|
|
500cec88d0 | ||
|
|
affd80ca2e | ||
|
|
5e1ed6b8de | ||
|
|
5d36d6de4f | ||
|
|
93eb8a63de | ||
|
|
6074caaae3 | ||
|
|
d206ff228e | ||
|
|
074af764ed | ||
|
|
e814aadb5b | ||
|
|
aaddd0ef6b | ||
|
|
8a39258d8e | ||
|
|
3136b198d5 | ||
|
|
8a431d962e | ||
|
|
50ab59ebcd | ||
|
|
3ba5bce437 | ||
|
|
9ed56b213e | ||
|
|
34804540c5 | ||
|
|
30c2ca5b85 | ||
|
|
68e6fcd3ac | ||
|
|
da385cd037 | ||
|
|
3b30bc98c7 | ||
|
|
056da1ad23 | ||
|
|
b7cda7a351 | ||
|
|
5896a5d6db | ||
|
|
af91e52555 | ||
|
|
b4ebb6334f | ||
|
|
27178bc3d1 | ||
|
|
76fefc88ca | ||
|
|
98c006939b | ||
|
|
80ed646dd4 | ||
|
|
7ea868d0b2 | ||
|
|
88e1bc3419 | ||
|
|
4ec34a0379 | ||
|
|
aec2dcb75c | ||
|
|
5bdc435f5d | ||
|
|
db46edd39e | ||
|
|
c9739f804d | ||
|
|
eeb44e344f | ||
|
|
a6674610b8 | ||
|
|
6ae3decafb | ||
|
|
00da638e81 | ||
|
|
f04c0a401e | ||
|
|
f5e9f164f5 | ||
|
|
589ac17114 | ||
|
|
8d3510947c | ||
|
|
08a8f5623a | ||
|
|
e85ccdc7da | ||
|
|
d0e7f146fb | ||
|
|
efdb33eb31 | ||
|
|
0abbe62515 | ||
|
|
ab0972dd29 | ||
|
|
83fbb26e03 | ||
|
|
e8ce928ec6 | ||
|
|
1a01e14702 | ||
|
|
aab8176987 | ||
|
|
5a8b885d25 | ||
|
|
c129b24352 | ||
|
|
d98d750268 | ||
|
|
8262b2bf24 | ||
|
|
b99f36c0c5 | ||
|
|
dfe37a260e | ||
|
|
2a42f1de53 | ||
|
|
cea2d0eda2 | ||
|
|
ef05974a72 | ||
|
|
5a6ac628d2 | ||
|
|
826f07544e | ||
|
|
911215c0fb | ||
|
|
43ed41bfae | ||
|
|
81597fbb6d | ||
|
|
cc722c2599 | ||
|
|
c20682fbe8 | ||
|
|
cfa6dc4400 | ||
|
|
851cecf18c | ||
|
|
d4c67485a2 | ||
|
|
381fd05c90 | ||
|
|
60c4ef55c0 | ||
|
|
0b7891419b | ||
|
|
aeedc622b1 | ||
|
|
6f5b87136b | ||
|
|
1ac0c719a2 | ||
|
|
c9ce5442e0 | ||
|
|
c28052720e | ||
|
|
d0f942c495 | ||
|
|
907ef82efb | ||
|
|
415ff04345 | ||
|
|
683ea27526 | ||
|
|
fa052483b2 | ||
|
|
0ae9e6321e | ||
|
|
5623f2e595 | ||
|
|
2c94c1e3f0 | ||
|
|
19dc2f70f2 | ||
|
|
5013ccc552 | ||
|
|
29eed3395f | ||
|
|
d6da27c634 | ||
|
|
5551b52bce | ||
|
|
af7eb48893 | ||
|
|
51ce79f13a | ||
|
|
bcfc04c35c | ||
|
|
d6911b2acb | ||
|
|
2a869f11e0 | ||
|
|
deab9974fa | ||
|
|
49872337f3 | ||
|
|
389b4de0eb | ||
|
|
959ccac857 | ||
|
|
78c58693a5 | ||
|
|
ab81fe5030 | ||
|
|
6bae30070e | ||
|
|
1f6a904717 | ||
|
|
9379475d1c | ||
|
|
77a5f4bd2a | ||
|
|
4fa01231cd | ||
|
|
1cd85507a7 | ||
|
|
b6f151c711 | ||
|
|
e3d924f3fc | ||
|
|
5914df23d3 | ||
|
|
2083c2b8c6 | ||
|
|
35a8411d9b | ||
|
|
15b3b5b990 | ||
|
|
ad56acb712 | ||
|
|
2f5fe87fc8 | ||
|
|
d313c71e24 | ||
|
|
903b4a4ec1 | ||
|
|
a511b25b87 | ||
|
|
e920cf9477 | ||
|
|
708a1bfd54 | ||
|
|
51842f55bf | ||
|
|
52991f8e20 | ||
|
|
e3cd4454b4 | ||
|
|
78bc1f46dd | ||
|
|
c8cd1e6e66 | ||
|
|
5254697fe2 | ||
|
|
13462efaed | ||
|
|
1df00fbfda | ||
|
|
c2e220a1f2 | ||
|
|
00740aab6d | ||
|
|
e12d67cc5f | ||
|
|
e12aaa2b6c | ||
|
|
9880a9ae34 | ||
|
|
603db680f2 | ||
|
|
ae0471946e | ||
|
|
a48308d57d | ||
|
|
f67b358148 | ||
|
|
46a0a3da1f | ||
|
|
c92a620ea8 | ||
|
|
34de372509 | ||
|
|
a422084949 | ||
|
|
bd0e075984 | ||
|
|
38f4b69d48 | ||
|
|
9d1d944daf | ||
|
|
e56461cb12 | ||
|
|
f6b6747f09 | ||
|
|
180c26c47a | ||
|
|
78da0cb3e4 | ||
|
|
3d74c25c7d | ||
|
|
f46f55705b | ||
|
|
205591602d | ||
|
|
c6a42e0304 | ||
|
|
688d4285e3 | ||
|
|
9f806afc45 | ||
|
|
1282e778c6 | ||
|
|
6fd40f2ff6 | ||
|
|
6ac40c8a17 | ||
|
|
92145af2bb | ||
|
|
1ebaf7ccd2 | ||
|
|
5d22819ae3 | ||
|
|
6761b1861e | ||
|
|
1d989eae76 | ||
|
|
33d6e5882d | ||
|
|
0a62924b78 | ||
|
|
e2472606dd | ||
|
|
6f04b8f513 | ||
|
|
a8ad346c5d | ||
|
|
465c24ed3a | ||
|
|
04dea350a4 | ||
|
|
29c4bcb69b | ||
|
|
23ea7f352b | ||
|
|
36b35367f1 | ||
|
|
183463c817 | ||
|
|
7fb91e71f1 | ||
|
|
717f094984 | ||
|
|
c69e50d3bb | ||
|
|
4e4d719d94 | ||
|
|
d453a6439c | ||
|
|
5dfa6ba3ae | ||
|
|
f2d2883eee | ||
|
|
84001d1b83 | ||
|
|
b7a390cf89 | ||
|
|
59d9179642 | ||
|
|
68301cd20f | ||
|
|
4d6b7e1a46 | ||
|
|
95fe9b548f | ||
|
|
e86ae9f05e | ||
|
|
2124be83c3 | ||
|
|
a8bb17d4cd | ||
|
|
a886a68822 | ||
|
|
76bdbc670d | ||
|
|
c16ce1fc7e | ||
|
|
a578d67b1e | ||
|
|
25d1ead9f5 | ||
|
|
ae5ea66dd2 | ||
|
|
cf5f8fae16 | ||
|
|
d9c46e602a | ||
|
|
4d980bf91c | ||
|
|
cb3b0e38e9 | ||
|
|
fbf5c455ca | ||
|
|
ed5decf3e9 | ||
|
|
44a7e6ae2c | ||
|
|
f52b94d72a | ||
|
|
d0833b5ed4 | ||
|
|
2f20b393bc | ||
|
|
13fa6cd485 | ||
|
|
e6e7240cd5 | ||
|
|
c1ff3b44d1 | ||
|
|
0577f862fd | ||
|
|
883cb352ff | ||
|
|
238cc9bc00 | ||
|
|
1800ee324e | ||
|
|
7d2dac2f1a | ||
|
|
7875f1d0bd | ||
|
|
d9263e07d1 | ||
|
|
9a345a7347 | ||
|
|
55d1af3bf9 | ||
|
|
feb3134b65 | ||
|
|
7d222e099f | ||
|
|
59436b5b9e | ||
|
|
2e08954e83 | ||
|
|
9cb1791a3a | ||
|
|
28ba620967 | ||
|
|
56f2d33e93 | ||
|
|
312c742969 | ||
|
|
0781c4ebfc | ||
|
|
85f4cd3590 | ||
|
|
89bc6258b1 | ||
|
|
534b628aea | ||
|
|
317d2e0b53 | ||
|
|
9ea69589fa | ||
|
|
89eaa97d30 | ||
|
|
0283405fb5 | ||
|
|
5eade913d1 | ||
|
|
15a7129b6d | ||
|
|
b9e17e0982 | ||
|
|
1be8c62c94 | ||
|
|
e2bf243b01 | ||
|
|
85d816b2a7 | ||
|
|
623bee4632 | ||
|
|
e68b97bde8 | ||
|
|
ca32dfca51 | ||
|
|
9de8b00d5d | ||
|
|
033ef5e995 | ||
|
|
c986b0d517 | ||
|
|
1729a5b066 | ||
|
|
c6186ea84e | ||
|
|
c798376411 | ||
|
|
e83c301e6a | ||
|
|
2c0aee3fe4 | ||
|
|
d0f043fb5a | ||
|
|
039b988869 | ||
|
|
d285003e1d | ||
|
|
530abeeb33 | ||
|
|
3ac6954cb7 | ||
|
|
1c0f619a47 | ||
|
|
0fcfd200a4 | ||
|
|
e01c8d33fc | ||
|
|
51c0f7d923 | ||
|
|
8c79b5fd75 | ||
|
|
29746f1042 | ||
|
|
829ec4bf6e | ||
|
|
30ae0d9dfb | ||
|
|
8924f1b307 | ||
|
|
f92fa2cc93 | ||
|
|
cc70b533e5 | ||
|
|
003c439658 | ||
|
|
019958073c | ||
|
|
3d47dddbd2 | ||
|
|
cabf897df8 | ||
|
|
4801c0d621 | ||
|
|
ae76d6e4ea | ||
|
|
a611e99ff6 | ||
|
|
1c039e164f | ||
|
|
ffa4b38106 | ||
|
|
3b22cb5c5d | ||
|
|
7bc4522be4 | ||
|
|
048e0d802b | ||
|
|
b282bc4972 | ||
|
|
c1a23c1f8f | ||
|
|
8a5aacfe7b | ||
|
|
9126910de5 | ||
|
|
496bbc36f4 | ||
|
|
90f25420b2 | ||
|
|
9167134a89 | ||
|
|
b5717f1ebf | ||
|
|
0c8eaaf220 | ||
|
|
80b2720838 | ||
|
|
ea69740fc8 | ||
|
|
d650997ff9 | ||
|
|
ba3554b173 | ||
|
|
2cc39d0200 | ||
|
|
9aa914a704 | ||
|
|
497b6fa4be | ||
|
|
4c838b0123 | ||
|
|
d551f66ef1 | ||
|
|
34514199ee | ||
|
|
228304f68a | ||
|
|
ba263acdff | ||
|
|
5131cbe12c | ||
|
|
fa8eed4f4e | ||
|
|
3ff57c4b67 | ||
|
|
51c364ea53 | ||
|
|
4d032372dc | ||
|
|
48b5aa3a30 | ||
|
|
d4483a2f91 | ||
|
|
c62cb21962 | ||
|
|
3f7d726ae6 | ||
|
|
ac0e5eb585 | ||
|
|
5a0dd49e4e | ||
|
|
d067193f21 | ||
|
|
774e2ba67c | ||
|
|
6f1c31058f | ||
|
|
7551a05aee | ||
|
|
df485b883d | ||
|
|
6f428af1bc | ||
|
|
e821aaf058 | ||
|
|
a84d439489 | ||
|
|
67bf7e017d | ||
|
|
e47419a0b8 | ||
|
|
2dda52c30f | ||
|
|
2e0a493243 | ||
|
|
2e955e9bed | ||
|
|
538cbd2296 | ||
|
|
c17eab5a47 | ||
|
|
b3c61ba635 | ||
|
|
3bfa750a0c | ||
|
|
d1f7e549c2 | ||
|
|
0fec120410 | ||
|
|
9b21075a9b | ||
|
|
4f78ee4794 | ||
|
|
8bb871913b | ||
|
|
49eb6855ca | ||
|
|
748b2e1631 | ||
|
|
9fa83a2a1c | ||
|
|
d45705e8e4 | ||
|
|
83c170b4e2 | ||
|
|
8459853c43 | ||
|
|
f7eeb080e1 | ||
|
|
2769b2dba7 | ||
|
|
46636b8e6a | ||
|
|
92a85761ef | ||
|
|
f6a325f7e9 | ||
|
|
a501fa816f | ||
|
|
5ece80b8e9 | ||
|
|
87c017b2c2 | ||
|
|
550ee415f0 | ||
|
|
aaaf226623 | ||
|
|
23ce0c9d4c | ||
|
|
dddf8575c4 | ||
|
|
3ab0610e1e | ||
|
|
e40f820fdc | ||
|
|
3f82bc7873 | ||
|
|
b913cc4d7f | ||
|
|
bc1aed30b4 | ||
|
|
9a801975aa | ||
|
|
f3e44edd51 | ||
|
|
0be6aa81ce | ||
|
|
c7b885cfcd | ||
|
|
11041df1fb | ||
|
|
89273e2a03 | ||
|
|
0610454e74 | ||
|
|
a02413a7cb | ||
|
|
0bc84e7c6c | ||
|
|
a1e28c6bc9 | ||
|
|
a1a7f0e4a4 | ||
|
|
cde8e30ab2 | ||
|
|
aa7e532950 | ||
|
|
c9208cfff2 | ||
|
|
2fb4132342 | ||
|
|
81180c8ba8 | ||
|
|
1c48adf44e |
@@ -2,4 +2,4 @@
|
|||||||
alwaysApply: true
|
alwaysApply: true
|
||||||
---
|
---
|
||||||
|
|
||||||
Keep files below 210 lines.
|
Keep files below 420 lines.
|
||||||
21
.cursor/rules/fetching-data-with-controllers.mdc
Normal file
21
.cursor/rules/fetching-data-with-controllers.mdc
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
description: fetching data from relays
|
||||||
|
alwaysApply: false
|
||||||
|
---
|
||||||
|
|
||||||
|
# Fetching Data with Controllers
|
||||||
|
|
||||||
|
We fetch data from relays using controllers:
|
||||||
|
|
||||||
|
- Start controllers immediatly; don't await.
|
||||||
|
- Stream via onEvent; dedupe replaceables; emit immediately.
|
||||||
|
- Parallel local/remote queries; complete on EOSE.
|
||||||
|
- Finalize and persist since after completion.
|
||||||
|
- Guard with generations to cancel stale runs.
|
||||||
|
- UI flips off loading on first streamed result.
|
||||||
|
|
||||||
|
We always include and prefer local relays for reads; optionally rebroadcast fetched content to local relays (depending on setting); and tolerate local‑only mode for writes (queueing for later).
|
||||||
|
|
||||||
|
Since we are streaming results, we should NEVER use timeouts for fetching data. We should always rely on EOSE.
|
||||||
|
|
||||||
|
In short: Local-first hydration, background network fetch, reactive updates, and replaceable lookups provide instant UI with eventual consistency. Use local relays as local data store for everything we fetch from remote relays.
|
||||||
@@ -3,6 +3,8 @@ description: anything related to UI/UX
|
|||||||
alwaysApply: false
|
alwaysApply: false
|
||||||
---
|
---
|
||||||
|
|
||||||
|
# Mobile-First UI/UX
|
||||||
|
|
||||||
This is a mobile-first application. All UI elements should be designed with that in mind. The application should work well on small screens, including older smartphones. The UX should be immaculate on mobile, even when in flight mode. (We use local caches and local relays, so that app works offline too.)
|
This is a mobile-first application. All UI elements should be designed with that in mind. The application should work well on small screens, including older smartphones. The UX should be immaculate on mobile, even when in flight mode. (We use local caches and local relays, so that app works offline too.)
|
||||||
|
|
||||||
Let's not show too many error messages, and more importantly: let's not make them red. Nothing is ever this tragic.
|
Let's not show too many error messages, and more importantly: let's not make them red. Nothing is ever this tragic.
|
||||||
|
|||||||
1384
CHANGELOG.md
1384
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
@@ -40,7 +40,7 @@
|
|||||||
|
|
||||||
- **Explore**: Discover friends' highlights and writings, plus a "nostrverse" feed.
|
- **Explore**: Discover friends' highlights and writings, plus a "nostrverse" feed.
|
||||||
- **Filters**: Visibility toggles (mine, friends, nostrverse) apply to Explore highlights.
|
- **Filters**: Visibility toggles (mine, friends, nostrverse) apply to Explore highlights.
|
||||||
- **Profiles**: View your own (`/me`) or other users (`/p/:npub`) with tabs for Highlights, Bookmarks, Archive, and Writings.
|
- **Profiles**: View your own (`/my`) or other users (`/p/:npub`) with tabs for Highlights, Bookmarks, Archive, and Writings.
|
||||||
|
|
||||||
## Support
|
## Support
|
||||||
|
|
||||||
|
|||||||
@@ -1,188 +0,0 @@
|
|||||||
# Tailwind CSS Migration Status
|
|
||||||
|
|
||||||
## ✅ Completed (Core Infrastructure)
|
|
||||||
|
|
||||||
### Phase 1: Setup & Foundation
|
|
||||||
- [x] Install Tailwind CSS with PostCSS and Autoprefixer
|
|
||||||
- [x] Configure `tailwind.config.js` with content globs and custom keyframes
|
|
||||||
- [x] Create `src/styles/tailwind.css` with base/components/utilities
|
|
||||||
- [x] Import Tailwind before existing CSS in `main.tsx`
|
|
||||||
- [x] Enable Tailwind preflight (CSS reset)
|
|
||||||
|
|
||||||
### Phase 2: Base Styles Reconciliation
|
|
||||||
- [x] Add CSS variables for user-settable theme colors
|
|
||||||
- `--highlight-color-mine`, `--highlight-color-friends`, `--highlight-color-nostrverse`
|
|
||||||
- `--reading-font`, `--reading-font-size`
|
|
||||||
- [x] Simplify `global.css` to work with Tailwind preflight
|
|
||||||
- [x] Remove redundant base styles handled by Tailwind
|
|
||||||
- [x] Keep app-specific overrides (mobile sidebar lock, loading states)
|
|
||||||
|
|
||||||
### Phase 3: Layout System Refactor ⭐ **CRITICAL FIX**
|
|
||||||
- [x] Switch from pane-scrolling to document-scrolling
|
|
||||||
- [x] Make sidebars sticky on desktop (`position: sticky`)
|
|
||||||
- [x] Update `app.css` to remove fixed container heights
|
|
||||||
- [x] Update `ThreePaneLayout.tsx` to use window scroll
|
|
||||||
- [x] Fix reading position tracking to work with document scroll
|
|
||||||
- [x] Maintain mobile overlay behavior
|
|
||||||
|
|
||||||
### Phase 4: Component Migrations
|
|
||||||
- [x] **ReadingProgressIndicator**: Full Tailwind conversion
|
|
||||||
- Removed 80+ lines of CSS
|
|
||||||
- Added shimmer animation to Tailwind config
|
|
||||||
- Z-index layering maintained (1102)
|
|
||||||
|
|
||||||
- [x] **Mobile UI Elements**: Tailwind utilities
|
|
||||||
- Mobile hamburger button
|
|
||||||
- Mobile highlights button
|
|
||||||
- Mobile backdrop
|
|
||||||
- Removed 60+ lines of CSS
|
|
||||||
|
|
||||||
- [x] **App Container**: Tailwind utilities
|
|
||||||
- Responsive padding (p-0 md:p-4)
|
|
||||||
- Min-height viewport support
|
|
||||||
|
|
||||||
## 📊 Impact & Metrics
|
|
||||||
|
|
||||||
### Lines of CSS Removed
|
|
||||||
- `global.css`: ~50 lines removed
|
|
||||||
- `reader.css`: ~80 lines removed (progress indicator)
|
|
||||||
- `app.css`: ~30 lines removed (mobile buttons/backdrop)
|
|
||||||
- `sidebar.css`: ~30 lines removed (mobile hamburger)
|
|
||||||
- **Total**: ~190 lines removed
|
|
||||||
|
|
||||||
### Key Achievements
|
|
||||||
1. **Fixed Core Issue**: Reading position tracking now works correctly with document scroll
|
|
||||||
2. **Tailwind Integration**: Fully functional with preflight enabled
|
|
||||||
3. **No Breaking Changes**: All existing functionality preserved
|
|
||||||
4. **Type Safety**: TypeScript checks passing
|
|
||||||
5. **Lint Clean**: ESLint checks passing
|
|
||||||
6. **Responsive**: Mobile/tablet/desktop layouts working
|
|
||||||
|
|
||||||
## 🔄 Remaining Work (Incremental)
|
|
||||||
|
|
||||||
The following migrations are **optional enhancements** that can be done as components are touched:
|
|
||||||
|
|
||||||
### High-Value Components
|
|
||||||
- [ ] **ContentPanel** - Large component, high impact
|
|
||||||
- Reader header, meta info, loading states
|
|
||||||
- Mark as read button
|
|
||||||
- Article/video menus
|
|
||||||
|
|
||||||
- [ ] **BookmarkList & BookmarkItem** - Core UI
|
|
||||||
- Card layouts (compact/cards/large views)
|
|
||||||
- Bookmark metadata display
|
|
||||||
- Interactive states
|
|
||||||
|
|
||||||
- [ ] **HighlightsPanel** - Feature-rich
|
|
||||||
- Header with toggles
|
|
||||||
- Highlight items
|
|
||||||
- Level-based styling
|
|
||||||
|
|
||||||
- [ ] **Settings Components** - Forms & controls
|
|
||||||
- Color pickers
|
|
||||||
- Font selectors
|
|
||||||
- Toggle switches
|
|
||||||
- Sliders
|
|
||||||
|
|
||||||
### CSS Files to Prune
|
|
||||||
- `src/index.css` - Contains many inline bookmark/highlight styles (~3000+ lines)
|
|
||||||
- `src/styles/components/cards.css` - Bookmark card styles
|
|
||||||
- `src/styles/components/modals.css` - Modal dialogs
|
|
||||||
- `src/styles/layout/highlights.css` - Highlight panel layout
|
|
||||||
|
|
||||||
## 🎯 Migration Strategy
|
|
||||||
|
|
||||||
### For New Components
|
|
||||||
Use Tailwind utilities from the start. Reference:
|
|
||||||
```tsx
|
|
||||||
// Good: Tailwind utilities
|
|
||||||
<div className="flex items-center gap-2 p-4 bg-gray-800 rounded-lg">
|
|
||||||
|
|
||||||
// Avoid: New CSS classes
|
|
||||||
<div className="custom-component">
|
|
||||||
```
|
|
||||||
|
|
||||||
### For Existing Components
|
|
||||||
Migrate incrementally when touching files:
|
|
||||||
1. Replace layout utilities (flex, grid, spacing, sizing)
|
|
||||||
2. Replace color/background utilities
|
|
||||||
3. Replace typography utilities
|
|
||||||
4. Replace responsive variants
|
|
||||||
5. Remove old CSS rules
|
|
||||||
6. Keep file under 210 lines
|
|
||||||
|
|
||||||
### CSS Variable Usage
|
|
||||||
Dynamic values should still use CSS variables or inline styles:
|
|
||||||
```tsx
|
|
||||||
// User-settable colors
|
|
||||||
style={{ backgroundColor: settings.highlightColorMine }}
|
|
||||||
|
|
||||||
// Or reference CSS variable
|
|
||||||
className="bg-[var(--highlight-color-mine)]"
|
|
||||||
```
|
|
||||||
|
|
||||||
## 📝 Technical Notes
|
|
||||||
|
|
||||||
### Z-Index Layering
|
|
||||||
- Mobile sidepanes: `z-[1001]`
|
|
||||||
- Mobile backdrop: `z-[999]`
|
|
||||||
- Progress indicator: `z-[1102]`
|
|
||||||
- Mobile buttons: `z-[900]`
|
|
||||||
- Relay status: `z-[999]`
|
|
||||||
- Modals: `z-[10000]`
|
|
||||||
|
|
||||||
### Responsive Breakpoints
|
|
||||||
- Mobile: `< 768px`
|
|
||||||
- Tablet: `768px - 1024px`
|
|
||||||
- Desktop: `> 1024px`
|
|
||||||
|
|
||||||
Use Tailwind: `md:` (768px), `lg:` (1024px)
|
|
||||||
|
|
||||||
### Safe Area Insets
|
|
||||||
Mobile notch support:
|
|
||||||
```tsx
|
|
||||||
style={{
|
|
||||||
top: 'calc(1rem + env(safe-area-inset-top))',
|
|
||||||
left: 'calc(1rem + env(safe-area-inset-left))'
|
|
||||||
}}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Custom Animations
|
|
||||||
Add to `tailwind.config.js`:
|
|
||||||
```js
|
|
||||||
keyframes: {
|
|
||||||
shimmer: {
|
|
||||||
'0%': { transform: 'translateX(-100%)' },
|
|
||||||
'100%': { transform: 'translateX(100%)' },
|
|
||||||
},
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## ✅ Success Criteria Met
|
|
||||||
|
|
||||||
- [x] Tailwind CSS fully integrated and functional
|
|
||||||
- [x] Document scrolling working correctly
|
|
||||||
- [x] Reading position tracking accurate
|
|
||||||
- [x] Progress indicator always visible
|
|
||||||
- [x] No TypeScript errors
|
|
||||||
- [x] No linting errors
|
|
||||||
- [x] Mobile responsiveness maintained
|
|
||||||
- [x] Theme colors (user settings) working
|
|
||||||
- [x] All existing features functional
|
|
||||||
|
|
||||||
## 🚀 Next Steps
|
|
||||||
|
|
||||||
1. **Ship It**: Current state is production-ready
|
|
||||||
2. **Incremental Migration**: Convert components as you touch them
|
|
||||||
3. **Monitor**: Watch for any CSS conflicts
|
|
||||||
4. **Cleanup**: Eventually remove unused CSS files
|
|
||||||
5. **Document**: Update component docs with Tailwind patterns
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Status**: ✅ **CORE MIGRATION COMPLETE**
|
|
||||||
**Date**: 2025-01-14
|
|
||||||
**Commits**: 8 conventional commits
|
|
||||||
**Lines Removed**: ~190 lines of CSS
|
|
||||||
**Breaking Changes**: None
|
|
||||||
|
|
||||||
@@ -4,6 +4,7 @@ import { nip19 } from 'nostr-tools'
|
|||||||
import { AddressPointer } from 'nostr-tools/nip19'
|
import { AddressPointer } from 'nostr-tools/nip19'
|
||||||
import { NostrEvent, Filter } from 'nostr-tools'
|
import { NostrEvent, Filter } from 'nostr-tools'
|
||||||
import { Helpers } from 'applesauce-core'
|
import { Helpers } from 'applesauce-core'
|
||||||
|
import { extractProfileDisplayName } from '../src/utils/profileUtils'
|
||||||
|
|
||||||
const { getArticleTitle, getArticleImage, getArticleSummary } = Helpers
|
const { getArticleTitle, getArticleImage, getArticleSummary } = Helpers
|
||||||
|
|
||||||
@@ -117,14 +118,14 @@ async function fetchArticleMetadata(naddr: string): Promise<ArticleMetadata | nu
|
|||||||
const summary = getArticleSummary(article) || 'Read this article on Boris'
|
const summary = getArticleSummary(article) || 'Read this article on Boris'
|
||||||
const image = getArticleImage(article) || '/boris-social-1200.png'
|
const image = getArticleImage(article) || '/boris-social-1200.png'
|
||||||
|
|
||||||
// Extract author name from profile
|
// Extract author name from profile using centralized utility
|
||||||
let authorName = pointer.pubkey.slice(0, 8) + '...'
|
let authorName = pointer.pubkey.slice(0, 8) + '...'
|
||||||
if (profileEvents.length > 0) {
|
if (profileEvents.length > 0) {
|
||||||
try {
|
const displayName = extractProfileDisplayName(profileEvents[0])
|
||||||
const profileData = JSON.parse(profileEvents[0].content)
|
if (displayName && !displayName.startsWith('@')) {
|
||||||
authorName = profileData.display_name || profileData.name || authorName
|
authorName = displayName
|
||||||
} catch {
|
} else if (displayName) {
|
||||||
// Use fallback
|
authorName = displayName.substring(1) // Remove @ prefix
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +148,7 @@ function generateHtml(naddr: string, meta: ArticleMetadata | null): string {
|
|||||||
const baseUrl = 'https://read.withboris.com'
|
const baseUrl = 'https://read.withboris.com'
|
||||||
const articleUrl = `${baseUrl}/a/${naddr}`
|
const articleUrl = `${baseUrl}/a/${naddr}`
|
||||||
|
|
||||||
const title = meta?.title || 'Boris – Nostr Bookmarks'
|
const title = meta?.title || 'Boris – Read, Highlight, Explore'
|
||||||
const description = meta?.summary || 'Your reading list for the Nostr world. A minimal nostr client for bookmark management with highlights.'
|
const description = meta?.summary || 'Your reading list for the Nostr world. A minimal nostr client for bookmark management with highlights.'
|
||||||
const image = meta?.image?.startsWith('http') ? meta.image : `${baseUrl}${meta?.image || '/boris-social-1200.png'}`
|
const image = meta?.image?.startsWith('http') ? meta.image : `${baseUrl}${meta?.image || '/boris-social-1200.png'}`
|
||||||
const author = meta?.author || 'Boris'
|
const author = meta?.author || 'Boris'
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ async function pickCaptions(videoID: string, preferredLangs: string[], manualFir
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getVimeoMetadata(videoId: string): Promise<{ title: string; description: string }> {
|
async function getVimeoMetadata(videoId: string): Promise<{ title: string; description: string; thumbnail_url?: string }> {
|
||||||
const vimeoUrl = `https://vimeo.com/${videoId}`
|
const vimeoUrl = `https://vimeo.com/${videoId}`
|
||||||
const oembedUrl = `https://vimeo.com/api/oembed.json?url=${encodeURIComponent(vimeoUrl)}`
|
const oembedUrl = `https://vimeo.com/api/oembed.json?url=${encodeURIComponent(vimeoUrl)}`
|
||||||
|
|
||||||
@@ -107,7 +107,8 @@ async function getVimeoMetadata(videoId: string): Promise<{ title: string; descr
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
title: data.title || '',
|
title: data.title || '',
|
||||||
description: data.description || ''
|
description: data.description || '',
|
||||||
|
thumbnail_url: data.thumbnail_url || ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,9 +148,28 @@ export default async function handler(req: VercelRequest, res: VercelResponse) {
|
|||||||
try {
|
try {
|
||||||
if (videoInfo.source === 'youtube') {
|
if (videoInfo.source === 'youtube') {
|
||||||
// YouTube handling
|
// YouTube handling
|
||||||
// Note: getVideoDetails doesn't exist in the library, so we use a simplified approach
|
// Fetch basic metadata from YouTube page
|
||||||
const title = ''
|
let title = ''
|
||||||
const description = ''
|
let description = ''
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`https://www.youtube.com/watch?v=${videoInfo.id}`)
|
||||||
|
if (response.ok) {
|
||||||
|
const html = await response.text()
|
||||||
|
// Extract title from HTML
|
||||||
|
const titleMatch = html.match(/<title>([^<]+)<\/title>/)
|
||||||
|
if (titleMatch) {
|
||||||
|
title = titleMatch[1].replace(' - YouTube', '').trim()
|
||||||
|
}
|
||||||
|
// Extract description from meta tag
|
||||||
|
const descMatch = html.match(/<meta name="description" content="([^"]+)"/)
|
||||||
|
if (descMatch) {
|
||||||
|
description = descMatch[1].trim()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Failed to fetch YouTube metadata:', error)
|
||||||
|
}
|
||||||
|
|
||||||
// Language order: manual en -> uiLocale -> lang -> any manual, then auto with same order
|
// Language order: manual en -> uiLocale -> lang -> any manual, then auto with same order
|
||||||
const langs: string[] = Array.from(new Set(['en', uiLocale, lang].filter(Boolean) as string[]))
|
const langs: string[] = Array.from(new Set(['en', uiLocale, lang].filter(Boolean) as string[]))
|
||||||
@@ -178,11 +198,12 @@ export default async function handler(req: VercelRequest, res: VercelResponse) {
|
|||||||
return ok(res, response)
|
return ok(res, response)
|
||||||
} else if (videoInfo.source === 'vimeo') {
|
} else if (videoInfo.source === 'vimeo') {
|
||||||
// Vimeo handling
|
// Vimeo handling
|
||||||
const { title, description } = await getVimeoMetadata(videoInfo.id)
|
const { title, description, thumbnail_url } = await getVimeoMetadata(videoInfo.id)
|
||||||
|
|
||||||
const response = {
|
const response = {
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
|
thumbnail_url,
|
||||||
captions: [], // Vimeo doesn't provide captions through oEmbed API
|
captions: [], // Vimeo doesn't provide captions through oEmbed API
|
||||||
transcript: '', // No transcript available
|
transcript: '', // No transcript available
|
||||||
lang: 'en', // Default language
|
lang: 'en', // Default language
|
||||||
|
|||||||
@@ -63,10 +63,28 @@ export default async function handler(req: VercelRequest, res: VercelResponse) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Since getVideoDetails doesn't exist, we'll use a simple approach
|
// Fetch basic metadata from YouTube page
|
||||||
// In a real implementation, you might want to use YouTube's API or other methods
|
let title = ''
|
||||||
const title = '' // Will be populated from captions or other sources
|
let description = ''
|
||||||
const description = ''
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`https://www.youtube.com/watch?v=${videoId}`)
|
||||||
|
if (response.ok) {
|
||||||
|
const html = await response.text()
|
||||||
|
// Extract title from HTML
|
||||||
|
const titleMatch = html.match(/<title>([^<]+)<\/title>/)
|
||||||
|
if (titleMatch) {
|
||||||
|
title = titleMatch[1].replace(' - YouTube', '').trim()
|
||||||
|
}
|
||||||
|
// Extract description from meta tag
|
||||||
|
const descMatch = html.match(/<meta name="description" content="([^"]+)"/)
|
||||||
|
if (descMatch) {
|
||||||
|
description = descMatch[1].trim()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Failed to fetch YouTube metadata:', error)
|
||||||
|
}
|
||||||
|
|
||||||
// Language order: manual en -> uiLocale -> lang -> any manual, then auto with same order
|
// Language order: manual en -> uiLocale -> lang -> any manual, then auto with same order
|
||||||
const langs: string[] = Array.from(new Set(['en', uiLocale, lang].filter(Boolean) as string[]))
|
const langs: string[] = Array.from(new Set(['en', uiLocale, lang].filter(Boolean) as string[]))
|
||||||
|
|||||||
@@ -9,14 +9,14 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
||||||
<meta name="theme-color" content="#0f172a" />
|
<meta name="theme-color" content="#0f172a" />
|
||||||
<link rel="manifest" href="/manifest.webmanifest" />
|
<link rel="manifest" href="/manifest.webmanifest" />
|
||||||
<title>Boris - Nostr Bookmarks</title>
|
<title>Boris - Read, Highlight, Explore</title>
|
||||||
<meta name="description" content="Your reading list for the Nostr world. A minimal nostr client for bookmark management with highlights." />
|
<meta name="description" content="Your reading list for the Nostr world. A minimal nostr client for bookmark management with highlights." />
|
||||||
<link rel="canonical" href="https://read.withboris.com/" />
|
<link rel="canonical" href="https://read.withboris.com/" />
|
||||||
|
|
||||||
<!-- Open Graph / Social Media -->
|
<!-- Open Graph / Social Media -->
|
||||||
<meta property="og:type" content="website" />
|
<meta property="og:type" content="website" />
|
||||||
<meta property="og:url" content="https://read.withboris.com/" />
|
<meta property="og:url" content="https://read.withboris.com/" />
|
||||||
<meta property="og:title" content="Boris - Nostr Bookmarks" />
|
<meta property="og:title" content="Boris - Read, Highlight, Explore" />
|
||||||
<meta property="og:description" content="Your reading list for the Nostr world. A minimal nostr client for bookmark management with highlights." />
|
<meta property="og:description" content="Your reading list for the Nostr world. A minimal nostr client for bookmark management with highlights." />
|
||||||
<meta property="og:image" content="https://read.withboris.com/boris-social-1200.png" />
|
<meta property="og:image" content="https://read.withboris.com/boris-social-1200.png" />
|
||||||
<meta property="og:site_name" content="Boris" />
|
<meta property="og:site_name" content="Boris" />
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
<!-- Twitter Card -->
|
<!-- Twitter Card -->
|
||||||
<meta name="twitter:card" content="summary_large_image" />
|
<meta name="twitter:card" content="summary_large_image" />
|
||||||
<meta name="twitter:url" content="https://read.withboris.com/" />
|
<meta name="twitter:url" content="https://read.withboris.com/" />
|
||||||
<meta name="twitter:title" content="Boris - Nostr Bookmarks" />
|
<meta name="twitter:title" content="Boris - Read, Highlight, Explore" />
|
||||||
<meta name="twitter:description" content="Your reading list for the Nostr world. A minimal nostr client for bookmark management with highlights." />
|
<meta name="twitter:description" content="Your reading list for the Nostr world. A minimal nostr client for bookmark management with highlights." />
|
||||||
<meta name="twitter:image" content="https://read.withboris.com/boris-social-1200.png" />
|
<meta name="twitter:image" content="https://read.withboris.com/boris-social-1200.png" />
|
||||||
|
|
||||||
|
|||||||
60
package-lock.json
generated
60
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "boris",
|
"name": "boris",
|
||||||
"version": "0.10.5",
|
"version": "0.10.23",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "boris",
|
"name": "boris",
|
||||||
"version": "0.10.5",
|
"version": "0.10.23",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fortawesome/fontawesome-svg-core": "^7.1.0",
|
"@fortawesome/fontawesome-svg-core": "^7.1.0",
|
||||||
"@fortawesome/free-regular-svg-icons": "^7.1.0",
|
"@fortawesome/free-regular-svg-icons": "^7.1.0",
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
"applesauce-relay": "^4.0.0",
|
"applesauce-relay": "^4.0.0",
|
||||||
"date-fns": "^4.1.0",
|
"date-fns": "^4.1.0",
|
||||||
"fast-average-color": "^9.5.0",
|
"fast-average-color": "^9.5.0",
|
||||||
|
"fetch-opengraph": "^1.0.36",
|
||||||
"nostr-tools": "^2.4.0",
|
"nostr-tools": "^2.4.0",
|
||||||
"prismjs": "^1.30.0",
|
"prismjs": "^1.30.0",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
@@ -4502,6 +4503,15 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/axios": {
|
||||||
|
"version": "0.21.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz",
|
||||||
|
"integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"follow-redirects": "^1.14.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/babel-plugin-polyfill-corejs2": {
|
"node_modules/babel-plugin-polyfill-corejs2": {
|
||||||
"version": "0.4.14",
|
"version": "0.4.14",
|
||||||
"resolved": "https://registry.npmjs.org/babel-plugin-polyfill-corejs2/-/babel-plugin-polyfill-corejs2-0.4.14.tgz",
|
"resolved": "https://registry.npmjs.org/babel-plugin-polyfill-corejs2/-/babel-plugin-polyfill-corejs2-0.4.14.tgz",
|
||||||
@@ -6171,6 +6181,16 @@
|
|||||||
"reusify": "^1.0.4"
|
"reusify": "^1.0.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/fetch-opengraph": {
|
||||||
|
"version": "1.0.36",
|
||||||
|
"resolved": "https://registry.npmjs.org/fetch-opengraph/-/fetch-opengraph-1.0.36.tgz",
|
||||||
|
"integrity": "sha512-w2Gs64zjL1O86E0I6E26MrxeXpTrR8Y1vWrgupmZN6NXKV8F5I3W0tlh+ZX686jZwxyilWnQjYwgnWpdETdHWw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"axios": "^0.21.1",
|
||||||
|
"html-entities": "^2.3.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/file-entry-cache": {
|
"node_modules/file-entry-cache": {
|
||||||
"version": "6.0.1",
|
"version": "6.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz",
|
||||||
@@ -6264,6 +6284,26 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
|
"node_modules/follow-redirects": {
|
||||||
|
"version": "1.15.11",
|
||||||
|
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.11.tgz",
|
||||||
|
"integrity": "sha512-deG2P0JfjrTxl50XGCDyfI97ZGVCxIpfKYmfyrQ54n5FO/0gfIES8C/Psl6kWVDolizcaaxZJnTS0QSMxvnsBQ==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "individual",
|
||||||
|
"url": "https://github.com/sponsors/RubenVerborgh"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"debug": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/for-each": {
|
"node_modules/for-each": {
|
||||||
"version": "0.3.5",
|
"version": "0.3.5",
|
||||||
"resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.5.tgz",
|
"resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.5.tgz",
|
||||||
@@ -6896,6 +6936,22 @@
|
|||||||
"he": "bin/he"
|
"he": "bin/he"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/html-entities": {
|
||||||
|
"version": "2.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/html-entities/-/html-entities-2.6.0.tgz",
|
||||||
|
"integrity": "sha512-kig+rMn/QOVRvr7c86gQ8lWXq+Hkv6CbAH1hLu+RG338StTpE8Z0b44SDVaqVu7HGKf27frdmUYEs9hTUX/cLQ==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/mdevils"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "patreon",
|
||||||
|
"url": "https://patreon.com/mdevils"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/html-url-attributes": {
|
"node_modules/html-url-attributes": {
|
||||||
"version": "3.0.1",
|
"version": "3.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/html-url-attributes/-/html-url-attributes-3.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/html-url-attributes/-/html-url-attributes-3.0.1.tgz",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "boris",
|
"name": "boris",
|
||||||
"version": "0.10.7",
|
"version": "0.10.33",
|
||||||
"description": "A minimal nostr client for bookmark management",
|
"description": "A minimal nostr client for bookmark management",
|
||||||
"homepage": "https://read.withboris.com/",
|
"homepage": "https://read.withboris.com/",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
"applesauce-relay": "^4.0.0",
|
"applesauce-relay": "^4.0.0",
|
||||||
"date-fns": "^4.1.0",
|
"date-fns": "^4.1.0",
|
||||||
"fast-average-color": "^9.5.0",
|
"fast-average-color": "^9.5.0",
|
||||||
|
"fetch-opengraph": "^1.0.36",
|
||||||
"nostr-tools": "^2.4.0",
|
"nostr-tools": "^2.4.0",
|
||||||
"prismjs": "^1.30.0",
|
"prismjs": "^1.30.0",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "Boris - Nostr Bookmarks",
|
"name": "Boris - Read, Highlight, Explore",
|
||||||
"short_name": "Boris",
|
"short_name": "Boris",
|
||||||
"description": "Your reading list for the Nostr world. A minimal nostr client for bookmark management with highlights.",
|
"description": "Your reading list for the Nostr world. A minimal nostr client for bookmark management with highlights.",
|
||||||
"start_url": "/",
|
"start_url": "/",
|
||||||
|
|||||||
47
public/sw-dev.js
Normal file
47
public/sw-dev.js
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
// Development Service Worker - simplified version for testing image caching
|
||||||
|
// This is served in dev mode when vite-plugin-pwa doesn't serve the injectManifest SW
|
||||||
|
|
||||||
|
self.addEventListener('install', (event) => {
|
||||||
|
self.skipWaiting()
|
||||||
|
})
|
||||||
|
|
||||||
|
self.addEventListener('activate', (event) => {
|
||||||
|
event.waitUntil(clients.claim())
|
||||||
|
})
|
||||||
|
|
||||||
|
// Image caching - simple version for dev testing
|
||||||
|
self.addEventListener('fetch', (event) => {
|
||||||
|
const url = new URL(event.request.url)
|
||||||
|
const isImage = event.request.destination === 'image' ||
|
||||||
|
/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(url.pathname)
|
||||||
|
|
||||||
|
if (isImage) {
|
||||||
|
event.respondWith(
|
||||||
|
caches.open('boris-images-dev').then((cache) => {
|
||||||
|
return cache.match(event.request).then((cachedResponse) => {
|
||||||
|
// Try to fetch from network
|
||||||
|
return fetch(event.request).then((response) => {
|
||||||
|
// If fetch succeeds, cache it and return
|
||||||
|
if (response.ok) {
|
||||||
|
cache.put(event.request, response.clone()).catch(() => {
|
||||||
|
// Ignore cache put errors
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return response
|
||||||
|
}).catch((error) => {
|
||||||
|
// If fetch fails (network error, CORS, etc.), return cached response if available
|
||||||
|
if (cachedResponse) {
|
||||||
|
return cachedResponse
|
||||||
|
}
|
||||||
|
// No cache available, reject the promise so browser handles it
|
||||||
|
return Promise.reject(error)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}).catch(() => {
|
||||||
|
// If cache operations fail, try to fetch directly without caching
|
||||||
|
return fetch(event.request)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
20
src/App.tsx
20
src/App.tsx
@@ -237,11 +237,11 @@ function AppRoutes({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="/me"
|
path="/my"
|
||||||
element={<Navigate to="/me/highlights" replace />}
|
element={<Navigate to="/my/highlights" replace />}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="/me/highlights"
|
path="/my/highlights"
|
||||||
element={
|
element={
|
||||||
<Bookmarks
|
<Bookmarks
|
||||||
relayPool={relayPool}
|
relayPool={relayPool}
|
||||||
@@ -253,7 +253,7 @@ function AppRoutes({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="/me/reading-list"
|
path="/my/bookmarks"
|
||||||
element={
|
element={
|
||||||
<Bookmarks
|
<Bookmarks
|
||||||
relayPool={relayPool}
|
relayPool={relayPool}
|
||||||
@@ -265,7 +265,7 @@ function AppRoutes({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="/me/reads"
|
path="/my/reads"
|
||||||
element={
|
element={
|
||||||
<Bookmarks
|
<Bookmarks
|
||||||
relayPool={relayPool}
|
relayPool={relayPool}
|
||||||
@@ -277,7 +277,7 @@ function AppRoutes({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="/me/reads/:filter"
|
path="/my/reads/:filter"
|
||||||
element={
|
element={
|
||||||
<Bookmarks
|
<Bookmarks
|
||||||
relayPool={relayPool}
|
relayPool={relayPool}
|
||||||
@@ -289,7 +289,7 @@ function AppRoutes({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="/me/links"
|
path="/my/links"
|
||||||
element={
|
element={
|
||||||
<Bookmarks
|
<Bookmarks
|
||||||
relayPool={relayPool}
|
relayPool={relayPool}
|
||||||
@@ -301,7 +301,7 @@ function AppRoutes({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="/me/links/:filter"
|
path="/my/links/:filter"
|
||||||
element={
|
element={
|
||||||
<Bookmarks
|
<Bookmarks
|
||||||
relayPool={relayPool}
|
relayPool={relayPool}
|
||||||
@@ -313,7 +313,7 @@ function AppRoutes({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="/me/writings"
|
path="/my/writings"
|
||||||
element={
|
element={
|
||||||
<Bookmarks
|
<Bookmarks
|
||||||
relayPool={relayPool}
|
relayPool={relayPool}
|
||||||
@@ -578,8 +578,6 @@ function App() {
|
|||||||
|
|
||||||
// Handle user relay list and blocked relays when account changes
|
// Handle user relay list and blocked relays when account changes
|
||||||
const userRelaysSub = accounts.active$.subscribe((account) => {
|
const userRelaysSub = accounts.active$.subscribe((account) => {
|
||||||
console.log('[relay-init] userRelaysSub fired, account:', account ? 'logged in' : 'logged out')
|
|
||||||
console.log('[relay-init] Pool has', Array.from(pool.relays.keys()).length, 'relays before applying changes')
|
|
||||||
if (account) {
|
if (account) {
|
||||||
// User logged in - start with hardcoded relays immediately, then stream user relay list updates
|
// User logged in - start with hardcoded relays immediately, then stream user relay list updates
|
||||||
const pubkey = account.pubkey
|
const pubkey = account.pubkey
|
||||||
|
|||||||
@@ -4,41 +4,40 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
|||||||
import { faTimes, faSpinner } from '@fortawesome/free-solid-svg-icons'
|
import { faTimes, faSpinner } from '@fortawesome/free-solid-svg-icons'
|
||||||
import IconButton from './IconButton'
|
import IconButton from './IconButton'
|
||||||
import { fetchReadableContent } from '../services/readerService'
|
import { fetchReadableContent } from '../services/readerService'
|
||||||
|
import { fetch as fetchOpenGraph } from 'fetch-opengraph'
|
||||||
|
|
||||||
interface AddBookmarkModalProps {
|
interface AddBookmarkModalProps {
|
||||||
onClose: () => void
|
onClose: () => void
|
||||||
onSave: (url: string, title?: string, description?: string, tags?: string[]) => Promise<void>
|
onSave: (url: string, title?: string, description?: string, tags?: string[]) => Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper to extract metadata from HTML
|
// Helper to extract tags from OpenGraph data
|
||||||
function extractMetaTag(html: string, patterns: string[]): string | null {
|
function extractTagsFromOgData(ogData: Record<string, unknown>): string[] {
|
||||||
for (const pattern of patterns) {
|
|
||||||
const match = html.match(new RegExp(pattern, 'i'))
|
|
||||||
if (match) return match[1]
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
function extractTags(html: string): string[] {
|
|
||||||
const tags: string[] = []
|
const tags: string[] = []
|
||||||
|
|
||||||
// Extract keywords meta tag
|
// Extract keywords from OpenGraph data
|
||||||
const keywords = extractMetaTag(html, [
|
if (ogData.keywords && typeof ogData.keywords === 'string') {
|
||||||
'<meta\\s+name=["\'"]keywords["\'"]\\s+content=["\'"]([^"\']+)["\']'
|
ogData.keywords.split(/[,;]/)
|
||||||
])
|
.map((k: string) => k.trim().toLowerCase())
|
||||||
if (keywords) {
|
.filter((k: string) => k.length > 0 && k.length < 30)
|
||||||
keywords.split(/[,;]/)
|
.forEach((k: string) => tags.push(k))
|
||||||
.map(k => k.trim().toLowerCase())
|
|
||||||
.filter(k => k.length > 0 && k.length < 30)
|
|
||||||
.forEach(k => tags.push(k))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract article:tag (multiple possible)
|
// Extract article:tag from OpenGraph data
|
||||||
const articleTagRegex = /<meta\s+property=["']article:tag["']\s+content=["']([^"']+)["']/gi
|
if (ogData['article:tag']) {
|
||||||
let match
|
const articleTagValue = ogData['article:tag']
|
||||||
while ((match = articleTagRegex.exec(html)) !== null) {
|
const articleTags = Array.isArray(articleTagValue)
|
||||||
const tag = match[1].trim().toLowerCase()
|
? articleTagValue
|
||||||
if (tag && tag.length < 30) tags.push(tag)
|
: [articleTagValue]
|
||||||
|
|
||||||
|
articleTags.forEach((tag: unknown) => {
|
||||||
|
if (typeof tag === 'string') {
|
||||||
|
const cleanTag = tag.trim().toLowerCase()
|
||||||
|
if (cleanTag && cleanTag.length < 30) {
|
||||||
|
tags.push(cleanTag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return Array.from(new Set(tags)).slice(0, 5)
|
return Array.from(new Set(tags)).slice(0, 5)
|
||||||
@@ -83,17 +82,27 @@ const AddBookmarkModal: React.FC<AddBookmarkModalProps> = ({ onClose, onSave })
|
|||||||
fetchTimeoutRef.current = window.setTimeout(async () => {
|
fetchTimeoutRef.current = window.setTimeout(async () => {
|
||||||
setIsFetchingMetadata(true)
|
setIsFetchingMetadata(true)
|
||||||
try {
|
try {
|
||||||
const content = await fetchReadableContent(normalizedUrl)
|
// Fetch both readable content and OpenGraph data in parallel
|
||||||
lastFetchedUrlRef.current = normalizedUrl
|
const [content, ogData] = await Promise.all([
|
||||||
|
fetchReadableContent(normalizedUrl),
|
||||||
|
fetchOpenGraph(normalizedUrl).catch(() => null) // Don't fail if OpenGraph fetch fails
|
||||||
|
])
|
||||||
|
|
||||||
|
lastFetchedUrlRef.current = normalizedUrl
|
||||||
let extractedAnything = false
|
let extractedAnything = false
|
||||||
|
|
||||||
// Extract title: prioritize og:title > twitter:title > <title>
|
// Extract title: prioritize og:title > twitter:title > content.title
|
||||||
if (!title && content.html) {
|
if (!title) {
|
||||||
const extractedTitle = extractMetaTag(content.html, [
|
let extractedTitle = null
|
||||||
'<meta\\s+property=["\'"]og:title["\'"]\\s+content=["\'"]([^"\']+)["\']',
|
|
||||||
'<meta\\s+name=["\'"]twitter:title["\'"]\\s+content=["\'"]([^"\']+)["\']'
|
if (ogData) {
|
||||||
]) || content.title
|
extractedTitle = ogData['og:title'] || ogData['twitter:title'] || ogData.title
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to content.title if no OpenGraph title found
|
||||||
|
if (!extractedTitle) {
|
||||||
|
extractedTitle = content.title
|
||||||
|
}
|
||||||
|
|
||||||
if (extractedTitle) {
|
if (extractedTitle) {
|
||||||
setTitle(extractedTitle)
|
setTitle(extractedTitle)
|
||||||
@@ -102,12 +111,8 @@ const AddBookmarkModal: React.FC<AddBookmarkModalProps> = ({ onClose, onSave })
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Extract description: prioritize og:description > twitter:description > meta description
|
// Extract description: prioritize og:description > twitter:description > meta description
|
||||||
if (!description && content.html) {
|
if (!description && ogData) {
|
||||||
const extractedDesc = extractMetaTag(content.html, [
|
const extractedDesc = ogData['og:description'] || ogData['twitter:description'] || ogData.description
|
||||||
'<meta\\s+property=["\'"]og:description["\'"]\\s+content=["\'"]([^"\']+)["\']',
|
|
||||||
'<meta\\s+name=["\'"]twitter:description["\'"]\\s+content=["\'"]([^"\']+)["\']',
|
|
||||||
'<meta\\s+name=["\'"]description["\'"]\\s+content=["\'"]([^"\']+)["\']'
|
|
||||||
])
|
|
||||||
|
|
||||||
if (extractedDesc) {
|
if (extractedDesc) {
|
||||||
setDescription(extractedDesc)
|
setDescription(extractedDesc)
|
||||||
@@ -116,8 +121,8 @@ const AddBookmarkModal: React.FC<AddBookmarkModalProps> = ({ onClose, onSave })
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Extract tags from keywords and article:tag (only if user hasn't modified tags)
|
// Extract tags from keywords and article:tag (only if user hasn't modified tags)
|
||||||
if (!tagsInput && content.html) {
|
if (!tagsInput && ogData) {
|
||||||
const extractedTags = extractTags(content.html)
|
const extractedTags = extractTagsFromOgData(ogData)
|
||||||
|
|
||||||
// Only add boris tag if we extracted something
|
// Only add boris tag if we extracted something
|
||||||
if (extractedAnything || extractedTags.length > 0) {
|
if (extractedAnything || extractedTags.length > 0) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { faUserCircle } from '@fortawesome/free-solid-svg-icons'
|
|||||||
import { useEventModel } from 'applesauce-react/hooks'
|
import { useEventModel } from 'applesauce-react/hooks'
|
||||||
import { Models } from 'applesauce-core'
|
import { Models } from 'applesauce-core'
|
||||||
import { nip19 } from 'nostr-tools'
|
import { nip19 } from 'nostr-tools'
|
||||||
|
import { getProfileDisplayName } from '../utils/nostrUriResolver'
|
||||||
|
|
||||||
interface AuthorCardProps {
|
interface AuthorCardProps {
|
||||||
authorPubkey: string
|
authorPubkey: string
|
||||||
@@ -16,9 +17,7 @@ const AuthorCard: React.FC<AuthorCardProps> = ({ authorPubkey, clickable = true
|
|||||||
const profile = useEventModel(Models.ProfileModel, [authorPubkey])
|
const profile = useEventModel(Models.ProfileModel, [authorPubkey])
|
||||||
|
|
||||||
const getAuthorName = () => {
|
const getAuthorName = () => {
|
||||||
if (profile?.name) return profile.name
|
return getProfileDisplayName(profile, authorPubkey)
|
||||||
if (profile?.display_name) return profile.display_name
|
|
||||||
return `${authorPubkey.slice(0, 8)}...${authorPubkey.slice(-8)}`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const authorImage = profile?.picture || profile?.image
|
const authorImage = profile?.picture || profile?.image
|
||||||
@@ -27,7 +26,7 @@ const AuthorCard: React.FC<AuthorCardProps> = ({ authorPubkey, clickable = true
|
|||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
if (clickable) {
|
if (clickable) {
|
||||||
const npub = nip19.npubEncode(authorPubkey)
|
const npub = nip19.npubEncode(authorPubkey)
|
||||||
navigate(`/p/${npub}`)
|
navigate(`/p/${npub}/writings`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { BlogPostPreview } from '../services/exploreService'
|
|||||||
import { useEventModel } from 'applesauce-react/hooks'
|
import { useEventModel } from 'applesauce-react/hooks'
|
||||||
import { Models } from 'applesauce-core'
|
import { Models } from 'applesauce-core'
|
||||||
import { isKnownBot } from '../config/bots'
|
import { isKnownBot } from '../config/bots'
|
||||||
|
import { getProfileDisplayName } from '../utils/nostrUriResolver'
|
||||||
|
|
||||||
interface BlogPostCardProps {
|
interface BlogPostCardProps {
|
||||||
post: BlogPostPreview
|
post: BlogPostPreview
|
||||||
@@ -18,8 +19,13 @@ interface BlogPostCardProps {
|
|||||||
|
|
||||||
const BlogPostCard: React.FC<BlogPostCardProps> = ({ post, href, level, readingProgress, hideBotByName = true }) => {
|
const BlogPostCard: React.FC<BlogPostCardProps> = ({ post, href, level, readingProgress, hideBotByName = true }) => {
|
||||||
const profile = useEventModel(Models.ProfileModel, [post.author])
|
const profile = useEventModel(Models.ProfileModel, [post.author])
|
||||||
const displayName = profile?.name || profile?.display_name ||
|
|
||||||
`${post.author.slice(0, 8)}...${post.author.slice(-4)}`
|
// Note: Images are lazy-loaded (loading="lazy" below), so they'll be fetched
|
||||||
|
// when they come into view. The Service Worker will cache them automatically.
|
||||||
|
// No need to preload all images at once - this causes ERR_INSUFFICIENT_RESOURCES
|
||||||
|
// when there are many blog posts.
|
||||||
|
|
||||||
|
const displayName = getProfileDisplayName(profile, post.author)
|
||||||
const rawName = (profile?.name || profile?.display_name || '').toLowerCase()
|
const rawName = (profile?.name || profile?.display_name || '').toLowerCase()
|
||||||
|
|
||||||
// Hide bot authors by name/display_name
|
// Hide bot authors by name/display_name
|
||||||
@@ -41,7 +47,7 @@ const BlogPostCard: React.FC<BlogPostCardProps> = ({ post, href, level, readingP
|
|||||||
} else if (readingProgress && readingProgress > 0 && readingProgress <= 0.10) {
|
} else if (readingProgress && readingProgress > 0 && readingProgress <= 0.10) {
|
||||||
progressColor = 'var(--color-text)' // Neutral text color (started)
|
progressColor = 'var(--color-text)' // Neutral text color (started)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debug log - reading progress shown as visual indicator
|
// Debug log - reading progress shown as visual indicator
|
||||||
if (readingProgress !== undefined) {
|
if (readingProgress !== undefined) {
|
||||||
// Reading progress display
|
// Reading progress display
|
||||||
@@ -50,6 +56,14 @@ const BlogPostCard: React.FC<BlogPostCardProps> = ({ post, href, level, readingP
|
|||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
to={href}
|
to={href}
|
||||||
|
state={{
|
||||||
|
previewData: {
|
||||||
|
title: post.title,
|
||||||
|
image: post.image,
|
||||||
|
summary: post.summary,
|
||||||
|
published: post.published
|
||||||
|
}
|
||||||
|
}}
|
||||||
className={`blog-post-card ${level ? `level-${level}` : ''}`}
|
className={`blog-post-card ${level ? `level-${level}` : ''}`}
|
||||||
style={{ textDecoration: 'none', color: 'inherit' }}
|
style={{ textDecoration: 'none', color: 'inherit' }}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
|
import { useNavigate } from 'react-router-dom'
|
||||||
import { faNewspaper, faStickyNote, faCirclePlay, faCamera, faFileLines } from '@fortawesome/free-regular-svg-icons'
|
import { faNewspaper, faStickyNote, faCirclePlay, faCamera, faFileLines } from '@fortawesome/free-regular-svg-icons'
|
||||||
import { faGlobe, faLink } from '@fortawesome/free-solid-svg-icons'
|
import { faGlobe, faLink } from '@fortawesome/free-solid-svg-icons'
|
||||||
import { IconDefinition } from '@fortawesome/fontawesome-svg-core'
|
import { IconDefinition } from '@fortawesome/fontawesome-svg-core'
|
||||||
import { useEventModel } from 'applesauce-react/hooks'
|
import { useEventModel } from 'applesauce-react/hooks'
|
||||||
import { Models } from 'applesauce-core'
|
import { Models } from 'applesauce-core'
|
||||||
import { npubEncode, neventEncode } from 'nostr-tools/nip19'
|
import { npubEncode, naddrEncode } from 'nostr-tools/nip19'
|
||||||
import { IndividualBookmark } from '../types/bookmarks'
|
import { IndividualBookmark } from '../types/bookmarks'
|
||||||
import { extractUrlsFromContent } from '../services/bookmarkHelpers'
|
import { extractUrlsFromContent } from '../services/bookmarkHelpers'
|
||||||
import { classifyUrl } from '../utils/helpers'
|
import { classifyUrl } from '../utils/helpers'
|
||||||
import { ViewMode } from './Bookmarks'
|
import { ViewMode } from './Bookmarks'
|
||||||
import { getPreviewImage, fetchOgImage } from '../utils/imagePreview'
|
import { getPreviewImage, fetchOgImage } from '../utils/imagePreview'
|
||||||
|
import { getProfileDisplayName } from '../utils/nostrUriResolver'
|
||||||
import { CompactView } from './BookmarkViews/CompactView'
|
import { CompactView } from './BookmarkViews/CompactView'
|
||||||
import { LargeView } from './BookmarkViews/LargeView'
|
import { LargeView } from './BookmarkViews/LargeView'
|
||||||
import { CardView } from './BookmarkViews/CardView'
|
import { CardView } from './BookmarkViews/CardView'
|
||||||
@@ -23,6 +25,7 @@ interface BookmarkItemProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const BookmarkItem: React.FC<BookmarkItemProps> = ({ bookmark, index, onSelectUrl, viewMode = 'cards', readingProgress }) => {
|
export const BookmarkItem: React.FC<BookmarkItemProps> = ({ bookmark, index, onSelectUrl, viewMode = 'cards', readingProgress }) => {
|
||||||
|
const navigate = useNavigate()
|
||||||
const [ogImage, setOgImage] = useState<string | null>(null)
|
const [ogImage, setOgImage] = useState<string | null>(null)
|
||||||
|
|
||||||
const short = (v: string) => `${v.slice(0, 8)}...${v.slice(-8)}`
|
const short = (v: string) => `${v.slice(0, 8)}...${v.slice(-8)}`
|
||||||
@@ -40,10 +43,11 @@ export const BookmarkItem: React.FC<BookmarkItemProps> = ({ bookmark, index, onS
|
|||||||
const firstUrl = hasUrls ? extractedUrls[0] : null
|
const firstUrl = hasUrls ? extractedUrls[0] : null
|
||||||
const firstUrlClassification = firstUrl ? classifyUrl(firstUrl) : null
|
const firstUrlClassification = firstUrl ? classifyUrl(firstUrl) : null
|
||||||
|
|
||||||
// For kind:30023 articles, extract image and summary tags (per NIP-23)
|
// For kind:30023 articles, extract title, image and summary tags (per NIP-23)
|
||||||
// Note: We extract directly from tags here since we don't have the full event.
|
// Note: We extract directly from tags here since we don't have the full event.
|
||||||
// When we have full events, we use getArticleImage() helper (see articleService.ts)
|
// When we have full events, we use getArticleImage() helper (see articleService.ts)
|
||||||
const isArticle = bookmark.kind === 30023
|
const isArticle = bookmark.kind === 30023
|
||||||
|
const articleTitle = isArticle ? bookmark.tags.find(t => t[0] === 'title')?.[1] : undefined
|
||||||
const articleImage = isArticle ? bookmark.tags.find(t => t[0] === 'image')?.[1] : undefined
|
const articleImage = isArticle ? bookmark.tags.find(t => t[0] === 'image')?.[1] : undefined
|
||||||
const articleSummary = isArticle ? bookmark.tags.find(t => t[0] === 'summary')?.[1] : undefined
|
const articleSummary = isArticle ? bookmark.tags.find(t => t[0] === 'summary')?.[1] : undefined
|
||||||
|
|
||||||
@@ -58,15 +62,16 @@ export const BookmarkItem: React.FC<BookmarkItemProps> = ({ bookmark, index, onS
|
|||||||
// Resolve author profile using applesauce
|
// Resolve author profile using applesauce
|
||||||
const authorProfile = useEventModel(Models.ProfileModel, [bookmark.pubkey])
|
const authorProfile = useEventModel(Models.ProfileModel, [bookmark.pubkey])
|
||||||
const authorNpub = npubEncode(bookmark.pubkey)
|
const authorNpub = npubEncode(bookmark.pubkey)
|
||||||
const isHexId = /^[0-9a-f]{64}$/i.test(bookmark.id)
|
|
||||||
const eventNevent = isHexId ? neventEncode({ id: bookmark.id }) : undefined
|
|
||||||
|
|
||||||
// Get display name for author
|
// Get display name for author using centralized utility
|
||||||
const getAuthorDisplayName = () => {
|
const getAuthorDisplayName = () => {
|
||||||
if (authorProfile?.name) return authorProfile.name
|
const displayName = getProfileDisplayName(authorProfile, bookmark.pubkey)
|
||||||
if (authorProfile?.display_name) return authorProfile.display_name
|
// getProfileDisplayName returns npub format for fallback, but we want short pubkey format
|
||||||
if (authorProfile?.nip05) return authorProfile.nip05
|
// So check if it's the fallback format and use short() instead
|
||||||
return short(bookmark.pubkey) // fallback to short pubkey
|
if (displayName.startsWith('@') && displayName.includes('...')) {
|
||||||
|
return short(bookmark.pubkey)
|
||||||
|
}
|
||||||
|
return displayName
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get content type icon based on bookmark kind and URL classification
|
// Get content type icon based on bookmark kind and URL classification
|
||||||
@@ -110,10 +115,16 @@ export const BookmarkItem: React.FC<BookmarkItemProps> = ({ bookmark, index, onS
|
|||||||
const handleReadNow = (event: React.MouseEvent<HTMLButtonElement>) => {
|
const handleReadNow = (event: React.MouseEvent<HTMLButtonElement>) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
|
||||||
// For kind:30023 articles, pass the bookmark data instead of URL
|
// For kind:30023 articles, navigate to /a/:naddr route
|
||||||
if (bookmark.kind === 30023) {
|
if (bookmark.kind === 30023) {
|
||||||
if (onSelectUrl) {
|
const dTag = bookmark.tags.find(t => t[0] === 'd')?.[1]
|
||||||
onSelectUrl('', { id: bookmark.id, kind: bookmark.kind, tags: bookmark.tags, pubkey: bookmark.pubkey })
|
if (dTag) {
|
||||||
|
const naddr = naddrEncode({
|
||||||
|
kind: bookmark.kind,
|
||||||
|
pubkey: bookmark.pubkey,
|
||||||
|
identifier: dTag
|
||||||
|
})
|
||||||
|
navigate(`/a/${naddr}`)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -135,7 +146,6 @@ export const BookmarkItem: React.FC<BookmarkItemProps> = ({ bookmark, index, onS
|
|||||||
extractedUrls,
|
extractedUrls,
|
||||||
onSelectUrl,
|
onSelectUrl,
|
||||||
authorNpub,
|
authorNpub,
|
||||||
eventNevent,
|
|
||||||
getAuthorDisplayName,
|
getAuthorDisplayName,
|
||||||
handleReadNow,
|
handleReadNow,
|
||||||
articleImage,
|
articleImage,
|
||||||
@@ -151,11 +161,7 @@ export const BookmarkItem: React.FC<BookmarkItemProps> = ({ bookmark, index, onS
|
|||||||
hasUrls,
|
hasUrls,
|
||||||
extractedUrls,
|
extractedUrls,
|
||||||
onSelectUrl,
|
onSelectUrl,
|
||||||
authorNpub,
|
articleTitle,
|
||||||
eventNevent,
|
|
||||||
getAuthorDisplayName,
|
|
||||||
handleReadNow,
|
|
||||||
articleSummary,
|
|
||||||
contentTypeIcon: getContentTypeIcon(),
|
contentTypeIcon: getContentTypeIcon(),
|
||||||
readingProgress
|
readingProgress
|
||||||
}
|
}
|
||||||
@@ -167,5 +173,5 @@ export const BookmarkItem: React.FC<BookmarkItemProps> = ({ bookmark, index, onS
|
|||||||
return <LargeView {...sharedProps} getIconForUrlType={getIconForUrlType} previewImage={previewImage} />
|
return <LargeView {...sharedProps} getIconForUrlType={getIconForUrlType} previewImage={previewImage} />
|
||||||
}
|
}
|
||||||
|
|
||||||
return <CardView {...sharedProps} articleImage={articleImage} />
|
return <CardView {...sharedProps} articleImage={articleImage} articleTitle={articleTitle} />
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import React, { useRef, useState } from 'react'
|
import React, { useRef, useState, useMemo } from 'react'
|
||||||
import { useNavigate } from 'react-router-dom'
|
import { useNavigate } from 'react-router-dom'
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||||
import { faChevronLeft, faBookmark, faList, faThLarge, faImage, faRotate, faHeart, faPlus, faLayerGroup, faBars } from '@fortawesome/free-solid-svg-icons'
|
import { faChevronLeft, faBookmark, faList, faThLarge, faImage, faHeart, faPlus, faLayerGroup } from '@fortawesome/free-solid-svg-icons'
|
||||||
import { formatDistanceToNow } from 'date-fns'
|
import { faClock } from '@fortawesome/free-regular-svg-icons'
|
||||||
import { RelayPool } from 'applesauce-relay'
|
import { RelayPool } from 'applesauce-relay'
|
||||||
import { Bookmark, IndividualBookmark } from '../types/bookmarks'
|
import { Bookmark, IndividualBookmark } from '../types/bookmarks'
|
||||||
import { BookmarkItem } from './BookmarkItem'
|
import { BookmarkItem } from './BookmarkItem'
|
||||||
@@ -13,7 +13,7 @@ import { ViewMode } from './Bookmarks'
|
|||||||
import { usePullToRefresh } from 'use-pull-to-refresh'
|
import { usePullToRefresh } from 'use-pull-to-refresh'
|
||||||
import RefreshIndicator from './RefreshIndicator'
|
import RefreshIndicator from './RefreshIndicator'
|
||||||
import { BookmarkSkeleton } from './Skeletons'
|
import { BookmarkSkeleton } from './Skeletons'
|
||||||
import { groupIndividualBookmarks, hasContent, getBookmarkSets, getBookmarksWithoutSet, hasCreationDate } from '../utils/bookmarkUtils'
|
import { groupIndividualBookmarks, hasContent, getBookmarkSets, getBookmarksWithoutSet, hasCreationDate, sortIndividualBookmarks } from '../utils/bookmarkUtils'
|
||||||
import { UserSettings } from '../services/settingsService'
|
import { UserSettings } from '../services/settingsService'
|
||||||
import AddBookmarkModal from './AddBookmarkModal'
|
import AddBookmarkModal from './AddBookmarkModal'
|
||||||
import { createWebBookmark } from '../services/webBookmarkService'
|
import { createWebBookmark } from '../services/webBookmarkService'
|
||||||
@@ -58,7 +58,6 @@ export const BookmarkList: React.FC<BookmarkListProps> = ({
|
|||||||
onOpenSettings,
|
onOpenSettings,
|
||||||
onRefresh,
|
onRefresh,
|
||||||
isRefreshing,
|
isRefreshing,
|
||||||
lastFetchTime,
|
|
||||||
loading = false,
|
loading = false,
|
||||||
relayPool,
|
relayPool,
|
||||||
isMobile = false,
|
isMobile = false,
|
||||||
@@ -71,7 +70,7 @@ export const BookmarkList: React.FC<BookmarkListProps> = ({
|
|||||||
const [selectedFilter, setSelectedFilter] = useState<BookmarkFilterType>('all')
|
const [selectedFilter, setSelectedFilter] = useState<BookmarkFilterType>('all')
|
||||||
const [groupingMode, setGroupingMode] = useState<'grouped' | 'flat'>(() => {
|
const [groupingMode, setGroupingMode] = useState<'grouped' | 'flat'>(() => {
|
||||||
const saved = localStorage.getItem('bookmarkGroupingMode')
|
const saved = localStorage.getItem('bookmarkGroupingMode')
|
||||||
return saved === 'flat' ? 'flat' : 'grouped'
|
return saved === 'grouped' ? 'grouped' : 'flat'
|
||||||
})
|
})
|
||||||
const activeAccount = Hooks.useActiveAccount()
|
const activeAccount = Hooks.useActiveAccount()
|
||||||
const [readingProgressMap, setReadingProgressMap] = useState<Map<string, number>>(new Map())
|
const [readingProgressMap, setReadingProgressMap] = useState<Map<string, number>>(new Map())
|
||||||
@@ -106,7 +105,18 @@ export const BookmarkList: React.FC<BookmarkListProps> = ({
|
|||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// For web bookmarks and other types, try to use URL if available
|
|
||||||
|
// For web bookmarks (kind:39701), URL is in the 'd' tag
|
||||||
|
if (bookmark.kind === 39701) {
|
||||||
|
const dTag = bookmark.tags.find(t => t[0] === 'd')?.[1]
|
||||||
|
if (dTag) {
|
||||||
|
// Ensure URL has protocol
|
||||||
|
const url = dTag.startsWith('http') ? dTag : `https://${dTag}`
|
||||||
|
return readingProgressMap.get(url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// For other bookmark types, try to extract URL from content
|
||||||
const urls = extractUrlsFromContent(bookmark.content)
|
const urls = extractUrlsFromContent(bookmark.content)
|
||||||
if (urls.length > 0) {
|
if (urls.length > 0) {
|
||||||
return readingProgressMap.get(urls[0])
|
return readingProgressMap.get(urls[0])
|
||||||
@@ -120,6 +130,18 @@ export const BookmarkList: React.FC<BookmarkListProps> = ({
|
|||||||
localStorage.setItem('bookmarkGroupingMode', newMode)
|
localStorage.setItem('bookmarkGroupingMode', newMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getFilterTitle = (filter: BookmarkFilterType): string => {
|
||||||
|
const titles: Record<BookmarkFilterType, string> = {
|
||||||
|
'all': 'All Bookmarks',
|
||||||
|
'article': 'Bookmarked Reads',
|
||||||
|
'external': 'Bookmarked Links',
|
||||||
|
'video': 'Bookmarked Videos',
|
||||||
|
'note': 'Bookmarked Notes',
|
||||||
|
'web': 'Web Bookmarks'
|
||||||
|
}
|
||||||
|
return titles[filter]
|
||||||
|
}
|
||||||
|
|
||||||
const handleSaveBookmark = async (url: string, title?: string, description?: string, tags?: string[]) => {
|
const handleSaveBookmark = async (url: string, title?: string, description?: string, tags?: string[]) => {
|
||||||
if (!activeAccount || !relayPool) {
|
if (!activeAccount || !relayPool) {
|
||||||
throw new Error('Please login to create bookmarks')
|
throw new Error('Please login to create bookmarks')
|
||||||
@@ -140,39 +162,58 @@ export const BookmarkList: React.FC<BookmarkListProps> = ({
|
|||||||
isDisabled: !onRefresh
|
isDisabled: !onRefresh
|
||||||
})
|
})
|
||||||
|
|
||||||
// Merge and flatten all individual bookmarks from all lists
|
// Merge and flatten all individual bookmarks from all lists - memoized to ensure consistent sorting
|
||||||
const allIndividualBookmarks = bookmarks.flatMap(b => b.individualBookmarks || [])
|
const sections = useMemo(() => {
|
||||||
.filter(hasContent)
|
const allIndividualBookmarks = bookmarks.flatMap(b => b.individualBookmarks || [])
|
||||||
.filter(b => !settings?.hideBookmarksWithoutCreationDate || hasCreationDate(b))
|
.filter(hasContent)
|
||||||
|
.filter(b => !settings?.hideBookmarksWithoutCreationDate || hasCreationDate(b))
|
||||||
|
|
||||||
|
// Apply filter
|
||||||
|
const filteredBookmarks = filterBookmarksByType(allIndividualBookmarks, selectedFilter)
|
||||||
|
|
||||||
|
// Separate bookmarks with setName (kind 30003) from regular bookmarks
|
||||||
|
const bookmarksWithoutSet = getBookmarksWithoutSet(filteredBookmarks)
|
||||||
|
const bookmarkSets = getBookmarkSets(filteredBookmarks)
|
||||||
|
|
||||||
|
// Group non-set bookmarks by source or flatten based on mode
|
||||||
|
const groups = groupIndividualBookmarks(bookmarksWithoutSet)
|
||||||
|
const sectionsArray: Array<{ key: string; title: string; items: IndividualBookmark[] }> =
|
||||||
|
groupingMode === 'flat'
|
||||||
|
? [{ key: 'all', title: getFilterTitle(selectedFilter), items: sortIndividualBookmarks(filteredBookmarks) }]
|
||||||
|
: [
|
||||||
|
{ key: 'web', title: 'Web Bookmarks', items: groups.standaloneWeb },
|
||||||
|
{ key: 'nip51-private', title: 'Private Bookmarks', items: groups.nip51Private },
|
||||||
|
{ key: 'nip51-public', title: 'My Bookmarks', items: groups.nip51Public },
|
||||||
|
{ key: 'amethyst-private', title: 'Private Lists', items: groups.amethystPrivate },
|
||||||
|
{ key: 'amethyst-public', title: 'My Lists', items: groups.amethystPublic }
|
||||||
|
]
|
||||||
|
|
||||||
|
// Add bookmark sets as additional sections (only in grouped mode)
|
||||||
|
if (groupingMode === 'grouped') {
|
||||||
|
bookmarkSets.forEach(set => {
|
||||||
|
sectionsArray.push({
|
||||||
|
key: `set-${set.name}`,
|
||||||
|
title: set.title || set.name,
|
||||||
|
items: set.bookmarks
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return sectionsArray
|
||||||
|
}, [bookmarks, selectedFilter, groupingMode, settings?.hideBookmarksWithoutCreationDate])
|
||||||
|
|
||||||
// Apply filter
|
// Get all filtered bookmarks for empty state checks
|
||||||
const filteredBookmarks = filterBookmarksByType(allIndividualBookmarks, selectedFilter)
|
const allIndividualBookmarks = useMemo(() =>
|
||||||
|
bookmarks.flatMap(b => b.individualBookmarks || [])
|
||||||
|
.filter(hasContent)
|
||||||
|
.filter(b => !settings?.hideBookmarksWithoutCreationDate || hasCreationDate(b)),
|
||||||
|
[bookmarks, settings?.hideBookmarksWithoutCreationDate]
|
||||||
|
)
|
||||||
|
|
||||||
// Separate bookmarks with setName (kind 30003) from regular bookmarks
|
const filteredBookmarks = useMemo(() =>
|
||||||
const bookmarksWithoutSet = getBookmarksWithoutSet(filteredBookmarks)
|
filterBookmarksByType(allIndividualBookmarks, selectedFilter),
|
||||||
const bookmarkSets = getBookmarkSets(filteredBookmarks)
|
[allIndividualBookmarks, selectedFilter]
|
||||||
|
)
|
||||||
// Group non-set bookmarks by source or flatten based on mode
|
|
||||||
const groups = groupIndividualBookmarks(bookmarksWithoutSet)
|
|
||||||
const sections: Array<{ key: string; title: string; items: IndividualBookmark[] }> =
|
|
||||||
groupingMode === 'flat'
|
|
||||||
? [{ key: 'all', title: `All Bookmarks (${bookmarksWithoutSet.length})`, items: bookmarksWithoutSet }]
|
|
||||||
: [
|
|
||||||
{ key: 'nip51-private', title: 'Private Bookmarks', items: groups.nip51Private },
|
|
||||||
{ key: 'nip51-public', title: 'My Bookmarks', items: groups.nip51Public },
|
|
||||||
{ key: 'amethyst-private', title: 'Private Lists', items: groups.amethystPrivate },
|
|
||||||
{ key: 'amethyst-public', title: 'My Lists', items: groups.amethystPublic },
|
|
||||||
{ key: 'web', title: 'Web Bookmarks', items: groups.standaloneWeb }
|
|
||||||
]
|
|
||||||
|
|
||||||
// Add bookmark sets as additional sections
|
|
||||||
bookmarkSets.forEach(set => {
|
|
||||||
sections.push({
|
|
||||||
key: `set-${set.name}`,
|
|
||||||
title: set.title || set.name,
|
|
||||||
items: set.bookmarks
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
if (isCollapsed) {
|
if (isCollapsed) {
|
||||||
// Check if the selected URL is in bookmarks
|
// Check if the selected URL is in bookmarks
|
||||||
@@ -206,10 +247,19 @@ export const BookmarkList: React.FC<BookmarkListProps> = ({
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
{allIndividualBookmarks.length > 0 && (
|
{allIndividualBookmarks.length > 0 && (
|
||||||
<BookmarkFilters
|
<div className="bookmark-filters-wrapper">
|
||||||
selectedFilter={selectedFilter}
|
<BookmarkFilters
|
||||||
onFilterChange={setSelectedFilter}
|
selectedFilter={selectedFilter}
|
||||||
/>
|
onFilterChange={setSelectedFilter}
|
||||||
|
/>
|
||||||
|
<CompactButton
|
||||||
|
icon={faPlus}
|
||||||
|
onClick={() => setShowAddModal(true)}
|
||||||
|
title="Add web bookmark"
|
||||||
|
ariaLabel="Add web bookmark"
|
||||||
|
className="bookmark-section-action"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!activeAccount ? (
|
{!activeAccount ? (
|
||||||
@@ -246,15 +296,6 @@ export const BookmarkList: React.FC<BookmarkListProps> = ({
|
|||||||
<div key={section.key} className="bookmarks-section">
|
<div key={section.key} className="bookmarks-section">
|
||||||
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
|
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
|
||||||
<h3 className="bookmarks-section-title" style={{ margin: 0, padding: '1.5rem 0.5rem 0.375rem', flex: 1 }}>{section.title}</h3>
|
<h3 className="bookmarks-section-title" style={{ margin: 0, padding: '1.5rem 0.5rem 0.375rem', flex: 1 }}>{section.title}</h3>
|
||||||
{section.key === 'web' && activeAccount && (
|
|
||||||
<CompactButton
|
|
||||||
icon={faPlus}
|
|
||||||
onClick={() => setShowAddModal(true)}
|
|
||||||
title="Add web bookmark"
|
|
||||||
ariaLabel="Add web bookmark"
|
|
||||||
className="bookmark-section-action"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
<div className={`bookmarks-grid bookmarks-${viewMode}`}>
|
<div className={`bookmarks-grid bookmarks-${viewMode}`}>
|
||||||
{section.items.map((individualBookmark, index) => (
|
{section.items.map((individualBookmark, index) => (
|
||||||
@@ -282,27 +323,18 @@ export const BookmarkList: React.FC<BookmarkListProps> = ({
|
|||||||
variant="ghost"
|
variant="ghost"
|
||||||
style={{ color: friendsColor }}
|
style={{ color: friendsColor }}
|
||||||
/>
|
/>
|
||||||
</div>
|
{activeAccount && (
|
||||||
{activeAccount && (
|
|
||||||
<div className="view-mode-right">
|
|
||||||
<IconButton
|
<IconButton
|
||||||
icon={groupingMode === 'grouped' ? faLayerGroup : faBars}
|
icon={groupingMode === 'grouped' ? faLayerGroup : faClock}
|
||||||
onClick={toggleGroupingMode}
|
onClick={toggleGroupingMode}
|
||||||
title={groupingMode === 'grouped' ? 'Show flat chronological list' : 'Show grouped by source'}
|
title={groupingMode === 'grouped' ? 'Show flat chronological list' : 'Show grouped by source'}
|
||||||
ariaLabel={groupingMode === 'grouped' ? 'Switch to flat view' : 'Switch to grouped view'}
|
ariaLabel={groupingMode === 'grouped' ? 'Switch to flat view' : 'Switch to grouped view'}
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
/>
|
/>
|
||||||
{onRefresh && (
|
)}
|
||||||
<IconButton
|
</div>
|
||||||
icon={faRotate}
|
{activeAccount && (
|
||||||
onClick={onRefresh}
|
<div className="view-mode-right">
|
||||||
title={lastFetchTime ? `Refresh bookmarks (updated ${formatDistanceToNow(lastFetchTime, { addSuffix: true })})` : 'Refresh bookmarks'}
|
|
||||||
ariaLabel="Refresh bookmarks"
|
|
||||||
variant="ghost"
|
|
||||||
disabled={isRefreshing}
|
|
||||||
spin={isRefreshing}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<IconButton
|
<IconButton
|
||||||
icon={faList}
|
icon={faList}
|
||||||
onClick={() => onViewModeChange('compact')}
|
onClick={() => onViewModeChange('compact')}
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||||
import { faChevronDown, faChevronUp } from '@fortawesome/free-solid-svg-icons'
|
import { faLink } from '@fortawesome/free-solid-svg-icons'
|
||||||
import { IconDefinition } from '@fortawesome/fontawesome-svg-core'
|
import { faNewspaper, faStickyNote, faCirclePlay, faCamera, faFileLines } from '@fortawesome/free-regular-svg-icons'
|
||||||
|
import { faGlobe } from '@fortawesome/free-solid-svg-icons'
|
||||||
import { IndividualBookmark } from '../../types/bookmarks'
|
import { IndividualBookmark } from '../../types/bookmarks'
|
||||||
import { formatDate, renderParsedContent } from '../../utils/bookmarkUtils'
|
import { formatDate, renderParsedContent } from '../../utils/bookmarkUtils'
|
||||||
import RichContent from '../RichContent'
|
import RichContent from '../RichContent'
|
||||||
import { classifyUrl } from '../../utils/helpers'
|
import { classifyUrl } from '../../utils/helpers'
|
||||||
import { useImageCache } from '../../hooks/useImageCache'
|
import { useImageCache } from '../../hooks/useImageCache'
|
||||||
import { getPreviewImage, fetchOgImage } from '../../utils/imagePreview'
|
import { getPreviewImage, fetchOgImage } from '../../utils/imagePreview'
|
||||||
import { getEventUrl } from '../../config/nostrGateways'
|
import { naddrEncode } from 'nostr-tools/nip19'
|
||||||
|
import { ReadingProgressBar } from '../ReadingProgressBar'
|
||||||
|
|
||||||
interface CardViewProps {
|
interface CardViewProps {
|
||||||
bookmark: IndividualBookmark
|
bookmark: IndividualBookmark
|
||||||
@@ -18,12 +20,11 @@ interface CardViewProps {
|
|||||||
extractedUrls: string[]
|
extractedUrls: string[]
|
||||||
onSelectUrl?: (url: string, bookmark?: { id: string; kind: number; tags: string[][]; pubkey: string }) => void
|
onSelectUrl?: (url: string, bookmark?: { id: string; kind: number; tags: string[][]; pubkey: string }) => void
|
||||||
authorNpub: string
|
authorNpub: string
|
||||||
eventNevent?: string
|
|
||||||
getAuthorDisplayName: () => string
|
getAuthorDisplayName: () => string
|
||||||
handleReadNow: (e: React.MouseEvent<HTMLButtonElement>) => void
|
handleReadNow: (e: React.MouseEvent<HTMLButtonElement>) => void
|
||||||
articleImage?: string
|
articleImage?: string
|
||||||
articleSummary?: string
|
articleSummary?: string
|
||||||
contentTypeIcon: IconDefinition
|
articleTitle?: string
|
||||||
readingProgress?: number
|
readingProgress?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,14 +33,12 @@ export const CardView: React.FC<CardViewProps> = ({
|
|||||||
index,
|
index,
|
||||||
hasUrls,
|
hasUrls,
|
||||||
extractedUrls,
|
extractedUrls,
|
||||||
onSelectUrl,
|
|
||||||
authorNpub,
|
authorNpub,
|
||||||
eventNevent,
|
|
||||||
getAuthorDisplayName,
|
getAuthorDisplayName,
|
||||||
handleReadNow,
|
handleReadNow,
|
||||||
articleImage,
|
articleImage,
|
||||||
articleSummary,
|
articleSummary,
|
||||||
contentTypeIcon,
|
articleTitle,
|
||||||
readingProgress
|
readingProgress
|
||||||
}) => {
|
}) => {
|
||||||
const firstUrl = hasUrls ? extractedUrls[0] : null
|
const firstUrl = hasUrls ? extractedUrls[0] : null
|
||||||
@@ -47,21 +46,41 @@ export const CardView: React.FC<CardViewProps> = ({
|
|||||||
const instantPreview = firstUrl ? getPreviewImage(firstUrl, firstUrlClassificationType || '') : null
|
const instantPreview = firstUrl ? getPreviewImage(firstUrl, firstUrlClassificationType || '') : null
|
||||||
|
|
||||||
const [ogImage, setOgImage] = useState<string | null>(null)
|
const [ogImage, setOgImage] = useState<string | null>(null)
|
||||||
const [expanded, setExpanded] = useState(false)
|
|
||||||
const [urlsExpanded, setUrlsExpanded] = useState(false)
|
|
||||||
|
|
||||||
const contentLength = (bookmark.content || '').length
|
|
||||||
const shouldTruncate = !expanded && contentLength > 210
|
|
||||||
const isArticle = bookmark.kind === 30023
|
const isArticle = bookmark.kind === 30023
|
||||||
|
const isWebBookmark = bookmark.kind === 39701
|
||||||
|
const isNote = bookmark.kind === 1
|
||||||
|
|
||||||
// Calculate progress color (matching BlogPostCard logic)
|
// Extract title from tags for regular bookmarks (not just articles)
|
||||||
let progressColor = '#6366f1' // Default blue (reading)
|
const bookmarkTitle = bookmark.tags.find(t => t[0] === 'title')?.[1]
|
||||||
if (readingProgress && readingProgress >= 0.95) {
|
|
||||||
progressColor = '#10b981' // Green (completed)
|
// Get content type icon based on bookmark kind and URL classification
|
||||||
} else if (readingProgress && readingProgress > 0 && readingProgress <= 0.10) {
|
const getContentTypeIcon = () => {
|
||||||
progressColor = 'var(--color-text)' // Neutral text color (started)
|
if (isArticle) return faNewspaper // Nostr-native article
|
||||||
|
|
||||||
|
// For web bookmarks, classify the URL to determine icon
|
||||||
|
if (isWebBookmark && firstUrlClassificationType) {
|
||||||
|
switch (firstUrlClassificationType) {
|
||||||
|
case 'youtube':
|
||||||
|
case 'video':
|
||||||
|
return faCirclePlay
|
||||||
|
case 'image':
|
||||||
|
return faCamera
|
||||||
|
case 'article':
|
||||||
|
return faFileLines
|
||||||
|
default:
|
||||||
|
return faGlobe
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// For notes, use sticky note icon
|
||||||
|
if (isNote) return faStickyNote
|
||||||
|
|
||||||
|
// Default fallback
|
||||||
|
return faLink
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Determine which image to use (article image, instant preview, or OG image)
|
// Determine which image to use (article image, instant preview, or OG image)
|
||||||
const previewImage = articleImage || instantPreview || ogImage
|
const previewImage = articleImage || instantPreview || ogImage
|
||||||
const cachedImage = useImageCache(previewImage || undefined)
|
const cachedImage = useImageCache(previewImage || undefined)
|
||||||
@@ -73,6 +92,7 @@ export const CardView: React.FC<CardViewProps> = ({
|
|||||||
}
|
}
|
||||||
}, [firstUrl, articleImage, instantPreview, ogImage])
|
}, [firstUrl, articleImage, instantPreview, ogImage])
|
||||||
|
|
||||||
|
|
||||||
const triggerOpen = () => handleReadNow({ preventDefault: () => {} } as React.MouseEvent<HTMLButtonElement>)
|
const triggerOpen = () => handleReadNow({ preventDefault: () => {} } as React.MouseEvent<HTMLButtonElement>)
|
||||||
|
|
||||||
const handleKeyDown: React.KeyboardEventHandler<HTMLDivElement> = (e) => {
|
const handleKeyDown: React.KeyboardEventHandler<HTMLDivElement> = (e) => {
|
||||||
@@ -82,127 +102,113 @@ export const CardView: React.FC<CardViewProps> = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get internal route for the bookmark
|
||||||
|
const getInternalRoute = (): string | null => {
|
||||||
|
if (bookmark.kind === 30023) {
|
||||||
|
// Nostr-native article - use /a/ route
|
||||||
|
const dTag = bookmark.tags.find(t => t[0] === 'd')?.[1]
|
||||||
|
if (dTag) {
|
||||||
|
const naddr = naddrEncode({
|
||||||
|
kind: bookmark.kind,
|
||||||
|
pubkey: bookmark.pubkey,
|
||||||
|
identifier: dTag
|
||||||
|
})
|
||||||
|
return `/a/${naddr}`
|
||||||
|
}
|
||||||
|
} else if (bookmark.kind === 1) {
|
||||||
|
// Note - use /e/ route
|
||||||
|
return `/e/${bookmark.id}`
|
||||||
|
} else if (firstUrl) {
|
||||||
|
// External URL - use /r/ route
|
||||||
|
return `/r/${encodeURIComponent(firstUrl)}`
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={`${bookmark.id}-${index}`}
|
key={`${bookmark.id}-${index}`}
|
||||||
className={`individual-bookmark ${bookmark.isPrivate ? 'private-bookmark' : ''}`}
|
className={`individual-bookmark card-view ${bookmark.isPrivate ? 'private-bookmark' : ''}`}
|
||||||
onClick={triggerOpen}
|
onClick={triggerOpen}
|
||||||
role="button"
|
role="button"
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
>
|
>
|
||||||
{cachedImage && (
|
<div className="card-layout">
|
||||||
<div
|
<div className="card-content">
|
||||||
className="article-hero-image"
|
<div className="card-content-header">
|
||||||
style={{ backgroundImage: `url(${cachedImage})` }}
|
{(cachedImage || firstUrl) && (
|
||||||
onClick={() => handleReadNow({ preventDefault: () => {} } as React.MouseEvent<HTMLButtonElement>)}
|
<div
|
||||||
/>
|
className="card-thumbnail"
|
||||||
)}
|
style={cachedImage ? { backgroundImage: `url(${cachedImage})` } : undefined}
|
||||||
<div className="bookmark-header">
|
onClick={() => handleReadNow({ preventDefault: () => {} } as React.MouseEvent<HTMLButtonElement>)}
|
||||||
<span className="bookmark-type">
|
|
||||||
<FontAwesomeIcon icon={contentTypeIcon} className="content-type-icon" />
|
|
||||||
</span>
|
|
||||||
|
|
||||||
{eventNevent ? (
|
|
||||||
<a
|
|
||||||
href={getEventUrl(eventNevent)}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className="bookmark-date-link"
|
|
||||||
title="Open event in search"
|
|
||||||
onClick={(e) => e.stopPropagation()}
|
|
||||||
>
|
|
||||||
{formatDate(bookmark.created_at)}
|
|
||||||
</a>
|
|
||||||
) : (
|
|
||||||
<span className="bookmark-date">{formatDate(bookmark.created_at)}</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{extractedUrls.length > 0 && (
|
|
||||||
<div className="bookmark-urls">
|
|
||||||
{(urlsExpanded ? extractedUrls : extractedUrls.slice(0, 1)).map((url, urlIndex) => {
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
key={urlIndex}
|
|
||||||
className="bookmark-url"
|
|
||||||
onClick={(e) => { e.stopPropagation(); onSelectUrl?.(url) }}
|
|
||||||
title="Open in reader"
|
|
||||||
>
|
>
|
||||||
{url}
|
{!cachedImage && firstUrl && (
|
||||||
</button>
|
<div className="thumbnail-placeholder">
|
||||||
)
|
<FontAwesomeIcon icon={getContentTypeIcon()} />
|
||||||
})}
|
</div>
|
||||||
{extractedUrls.length > 1 && (
|
)}
|
||||||
<button
|
</div>
|
||||||
className="expand-toggle-urls"
|
)}
|
||||||
onClick={(e) => { e.stopPropagation(); setUrlsExpanded(v => !v) }}
|
<div className="card-text-content">
|
||||||
aria-label={urlsExpanded ? 'Collapse URLs' : 'Expand URLs'}
|
<div className="bookmark-header">
|
||||||
title={urlsExpanded ? 'Collapse URLs' : 'Expand URLs'}
|
</div>
|
||||||
|
|
||||||
|
{/* Display title for articles or bookmarks with titles */}
|
||||||
|
{(articleTitle || bookmarkTitle) && (
|
||||||
|
<h3 className="bookmark-title">
|
||||||
|
<RichContent content={articleTitle || bookmarkTitle || ''} className="" />
|
||||||
|
</h3>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{isArticle && articleSummary ? (
|
||||||
|
<RichContent content={articleSummary} className="bookmark-content article-summary" />
|
||||||
|
) : bookmark.parsedContent ? (
|
||||||
|
<div className="bookmark-content">
|
||||||
|
{renderParsedContent(bookmark.parsedContent)}
|
||||||
|
</div>
|
||||||
|
) : bookmark.content && (
|
||||||
|
<RichContent content={bookmark.content} className="bookmark-content" />
|
||||||
|
)}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Reading progress indicator as separator - always shown for all bookmark types */}
|
||||||
|
<ReadingProgressBar
|
||||||
|
readingProgress={readingProgress}
|
||||||
|
height={1}
|
||||||
|
marginTop="0.125rem"
|
||||||
|
marginBottom="0.125rem"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="bookmark-footer">
|
||||||
|
<div className="bookmark-meta-minimal">
|
||||||
|
<Link
|
||||||
|
to={`/p/${authorNpub}`}
|
||||||
|
className="author-link-minimal"
|
||||||
|
title="Open author profile"
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
>
|
>
|
||||||
{urlsExpanded ? `Hide ${extractedUrls.length - 1} more` : `Show ${extractedUrls.length - 1} more`}
|
{getAuthorDisplayName()}
|
||||||
</button>
|
</Link>
|
||||||
)}
|
</div>
|
||||||
|
<div className="bookmark-footer-right">
|
||||||
|
{getInternalRoute() ? (
|
||||||
|
<Link
|
||||||
|
to={getInternalRoute()!}
|
||||||
|
className="bookmark-date-link"
|
||||||
|
title="Open in app"
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
>
|
||||||
|
{formatDate(bookmark.created_at ?? bookmark.listUpdatedAt)}
|
||||||
|
</Link>
|
||||||
|
) : (
|
||||||
|
<span className="bookmark-date">{formatDate(bookmark.created_at ?? bookmark.listUpdatedAt)}</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
|
|
||||||
{isArticle && articleSummary ? (
|
|
||||||
<RichContent content={articleSummary} className="bookmark-content article-summary" />
|
|
||||||
) : bookmark.parsedContent ? (
|
|
||||||
<div className="bookmark-content">
|
|
||||||
{shouldTruncate && bookmark.content
|
|
||||||
? <RichContent content={`${bookmark.content.slice(0, 210).trimEnd()}…`} className="" />
|
|
||||||
: renderParsedContent(bookmark.parsedContent)}
|
|
||||||
</div>
|
|
||||||
) : bookmark.content && (
|
|
||||||
<RichContent content={shouldTruncate ? `${bookmark.content.slice(0, 210).trimEnd()}…` : bookmark.content} />
|
|
||||||
)}
|
|
||||||
|
|
||||||
{contentLength > 210 && (
|
|
||||||
<button
|
|
||||||
className="expand-toggle"
|
|
||||||
onClick={(e) => { e.stopPropagation(); setExpanded(v => !v) }}
|
|
||||||
aria-label={expanded ? 'Collapse' : 'Expand'}
|
|
||||||
title={expanded ? 'Collapse' : 'Expand'}
|
|
||||||
>
|
|
||||||
<FontAwesomeIcon icon={expanded ? faChevronUp : faChevronDown} />
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Reading progress indicator for articles */}
|
|
||||||
{isArticle && readingProgress !== undefined && readingProgress > 0 && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
height: '3px',
|
|
||||||
width: '100%',
|
|
||||||
background: 'var(--color-border)',
|
|
||||||
overflow: 'hidden',
|
|
||||||
marginTop: '0.75rem'
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
height: '100%',
|
|
||||||
width: `${Math.round(readingProgress * 100)}%`,
|
|
||||||
background: progressColor,
|
|
||||||
transition: 'width 0.3s ease, background 0.3s ease'
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className="bookmark-footer">
|
|
||||||
<div className="bookmark-meta-minimal">
|
|
||||||
<Link
|
|
||||||
to={`/p/${authorNpub}`}
|
|
||||||
className="author-link-minimal"
|
|
||||||
title="Open author profile"
|
|
||||||
onClick={(e) => e.stopPropagation()}
|
|
||||||
>
|
|
||||||
{getAuthorDisplayName()}
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
{/* CTA removed */}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import { IconDefinition } from '@fortawesome/fontawesome-svg-core'
|
|||||||
import { IndividualBookmark } from '../../types/bookmarks'
|
import { IndividualBookmark } from '../../types/bookmarks'
|
||||||
import { formatDateCompact } from '../../utils/bookmarkUtils'
|
import { formatDateCompact } from '../../utils/bookmarkUtils'
|
||||||
import RichContent from '../RichContent'
|
import RichContent from '../RichContent'
|
||||||
|
import { naddrEncode } from 'nostr-tools/nip19'
|
||||||
|
import { ReadingProgressBar } from '../ReadingProgressBar'
|
||||||
|
|
||||||
interface CompactViewProps {
|
interface CompactViewProps {
|
||||||
bookmark: IndividualBookmark
|
bookmark: IndividualBookmark
|
||||||
@@ -12,7 +14,7 @@ interface CompactViewProps {
|
|||||||
hasUrls: boolean
|
hasUrls: boolean
|
||||||
extractedUrls: string[]
|
extractedUrls: string[]
|
||||||
onSelectUrl?: (url: string, bookmark?: { id: string; kind: number; tags: string[][]; pubkey: string }) => void
|
onSelectUrl?: (url: string, bookmark?: { id: string; kind: number; tags: string[][]; pubkey: string }) => void
|
||||||
articleSummary?: string
|
articleTitle?: string
|
||||||
contentTypeIcon: IconDefinition
|
contentTypeIcon: IconDefinition
|
||||||
readingProgress?: number
|
readingProgress?: number
|
||||||
}
|
}
|
||||||
@@ -23,7 +25,7 @@ export const CompactView: React.FC<CompactViewProps> = ({
|
|||||||
hasUrls,
|
hasUrls,
|
||||||
extractedUrls,
|
extractedUrls,
|
||||||
onSelectUrl,
|
onSelectUrl,
|
||||||
articleSummary,
|
articleTitle,
|
||||||
contentTypeIcon,
|
contentTypeIcon,
|
||||||
readingProgress
|
readingProgress
|
||||||
}) => {
|
}) => {
|
||||||
@@ -33,19 +35,20 @@ export const CompactView: React.FC<CompactViewProps> = ({
|
|||||||
const isNote = bookmark.kind === 1
|
const isNote = bookmark.kind === 1
|
||||||
const isClickable = hasUrls || isArticle || isWebBookmark || isNote
|
const isClickable = hasUrls || isArticle || isWebBookmark || isNote
|
||||||
|
|
||||||
const displayText = isArticle && articleSummary ? articleSummary : bookmark.content
|
const displayText = isArticle && articleTitle ? articleTitle : bookmark.content
|
||||||
|
|
||||||
// Calculate progress color
|
|
||||||
let progressColor = '#6366f1' // Default blue (reading)
|
|
||||||
if (readingProgress && readingProgress >= 0.95) {
|
|
||||||
progressColor = '#10b981' // Green (completed)
|
|
||||||
} else if (readingProgress && readingProgress > 0 && readingProgress <= 0.10) {
|
|
||||||
progressColor = 'var(--color-text)' // Neutral text color (started)
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleCompactClick = () => {
|
const handleCompactClick = () => {
|
||||||
if (isArticle) {
|
if (isArticle) {
|
||||||
onSelectUrl?.('', { id: bookmark.id, kind: bookmark.kind, tags: bookmark.tags, pubkey: bookmark.pubkey })
|
const dTag = bookmark.tags.find(t => t[0] === 'd')?.[1]
|
||||||
|
if (dTag) {
|
||||||
|
const naddr = naddrEncode({
|
||||||
|
kind: bookmark.kind,
|
||||||
|
pubkey: bookmark.pubkey,
|
||||||
|
identifier: dTag
|
||||||
|
})
|
||||||
|
navigate(`/a/${naddr}`)
|
||||||
|
}
|
||||||
} else if (hasUrls) {
|
} else if (hasUrls) {
|
||||||
onSelectUrl?.(extractedUrls[0])
|
onSelectUrl?.(extractedUrls[0])
|
||||||
} else if (isNote) {
|
} else if (isNote) {
|
||||||
@@ -73,31 +76,17 @@ export const CompactView: React.FC<CompactViewProps> = ({
|
|||||||
<code>{bookmark.id.slice(0, 12)}...</code>
|
<code>{bookmark.id.slice(0, 12)}...</code>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<span className="bookmark-date-compact">{formatDateCompact(bookmark.created_at)}</span>
|
<span className="bookmark-date-compact">{formatDateCompact(bookmark.created_at ?? bookmark.listUpdatedAt)}</span>
|
||||||
{/* CTA removed */}
|
{/* CTA removed */}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Reading progress indicator for all bookmark types with reading data */}
|
{/* Reading progress indicator - only show when there's actual progress */}
|
||||||
{readingProgress !== undefined && readingProgress > 0 && (
|
{readingProgress !== undefined && readingProgress > 0 && (
|
||||||
<div
|
<ReadingProgressBar
|
||||||
style={{
|
readingProgress={readingProgress}
|
||||||
height: '1px',
|
height={1}
|
||||||
width: '100%',
|
marginLeft="1.5rem"
|
||||||
background: 'var(--color-border)',
|
/>
|
||||||
overflow: 'hidden',
|
|
||||||
margin: '0',
|
|
||||||
marginLeft: '1.5rem'
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
height: '100%',
|
|
||||||
width: `${Math.round(readingProgress * 100)}%`,
|
|
||||||
background: progressColor,
|
|
||||||
transition: 'width 0.3s ease, background 0.3s ease'
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ import { formatDate } from '../../utils/bookmarkUtils'
|
|||||||
import RichContent from '../RichContent'
|
import RichContent from '../RichContent'
|
||||||
import { IconGetter } from './shared'
|
import { IconGetter } from './shared'
|
||||||
import { useImageCache } from '../../hooks/useImageCache'
|
import { useImageCache } from '../../hooks/useImageCache'
|
||||||
import { getEventUrl } from '../../config/nostrGateways'
|
import { naddrEncode } from 'nostr-tools/nip19'
|
||||||
|
import { ReadingProgressBar } from '../ReadingProgressBar'
|
||||||
|
|
||||||
interface LargeViewProps {
|
interface LargeViewProps {
|
||||||
bookmark: IndividualBookmark
|
bookmark: IndividualBookmark
|
||||||
@@ -18,7 +19,6 @@ interface LargeViewProps {
|
|||||||
getIconForUrlType: IconGetter
|
getIconForUrlType: IconGetter
|
||||||
previewImage: string | null
|
previewImage: string | null
|
||||||
authorNpub: string
|
authorNpub: string
|
||||||
eventNevent?: string
|
|
||||||
getAuthorDisplayName: () => string
|
getAuthorDisplayName: () => string
|
||||||
handleReadNow: (e: React.MouseEvent<HTMLButtonElement>) => void
|
handleReadNow: (e: React.MouseEvent<HTMLButtonElement>) => void
|
||||||
articleSummary?: string
|
articleSummary?: string
|
||||||
@@ -35,7 +35,6 @@ export const LargeView: React.FC<LargeViewProps> = ({
|
|||||||
getIconForUrlType,
|
getIconForUrlType,
|
||||||
previewImage,
|
previewImage,
|
||||||
authorNpub,
|
authorNpub,
|
||||||
eventNevent,
|
|
||||||
getAuthorDisplayName,
|
getAuthorDisplayName,
|
||||||
handleReadNow,
|
handleReadNow,
|
||||||
articleSummary,
|
articleSummary,
|
||||||
@@ -45,15 +44,6 @@ export const LargeView: React.FC<LargeViewProps> = ({
|
|||||||
const cachedImage = useImageCache(previewImage || undefined)
|
const cachedImage = useImageCache(previewImage || undefined)
|
||||||
const isArticle = bookmark.kind === 30023
|
const isArticle = bookmark.kind === 30023
|
||||||
|
|
||||||
// Calculate progress display (matching readingProgressUtils.ts logic)
|
|
||||||
const progressPercent = readingProgress ? Math.round(readingProgress * 100) : 0
|
|
||||||
let progressColor = '#6366f1' // Default blue (reading)
|
|
||||||
|
|
||||||
if (readingProgress && readingProgress >= 0.95) {
|
|
||||||
progressColor = '#10b981' // Green (completed)
|
|
||||||
} else if (readingProgress && readingProgress > 0 && readingProgress <= 0.10) {
|
|
||||||
progressColor = 'var(--color-text)' // Neutral text color (started)
|
|
||||||
}
|
|
||||||
|
|
||||||
const triggerOpen = () => handleReadNow({ preventDefault: () => {} } as React.MouseEvent<HTMLButtonElement>)
|
const triggerOpen = () => handleReadNow({ preventDefault: () => {} } as React.MouseEvent<HTMLButtonElement>)
|
||||||
const handleKeyDown: React.KeyboardEventHandler<HTMLDivElement> = (e) => {
|
const handleKeyDown: React.KeyboardEventHandler<HTMLDivElement> = (e) => {
|
||||||
@@ -63,6 +53,30 @@ export const LargeView: React.FC<LargeViewProps> = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get internal route for the bookmark
|
||||||
|
const getInternalRoute = (): string | null => {
|
||||||
|
const firstUrl = hasUrls ? extractedUrls[0] : null
|
||||||
|
if (bookmark.kind === 30023) {
|
||||||
|
// Nostr-native article - use /a/ route
|
||||||
|
const dTag = bookmark.tags.find(t => t[0] === 'd')?.[1]
|
||||||
|
if (dTag) {
|
||||||
|
const naddr = naddrEncode({
|
||||||
|
kind: bookmark.kind,
|
||||||
|
pubkey: bookmark.pubkey,
|
||||||
|
identifier: dTag
|
||||||
|
})
|
||||||
|
return `/a/${naddr}`
|
||||||
|
}
|
||||||
|
} else if (bookmark.kind === 1) {
|
||||||
|
// Note - use /e/ route
|
||||||
|
return `/e/${bookmark.id}`
|
||||||
|
} else if (firstUrl) {
|
||||||
|
// External URL - use /r/ route
|
||||||
|
return `/r/${encodeURIComponent(firstUrl)}`
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={`${bookmark.id}-${index}`}
|
key={`${bookmark.id}-${index}`}
|
||||||
@@ -100,27 +114,12 @@ export const LargeView: React.FC<LargeViewProps> = ({
|
|||||||
<RichContent content={bookmark.content} className="large-text" />
|
<RichContent content={bookmark.content} className="large-text" />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Reading progress indicator for articles - shown only if there's progress */}
|
{/* Reading progress indicator for all bookmark types - always shown */}
|
||||||
{isArticle && readingProgress !== undefined && readingProgress > 0 && (
|
<ReadingProgressBar
|
||||||
<div
|
readingProgress={readingProgress}
|
||||||
style={{
|
height={3}
|
||||||
height: '3px',
|
marginTop="0.75rem"
|
||||||
width: '100%',
|
/>
|
||||||
background: 'var(--color-border)',
|
|
||||||
overflow: 'hidden',
|
|
||||||
marginTop: '0.75rem'
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
height: '100%',
|
|
||||||
width: `${progressPercent}%`,
|
|
||||||
background: progressColor,
|
|
||||||
transition: 'width 0.3s ease, background 0.3s ease'
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className="large-footer">
|
<div className="large-footer">
|
||||||
<span className="bookmark-type-large">
|
<span className="bookmark-type-large">
|
||||||
@@ -136,16 +135,17 @@ export const LargeView: React.FC<LargeViewProps> = ({
|
|||||||
</Link>
|
</Link>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
{eventNevent && (
|
{getInternalRoute() ? (
|
||||||
<a
|
<Link
|
||||||
href={getEventUrl(eventNevent)}
|
to={getInternalRoute()!}
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className="bookmark-date-link"
|
className="bookmark-date-link"
|
||||||
|
title="Open in app"
|
||||||
onClick={(e) => e.stopPropagation()}
|
onClick={(e) => e.stopPropagation()}
|
||||||
>
|
>
|
||||||
{formatDate(bookmark.created_at)}
|
{formatDate(bookmark.created_at ?? bookmark.listUpdatedAt)}
|
||||||
</a>
|
</Link>
|
||||||
|
) : (
|
||||||
|
<span className="bookmark-date">{formatDate(bookmark.created_at ?? bookmark.listUpdatedAt)}</span>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* CTA removed */}
|
{/* CTA removed */}
|
||||||
|
|||||||
@@ -2,8 +2,11 @@ import React, { useMemo, useEffect, useRef } from 'react'
|
|||||||
import { useParams, useLocation, useNavigate } from 'react-router-dom'
|
import { useParams, useLocation, useNavigate } from 'react-router-dom'
|
||||||
import { Hooks } from 'applesauce-react'
|
import { Hooks } from 'applesauce-react'
|
||||||
import { useEventStore } from 'applesauce-react/hooks'
|
import { useEventStore } from 'applesauce-react/hooks'
|
||||||
|
import { Helpers } from 'applesauce-core'
|
||||||
import { RelayPool } from 'applesauce-relay'
|
import { RelayPool } from 'applesauce-relay'
|
||||||
import { nip19 } from 'nostr-tools'
|
import { nip19 } from 'nostr-tools'
|
||||||
|
|
||||||
|
const { getPubkeyFromDecodeResult } = Helpers
|
||||||
import { useSettings } from '../hooks/useSettings'
|
import { useSettings } from '../hooks/useSettings'
|
||||||
import { useArticleLoader } from '../hooks/useArticleLoader'
|
import { useArticleLoader } from '../hooks/useArticleLoader'
|
||||||
import { useExternalUrlLoader } from '../hooks/useExternalUrlLoader'
|
import { useExternalUrlLoader } from '../hooks/useExternalUrlLoader'
|
||||||
@@ -14,6 +17,7 @@ import { useBookmarksUI } from '../hooks/useBookmarksUI'
|
|||||||
import { useRelayStatus } from '../hooks/useRelayStatus'
|
import { useRelayStatus } from '../hooks/useRelayStatus'
|
||||||
import { useOfflineSync } from '../hooks/useOfflineSync'
|
import { useOfflineSync } from '../hooks/useOfflineSync'
|
||||||
import { useEventLoader } from '../hooks/useEventLoader'
|
import { useEventLoader } from '../hooks/useEventLoader'
|
||||||
|
import { useDocumentTitle } from '../hooks/useDocumentTitle'
|
||||||
import { Bookmark } from '../types/bookmarks'
|
import { Bookmark } from '../types/bookmarks'
|
||||||
import ThreePaneLayout from './ThreePaneLayout'
|
import ThreePaneLayout from './ThreePaneLayout'
|
||||||
import Explore from './Explore'
|
import Explore from './Explore'
|
||||||
@@ -53,46 +57,59 @@ const Bookmarks: React.FC<BookmarksProps> = ({
|
|||||||
|
|
||||||
const showSettings = location.pathname === '/settings'
|
const showSettings = location.pathname === '/settings'
|
||||||
const showExplore = location.pathname.startsWith('/explore')
|
const showExplore = location.pathname.startsWith('/explore')
|
||||||
const showMe = location.pathname.startsWith('/me')
|
const showMe = location.pathname.startsWith('/my')
|
||||||
const showProfile = location.pathname.startsWith('/p/')
|
const showProfile = location.pathname.startsWith('/p/')
|
||||||
const showSupport = location.pathname === '/support'
|
const showSupport = location.pathname === '/support'
|
||||||
const eventId = eventIdParam
|
const eventId = eventIdParam
|
||||||
|
|
||||||
|
// Manage document title based on current route
|
||||||
|
const isViewingContent = !!(naddr || externalUrl || eventId)
|
||||||
|
useDocumentTitle({
|
||||||
|
title: isViewingContent ? undefined : 'Boris - Read, Highlight, Explore'
|
||||||
|
})
|
||||||
|
|
||||||
// Extract tab from explore routes
|
// Extract tab from explore routes
|
||||||
const exploreTab = location.pathname === '/explore/writings' ? 'writings' : 'highlights'
|
const exploreTab = location.pathname === '/explore/writings' ? 'writings' : 'highlights'
|
||||||
|
|
||||||
// Extract tab from me routes
|
// Extract tab from me routes
|
||||||
const meTab = location.pathname === '/me' ? 'highlights' :
|
const meTab = location.pathname === '/my' ? 'highlights' :
|
||||||
location.pathname === '/me/highlights' ? 'highlights' :
|
location.pathname === '/my/highlights' ? 'highlights' :
|
||||||
location.pathname === '/me/reading-list' ? 'reading-list' :
|
location.pathname === '/my/bookmarks' ? 'bookmarks' :
|
||||||
location.pathname.startsWith('/me/reads') ? 'reads' :
|
location.pathname.startsWith('/my/reads') ? 'reads' :
|
||||||
location.pathname.startsWith('/me/links') ? 'links' :
|
location.pathname.startsWith('/my/links') ? 'links' :
|
||||||
location.pathname === '/me/writings' ? 'writings' : 'highlights'
|
location.pathname === '/my/writings' ? 'writings' : 'highlights'
|
||||||
|
|
||||||
// Extract tab from profile routes
|
// Extract tab from profile routes
|
||||||
const profileTab = location.pathname.endsWith('/writings') ? 'writings' : 'highlights'
|
const profileTab = location.pathname.endsWith('/writings') ? 'writings' : 'highlights'
|
||||||
|
|
||||||
// Decode npub or nprofile to pubkey for profile view
|
// Decode npub or nprofile to pubkey for profile view using applesauce helper
|
||||||
let profilePubkey: string | undefined
|
let profilePubkey: string | undefined
|
||||||
if (npub && showProfile) {
|
if (npub && showProfile) {
|
||||||
try {
|
try {
|
||||||
const decoded = nip19.decode(npub)
|
const decoded = nip19.decode(npub)
|
||||||
if (decoded.type === 'npub') {
|
profilePubkey = getPubkeyFromDecodeResult(decoded)
|
||||||
profilePubkey = decoded.data
|
|
||||||
} else if (decoded.type === 'nprofile') {
|
|
||||||
profilePubkey = decoded.data.pubkey
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to decode npub/nprofile:', err)
|
console.error('Failed to decode npub/nprofile:', err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Track previous location for going back from settings/me/explore/profile
|
// Track previous location for going back from settings/my/explore/profile
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!showSettings && !showMe && !showExplore && !showProfile) {
|
if (!showSettings && !showMe && !showExplore && !showProfile) {
|
||||||
previousLocationRef.current = location.pathname
|
previousLocationRef.current = location.pathname
|
||||||
}
|
}
|
||||||
}, [location.pathname, showSettings, showMe, showExplore, showProfile])
|
}, [location.pathname, showSettings, showMe, showExplore, showProfile])
|
||||||
|
|
||||||
|
// Reset scroll to top when navigating to profile routes
|
||||||
|
useEffect(() => {
|
||||||
|
if (showProfile) {
|
||||||
|
// Reset scroll position when navigating to profile pages
|
||||||
|
// Use requestAnimationFrame to ensure it happens after DOM updates
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
window.scrollTo({ top: 0, behavior: 'instant' })
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [location.pathname, showProfile])
|
||||||
|
|
||||||
const activeAccount = Hooks.useActiveAccount()
|
const activeAccount = Hooks.useActiveAccount()
|
||||||
const accountManager = Hooks.useAccountManager()
|
const accountManager = Hooks.useAccountManager()
|
||||||
@@ -222,14 +239,28 @@ const Bookmarks: React.FC<BookmarksProps> = ({
|
|||||||
currentArticle,
|
currentArticle,
|
||||||
selectedUrl,
|
selectedUrl,
|
||||||
readerContent,
|
readerContent,
|
||||||
onHighlightCreated: (highlight) => setHighlights(prev => [highlight, ...prev]),
|
onHighlightCreated: (highlight) => setHighlights(prev => {
|
||||||
|
// Deduplicate by checking if highlight with this ID already exists
|
||||||
|
const exists = prev.some(h => h.id === highlight.id)
|
||||||
|
if (exists) {
|
||||||
|
return prev // Don't add duplicate
|
||||||
|
}
|
||||||
|
return [highlight, ...prev]
|
||||||
|
}),
|
||||||
settings
|
settings
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Determine which loader should be active based on route
|
||||||
|
// Only one loader should run at a time to prevent state conflicts
|
||||||
|
const shouldLoadArticle = !!naddr && !externalUrl && !eventId
|
||||||
|
const shouldLoadExternal = !!externalUrl && !naddr && !eventId
|
||||||
|
const shouldLoadEvent = !!eventId && !naddr && !externalUrl
|
||||||
|
|
||||||
// Load nostr-native article if naddr is in URL
|
// Load nostr-native article if naddr is in URL
|
||||||
useArticleLoader({
|
useArticleLoader({
|
||||||
naddr,
|
naddr: shouldLoadArticle ? naddr : undefined,
|
||||||
relayPool,
|
relayPool,
|
||||||
|
eventStore,
|
||||||
setSelectedUrl,
|
setSelectedUrl,
|
||||||
setReaderContent,
|
setReaderContent,
|
||||||
setReaderLoading,
|
setReaderLoading,
|
||||||
@@ -244,7 +275,7 @@ const Bookmarks: React.FC<BookmarksProps> = ({
|
|||||||
|
|
||||||
// Load external URL if /r/* route is used
|
// Load external URL if /r/* route is used
|
||||||
useExternalUrlLoader({
|
useExternalUrlLoader({
|
||||||
url: externalUrl,
|
url: shouldLoadExternal ? externalUrl : undefined,
|
||||||
relayPool,
|
relayPool,
|
||||||
eventStore,
|
eventStore,
|
||||||
setSelectedUrl,
|
setSelectedUrl,
|
||||||
@@ -259,7 +290,7 @@ const Bookmarks: React.FC<BookmarksProps> = ({
|
|||||||
|
|
||||||
// Load event if /e/:eventId route is used
|
// Load event if /e/:eventId route is used
|
||||||
useEventLoader({
|
useEventLoader({
|
||||||
eventId,
|
eventId: shouldLoadEvent ? eventId : undefined,
|
||||||
relayPool,
|
relayPool,
|
||||||
eventStore,
|
eventStore,
|
||||||
setSelectedUrl,
|
setSelectedUrl,
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import React, { useMemo, useState, useEffect, useRef, useCallback } from 'react'
|
import React, { useMemo, useState, useEffect, useRef, useCallback } from 'react'
|
||||||
import ReactPlayer from 'react-player'
|
|
||||||
import ReactMarkdown from 'react-markdown'
|
import ReactMarkdown from 'react-markdown'
|
||||||
import remarkGfm from 'remark-gfm'
|
import remarkGfm from 'remark-gfm'
|
||||||
import rehypeRaw from 'rehype-raw'
|
import rehypeRaw from 'rehype-raw'
|
||||||
@@ -34,18 +33,16 @@ import { unarchiveEvent, unarchiveWebsite } from '../services/unarchiveService'
|
|||||||
import { archiveController } from '../services/archiveController'
|
import { archiveController } from '../services/archiveController'
|
||||||
import AuthorCard from './AuthorCard'
|
import AuthorCard from './AuthorCard'
|
||||||
import { faBooks } from '../icons/customIcons'
|
import { faBooks } from '../icons/customIcons'
|
||||||
import { extractYouTubeId, getYouTubeMeta } from '../services/youtubeMetaService'
|
import { shouldTrackReadingProgress } from '../utils/helpers'
|
||||||
import { classifyUrl, shouldTrackReadingProgress } from '../utils/helpers'
|
|
||||||
import { buildNativeVideoUrl } from '../utils/videoHelpers'
|
|
||||||
import { useReadingPosition } from '../hooks/useReadingPosition'
|
import { useReadingPosition } from '../hooks/useReadingPosition'
|
||||||
import { ReadingProgressIndicator } from './ReadingProgressIndicator'
|
import { ReadingProgressIndicator } from './ReadingProgressIndicator'
|
||||||
import { EventFactory } from 'applesauce-factory'
|
import { EventFactory } from 'applesauce-factory'
|
||||||
import { Hooks } from 'applesauce-react'
|
import { Hooks } from 'applesauce-react'
|
||||||
import {
|
import {
|
||||||
generateArticleIdentifier,
|
generateArticleIdentifier,
|
||||||
loadReadingPosition,
|
saveReadingPosition
|
||||||
saveReadingPosition
|
|
||||||
} from '../services/readingPositionService'
|
} from '../services/readingPositionService'
|
||||||
|
import { readingProgressController } from '../services/readingProgressController'
|
||||||
import TTSControls from './TTSControls'
|
import TTSControls from './TTSControls'
|
||||||
|
|
||||||
interface ContentPanelProps {
|
interface ContentPanelProps {
|
||||||
@@ -76,6 +73,7 @@ interface ContentPanelProps {
|
|||||||
// For reading progress indicator positioning
|
// For reading progress indicator positioning
|
||||||
isSidebarCollapsed?: boolean
|
isSidebarCollapsed?: boolean
|
||||||
isHighlightsCollapsed?: boolean
|
isHighlightsCollapsed?: boolean
|
||||||
|
onOpenHighlights?: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const ContentPanel: React.FC<ContentPanelProps> = ({
|
const ContentPanel: React.FC<ContentPanelProps> = ({
|
||||||
@@ -103,21 +101,18 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
onTextSelection,
|
onTextSelection,
|
||||||
onClearSelection,
|
onClearSelection,
|
||||||
isSidebarCollapsed = false,
|
isSidebarCollapsed = false,
|
||||||
isHighlightsCollapsed = false
|
isHighlightsCollapsed = false,
|
||||||
|
onOpenHighlights
|
||||||
}) => {
|
}) => {
|
||||||
const [isMarkedAsRead, setIsMarkedAsRead] = useState(false)
|
const [isMarkedAsRead, setIsMarkedAsRead] = useState(false)
|
||||||
const [isCheckingReadStatus, setIsCheckingReadStatus] = useState(false)
|
const [isCheckingReadStatus, setIsCheckingReadStatus] = useState(false)
|
||||||
const [showCheckAnimation, setShowCheckAnimation] = useState(false)
|
const [showCheckAnimation, setShowCheckAnimation] = useState(false)
|
||||||
const [showArticleMenu, setShowArticleMenu] = useState(false)
|
const [showArticleMenu, setShowArticleMenu] = useState(false)
|
||||||
const [showVideoMenu, setShowVideoMenu] = useState(false)
|
|
||||||
const [showExternalMenu, setShowExternalMenu] = useState(false)
|
const [showExternalMenu, setShowExternalMenu] = useState(false)
|
||||||
const [articleMenuOpenUpward, setArticleMenuOpenUpward] = useState(false)
|
const [articleMenuOpenUpward, setArticleMenuOpenUpward] = useState(false)
|
||||||
const [videoMenuOpenUpward, setVideoMenuOpenUpward] = useState(false)
|
|
||||||
const [externalMenuOpenUpward, setExternalMenuOpenUpward] = useState(false)
|
const [externalMenuOpenUpward, setExternalMenuOpenUpward] = useState(false)
|
||||||
const articleMenuRef = useRef<HTMLDivElement>(null)
|
const articleMenuRef = useRef<HTMLDivElement>(null)
|
||||||
const videoMenuRef = useRef<HTMLDivElement>(null)
|
|
||||||
const externalMenuRef = useRef<HTMLDivElement>(null)
|
const externalMenuRef = useRef<HTMLDivElement>(null)
|
||||||
const [ytMeta, setYtMeta] = useState<{ title?: string; description?: string; transcript?: string } | null>(null)
|
|
||||||
const { renderedHtml: renderedMarkdownHtml, previewRef: markdownPreviewRef, processedMarkdown } = useMarkdownToHTML(markdown, relayPool)
|
const { renderedHtml: renderedMarkdownHtml, previewRef: markdownPreviewRef, processedMarkdown } = useMarkdownToHTML(markdown, relayPool)
|
||||||
|
|
||||||
const { finalHtml, relevantHighlights } = useHighlightedContent({
|
const { finalHtml, relevantHighlights } = useHighlightedContent({
|
||||||
@@ -132,8 +127,13 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
currentUserPubkey,
|
currentUserPubkey,
|
||||||
followedPubkeys
|
followedPubkeys
|
||||||
})
|
})
|
||||||
|
// Key used to force re-mount of markdown preview/render when content changes
|
||||||
|
const contentKey = useMemo(() => {
|
||||||
|
// Prefer selectedUrl as a stable per-article key; fallback to title+length
|
||||||
|
return selectedUrl || `${title || ''}:${(markdown || html || '').length}`
|
||||||
|
}, [selectedUrl, title, markdown, html])
|
||||||
|
|
||||||
const { contentRef, handleSelectionEnd } = useHighlightInteractions({
|
const { contentRef } = useHighlightInteractions({
|
||||||
onHighlightClick,
|
onHighlightClick,
|
||||||
selectedHighlightId,
|
selectedHighlightId,
|
||||||
onTextSelection,
|
onTextSelection,
|
||||||
@@ -143,8 +143,18 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
// Get event store for reading position service
|
// Get event store for reading position service
|
||||||
const eventStore = Hooks.useEventStore()
|
const eventStore = Hooks.useEventStore()
|
||||||
|
|
||||||
// Reading position tracking - only for text content, not videos
|
// Reading position tracking - only for text content that's loaded and long enough
|
||||||
const isTextContent = !loading && !!(markdown || html) && !selectedUrl?.includes('youtube') && !selectedUrl?.includes('vimeo')
|
// Wait for content to load, check it's not a video, and verify it's long enough to track
|
||||||
|
const isTextContent = useMemo(() => {
|
||||||
|
if (loading) return false
|
||||||
|
if (!markdown && !html) return false
|
||||||
|
// Don't track internal sentinel URLs (nostr-event: is not a real Nostr URI per NIP-21)
|
||||||
|
if (selectedUrl?.startsWith('nostr-event:')) return false
|
||||||
|
if (selectedUrl?.includes('youtube') || selectedUrl?.includes('vimeo')) return false
|
||||||
|
if (!shouldTrackReadingProgress(html, markdown)) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}, [loading, markdown, html, selectedUrl])
|
||||||
|
|
||||||
// Generate article identifier for saving/loading position
|
// Generate article identifier for saving/loading position
|
||||||
const articleIdentifier = useMemo(() => {
|
const articleIdentifier = useMemo(() => {
|
||||||
@@ -152,6 +162,14 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
return generateArticleIdentifier(selectedUrl)
|
return generateArticleIdentifier(selectedUrl)
|
||||||
}, [selectedUrl])
|
}, [selectedUrl])
|
||||||
|
|
||||||
|
// Use refs for content to avoid recreating callback on every content change
|
||||||
|
const htmlRef = useRef(html)
|
||||||
|
const markdownRef = useRef(markdown)
|
||||||
|
useEffect(() => {
|
||||||
|
htmlRef.current = html
|
||||||
|
markdownRef.current = markdown
|
||||||
|
}, [html, markdown])
|
||||||
|
|
||||||
// Callback to save reading position
|
// Callback to save reading position
|
||||||
const handleSavePosition = useCallback(async (position: number) => {
|
const handleSavePosition = useCallback(async (position: number) => {
|
||||||
if (!activeAccount || !relayPool || !eventStore || !articleIdentifier) {
|
if (!activeAccount || !relayPool || !eventStore || !articleIdentifier) {
|
||||||
@@ -162,7 +180,7 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if content is long enough to track reading progress
|
// Check if content is long enough to track reading progress
|
||||||
if (!shouldTrackReadingProgress(html, markdown)) {
|
if (!shouldTrackReadingProgress(htmlRef.current, markdownRef.current)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,12 +200,39 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[progress] ❌ ContentPanel: Failed to save reading position:', error)
|
console.error('[reading-position] Failed to save reading position:', error)
|
||||||
}
|
}
|
||||||
}, [activeAccount, relayPool, eventStore, articleIdentifier, settings?.syncReadingPosition, html, markdown])
|
}, [activeAccount, relayPool, eventStore, articleIdentifier, settings?.syncReadingPosition])
|
||||||
|
|
||||||
const { progressPercentage, saveNow } = useReadingPosition({
|
// Delay enabling position tracking to ensure content is stable
|
||||||
enabled: isTextContent,
|
const [isTrackingEnabled, setIsTrackingEnabled] = useState(false)
|
||||||
|
|
||||||
|
// Reset tracking when article changes
|
||||||
|
useEffect(() => {
|
||||||
|
setIsTrackingEnabled(false)
|
||||||
|
}, [selectedUrl])
|
||||||
|
|
||||||
|
// Enable/disable tracking based on content state
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isTextContent) {
|
||||||
|
// Disable tracking if content is not suitable
|
||||||
|
if (isTrackingEnabled) {
|
||||||
|
setIsTrackingEnabled(false)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isTrackingEnabled) {
|
||||||
|
// Wait 500ms after content loads before enabling tracking
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
setIsTrackingEnabled(true)
|
||||||
|
}, 500)
|
||||||
|
return () => clearTimeout(timer)
|
||||||
|
}
|
||||||
|
}, [isTextContent, isTrackingEnabled])
|
||||||
|
|
||||||
|
const { progressPercentage, suppressSavesFor } = useReadingPosition({
|
||||||
|
enabled: isTrackingEnabled,
|
||||||
syncEnabled: settings?.syncReadingPosition !== false,
|
syncEnabled: settings?.syncReadingPosition !== false,
|
||||||
onSave: handleSavePosition,
|
onSave: handleSavePosition,
|
||||||
onReadingComplete: () => {
|
onReadingComplete: () => {
|
||||||
@@ -207,59 +252,99 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
}, [isTextContent, settings?.syncReadingPosition, activeAccount, relayPool, eventStore, articleIdentifier, progressPercentage])
|
}, [isTextContent, settings?.syncReadingPosition, activeAccount, relayPool, eventStore, articleIdentifier, progressPercentage])
|
||||||
|
|
||||||
// Load saved reading position when article loads
|
// Load saved reading position when article loads (using pre-loaded data from controller)
|
||||||
|
const suppressSavesForRef = useRef(suppressSavesFor)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isTextContent || !activeAccount || !relayPool || !eventStore || !articleIdentifier) {
|
suppressSavesForRef.current = suppressSavesFor
|
||||||
|
}, [suppressSavesFor])
|
||||||
|
|
||||||
|
// Track if we've successfully started restore for this article + tracking state
|
||||||
|
// Use a composite key to ensure we only restore once per article when tracking is enabled
|
||||||
|
const restoreKey = `${articleIdentifier}-${isTrackingEnabled}`
|
||||||
|
const hasAttemptedRestoreRef = useRef<string | null>(null)
|
||||||
|
|
||||||
|
// Reset scroll position and restore ref when article changes
|
||||||
|
useEffect(() => {
|
||||||
|
if (!articleIdentifier) return
|
||||||
|
|
||||||
|
// Suppress saves during navigation to prevent saving 0% position
|
||||||
|
// The 500ms suppression covers the scroll reset and initial render
|
||||||
|
if (suppressSavesForRef.current) {
|
||||||
|
suppressSavesForRef.current(500)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset scroll to top when article identifier changes
|
||||||
|
// This prevents showing wrong scroll position from previous article
|
||||||
|
window.scrollTo({ top: 0, behavior: 'instant' })
|
||||||
|
// Reset restore attempt tracking for new article
|
||||||
|
hasAttemptedRestoreRef.current = null
|
||||||
|
}, [articleIdentifier])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isTextContent || !activeAccount || !articleIdentifier) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (settings?.syncReadingPosition === false) {
|
if (settings?.syncReadingPosition === false) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (settings?.autoScrollToReadingPosition === false) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!isTrackingEnabled) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const loadPosition = async () => {
|
// Only attempt restore once per article (after tracking is enabled)
|
||||||
try {
|
if (hasAttemptedRestoreRef.current === restoreKey) {
|
||||||
const savedPosition = await loadReadingPosition(
|
return
|
||||||
relayPool,
|
}
|
||||||
eventStore,
|
|
||||||
activeAccount.pubkey,
|
|
||||||
articleIdentifier
|
|
||||||
)
|
|
||||||
|
|
||||||
if (savedPosition && savedPosition.position > 0.05 && savedPosition.position < 1) {
|
// Mark as attempted using composite key
|
||||||
// Wait for content to be fully rendered before scrolling
|
hasAttemptedRestoreRef.current = restoreKey
|
||||||
setTimeout(() => {
|
|
||||||
const documentHeight = document.documentElement.scrollHeight
|
// Get the saved position from the controller (already loaded and displayed on card)
|
||||||
const windowHeight = window.innerHeight
|
const savedProgress = readingProgressController.getProgress(articleIdentifier)
|
||||||
const scrollTop = savedPosition.position * (documentHeight - windowHeight)
|
|
||||||
|
if (!savedProgress || savedProgress <= 0.05 || savedProgress >= 1) {
|
||||||
window.scrollTo({
|
return
|
||||||
top: scrollTop,
|
}
|
||||||
behavior: 'smooth'
|
|
||||||
})
|
// Suppress saves during restore (500ms render + 1000ms smooth scroll = 1500ms)
|
||||||
}, 500) // Give content time to render
|
if (suppressSavesForRef.current) {
|
||||||
} else if (savedPosition) {
|
suppressSavesForRef.current(1500)
|
||||||
if (savedPosition.position === 1) {
|
}
|
||||||
// Article was completed, start from top
|
|
||||||
} else {
|
// Wait for content to be fully rendered
|
||||||
// Position was too early, skip restore
|
setTimeout(() => {
|
||||||
}
|
const docH = document.documentElement.scrollHeight
|
||||||
|
const winH = window.innerHeight
|
||||||
|
const maxScroll = Math.max(0, docH - winH)
|
||||||
|
const currentTop = window.pageYOffset || document.documentElement.scrollTop
|
||||||
|
const targetTop = savedProgress * maxScroll
|
||||||
|
|
||||||
|
// Skip if delta is too small (< 48px or < 5%)
|
||||||
|
const deltaPx = Math.abs(targetTop - currentTop)
|
||||||
|
const deltaPct = maxScroll > 0 ? Math.abs((targetTop - currentTop) / maxScroll) : 0
|
||||||
|
if (deltaPx < 48 || deltaPct < 0.05) {
|
||||||
|
// Allow saves immediately since no scroll happened
|
||||||
|
if (suppressSavesForRef.current) {
|
||||||
|
suppressSavesForRef.current(0)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
return
|
||||||
console.error('❌ [ContentPanel] Failed to load reading position:', error)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
loadPosition()
|
// Perform smooth animated restore
|
||||||
}, [isTextContent, activeAccount, relayPool, eventStore, articleIdentifier, settings?.syncReadingPosition, selectedUrl])
|
window.scrollTo({
|
||||||
|
top: targetTop,
|
||||||
|
behavior: 'smooth'
|
||||||
|
})
|
||||||
|
}, 500) // Give content time to render
|
||||||
|
}, [isTextContent, activeAccount, articleIdentifier, settings?.syncReadingPosition, settings?.autoScrollToReadingPosition, selectedUrl, isTrackingEnabled, restoreKey])
|
||||||
|
|
||||||
// Save position before unmounting or changing article
|
// Note: We intentionally do NOT save on unmount because:
|
||||||
useEffect(() => {
|
// 1. Browser may scroll to top during back navigation, causing 0% saves
|
||||||
return () => {
|
// 2. The auto-save with 1s throttle already captures position during reading
|
||||||
if (saveNow) {
|
// 3. Position state may not reflect actual reading position during navigation
|
||||||
saveNow()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [saveNow, selectedUrl])
|
|
||||||
|
|
||||||
// Close menu when clicking outside
|
// Close menu when clicking outside
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -268,21 +353,18 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
if (articleMenuRef.current && !articleMenuRef.current.contains(target)) {
|
if (articleMenuRef.current && !articleMenuRef.current.contains(target)) {
|
||||||
setShowArticleMenu(false)
|
setShowArticleMenu(false)
|
||||||
}
|
}
|
||||||
if (videoMenuRef.current && !videoMenuRef.current.contains(target)) {
|
|
||||||
setShowVideoMenu(false)
|
|
||||||
}
|
|
||||||
if (externalMenuRef.current && !externalMenuRef.current.contains(target)) {
|
if (externalMenuRef.current && !externalMenuRef.current.contains(target)) {
|
||||||
setShowExternalMenu(false)
|
setShowExternalMenu(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showArticleMenu || showVideoMenu || showExternalMenu) {
|
if (showArticleMenu || showExternalMenu) {
|
||||||
document.addEventListener('mousedown', handleClickOutside)
|
document.addEventListener('mousedown', handleClickOutside)
|
||||||
return () => {
|
return () => {
|
||||||
document.removeEventListener('mousedown', handleClickOutside)
|
document.removeEventListener('mousedown', handleClickOutside)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [showArticleMenu, showVideoMenu, showExternalMenu])
|
}, [showArticleMenu, showExternalMenu])
|
||||||
|
|
||||||
// Check available space and position menu upward if needed
|
// Check available space and position menu upward if needed
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -305,13 +387,10 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
if (showArticleMenu) {
|
if (showArticleMenu) {
|
||||||
checkMenuPosition(articleMenuRef, setArticleMenuOpenUpward)
|
checkMenuPosition(articleMenuRef, setArticleMenuOpenUpward)
|
||||||
}
|
}
|
||||||
if (showVideoMenu) {
|
|
||||||
checkMenuPosition(videoMenuRef, setVideoMenuOpenUpward)
|
|
||||||
}
|
|
||||||
if (showExternalMenu) {
|
if (showExternalMenu) {
|
||||||
checkMenuPosition(externalMenuRef, setExternalMenuOpenUpward)
|
checkMenuPosition(externalMenuRef, setExternalMenuOpenUpward)
|
||||||
}
|
}
|
||||||
}, [showArticleMenu, showVideoMenu, showExternalMenu])
|
}, [showArticleMenu, showExternalMenu])
|
||||||
|
|
||||||
const readingStats = useMemo(() => {
|
const readingStats = useMemo(() => {
|
||||||
const content = markdown || html || ''
|
const content = markdown || html || ''
|
||||||
@@ -343,34 +422,8 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
|
|
||||||
// Determine if we're on a nostr-native article (/a/) or external URL (/r/)
|
// Determine if we're on a nostr-native article (/a/) or external URL (/r/)
|
||||||
const isNostrArticle = selectedUrl && selectedUrl.startsWith('nostr:')
|
const isNostrArticle = selectedUrl && selectedUrl.startsWith('nostr:')
|
||||||
const isExternalVideo = !isNostrArticle && !!selectedUrl && ['youtube', 'video'].includes(classifyUrl(selectedUrl).type)
|
|
||||||
|
|
||||||
// Track external video duration (in seconds) for display in header
|
|
||||||
const [videoDurationSec, setVideoDurationSec] = useState<number | null>(null)
|
|
||||||
// Load YouTube metadata/captions when applicable
|
|
||||||
useEffect(() => {
|
|
||||||
(async () => {
|
|
||||||
try {
|
|
||||||
if (!selectedUrl) return setYtMeta(null)
|
|
||||||
const id = extractYouTubeId(selectedUrl)
|
|
||||||
if (!id) return setYtMeta(null)
|
|
||||||
const locale = navigator?.language?.split('-')[0] || 'en'
|
|
||||||
const data = await getYouTubeMeta(id, locale)
|
|
||||||
if (data) setYtMeta({ title: data.title, description: data.description, transcript: data.transcript })
|
|
||||||
} catch {
|
|
||||||
setYtMeta(null)
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
}, [selectedUrl])
|
|
||||||
|
|
||||||
const formatDuration = (totalSeconds: number): string => {
|
|
||||||
const hours = Math.floor(totalSeconds / 3600)
|
|
||||||
const minutes = Math.floor((totalSeconds % 3600) / 60)
|
|
||||||
const seconds = Math.floor(totalSeconds % 60)
|
|
||||||
const mm = hours > 0 ? String(minutes).padStart(2, '0') : String(minutes)
|
|
||||||
const ss = String(seconds).padStart(2, '0')
|
|
||||||
return hours > 0 ? `${hours}:${mm}:${ss}` : `${mm}:${ss}`
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Get article links for menu
|
// Get article links for menu
|
||||||
@@ -408,7 +461,6 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
setShowArticleMenu(!showArticleMenu)
|
setShowArticleMenu(!showArticleMenu)
|
||||||
}
|
}
|
||||||
|
|
||||||
const toggleVideoMenu = () => setShowVideoMenu(v => !v)
|
|
||||||
|
|
||||||
const handleOpenPortal = () => {
|
const handleOpenPortal = () => {
|
||||||
if (articleLinks) {
|
if (articleLinks) {
|
||||||
@@ -496,46 +548,6 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
setShowArticleMenu(false)
|
setShowArticleMenu(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Video actions
|
|
||||||
const handleOpenVideoExternal = () => {
|
|
||||||
if (selectedUrl) window.open(selectedUrl, '_blank', 'noopener,noreferrer')
|
|
||||||
setShowVideoMenu(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleOpenVideoNative = () => {
|
|
||||||
if (!selectedUrl) return
|
|
||||||
const native = buildNativeVideoUrl(selectedUrl)
|
|
||||||
if (native) {
|
|
||||||
window.location.href = native
|
|
||||||
} else {
|
|
||||||
window.location.href = selectedUrl
|
|
||||||
}
|
|
||||||
setShowVideoMenu(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleCopyVideoUrl = async () => {
|
|
||||||
try {
|
|
||||||
if (selectedUrl) await navigator.clipboard.writeText(selectedUrl)
|
|
||||||
} catch (e) {
|
|
||||||
console.warn('Clipboard copy failed', e)
|
|
||||||
} finally {
|
|
||||||
setShowVideoMenu(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleShareVideoUrl = async () => {
|
|
||||||
try {
|
|
||||||
if (selectedUrl && (navigator as { share?: (d: { title?: string; url?: string }) => Promise<void> }).share) {
|
|
||||||
await (navigator as { share: (d: { title?: string; url?: string }) => Promise<void> }).share({ title: title || 'Video', url: selectedUrl })
|
|
||||||
} else if (selectedUrl) {
|
|
||||||
await navigator.clipboard.writeText(selectedUrl)
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.warn('Share failed', e)
|
|
||||||
} finally {
|
|
||||||
setShowVideoMenu(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// External article actions
|
// External article actions
|
||||||
const toggleExternalMenu = () => setShowExternalMenu(v => !v)
|
const toggleExternalMenu = () => setShowExternalMenu(v => !v)
|
||||||
@@ -577,7 +589,13 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
|
|
||||||
const handleSearchExternalUrl = () => {
|
const handleSearchExternalUrl = () => {
|
||||||
if (selectedUrl) {
|
if (selectedUrl) {
|
||||||
window.open(getSearchUrl(selectedUrl), '_blank', 'noopener,noreferrer')
|
// If it's a nostr event sentinel, open the event directly on ants.sh
|
||||||
|
if (selectedUrl.startsWith('nostr-event:')) {
|
||||||
|
const eventId = selectedUrl.replace('nostr-event:', '')
|
||||||
|
window.open(`https://ants.sh/e/${eventId}`, '_blank', 'noopener,noreferrer')
|
||||||
|
} else {
|
||||||
|
window.open(getSearchUrl(selectedUrl), '_blank', 'noopener,noreferrer')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setShowExternalMenu(false)
|
setShowExternalMenu(false)
|
||||||
}
|
}
|
||||||
@@ -727,13 +745,6 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loading) {
|
|
||||||
return (
|
|
||||||
<div className="reader" aria-busy="true">
|
|
||||||
<ContentSkeleton />
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const highlightRgb = hexToRgb(highlightColor)
|
const highlightRgb = hexToRgb(highlightColor)
|
||||||
|
|
||||||
@@ -754,7 +765,7 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
<div className="reader" style={{ '--highlight-rgb': highlightRgb } as React.CSSProperties}>
|
<div className="reader" style={{ '--highlight-rgb': highlightRgb } as React.CSSProperties}>
|
||||||
{/* Hidden markdown preview to convert markdown to HTML */}
|
{/* Hidden markdown preview to convert markdown to HTML */}
|
||||||
{markdown && (
|
{markdown && (
|
||||||
<div ref={markdownPreviewRef} style={{ display: 'none' }}>
|
<div ref={markdownPreviewRef} key={`preview:${contentKey}`} style={{ display: 'none' }}>
|
||||||
<ReactMarkdown
|
<ReactMarkdown
|
||||||
remarkPlugins={[remarkGfm]}
|
remarkPlugins={[remarkGfm]}
|
||||||
rehypePlugins={[rehypeRaw, rehypePrism]}
|
rehypePlugins={[rehypeRaw, rehypePrism]}
|
||||||
@@ -773,134 +784,55 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<ReaderHeader
|
<ReaderHeader
|
||||||
title={ytMeta?.title || title}
|
title={title}
|
||||||
image={image}
|
image={image}
|
||||||
summary={summary}
|
summary={summary}
|
||||||
published={published}
|
published={published}
|
||||||
readingTimeText={isExternalVideo ? (videoDurationSec !== null ? formatDuration(videoDurationSec) : null) : (readingStats ? readingStats.text : null)}
|
readingTimeText={readingStats ? readingStats.text : null}
|
||||||
hasHighlights={hasHighlights}
|
hasHighlights={hasHighlights}
|
||||||
highlightCount={relevantHighlights.length}
|
highlightCount={relevantHighlights.length}
|
||||||
settings={settings}
|
settings={settings}
|
||||||
highlights={relevantHighlights}
|
highlights={relevantHighlights}
|
||||||
highlightVisibility={highlightVisibility}
|
highlightVisibility={highlightVisibility}
|
||||||
|
onHighlightCountClick={onOpenHighlights}
|
||||||
/>
|
/>
|
||||||
{isTextContent && articleText && (
|
{isTextContent && articleText && (
|
||||||
<div style={{ padding: '0 0.75rem 0.5rem 0.75rem' }}>
|
<div style={{ padding: '0 0.75rem 0.5rem 0.75rem' }}>
|
||||||
<TTSControls text={articleText} defaultLang={navigator?.language} settings={settings} />
|
<TTSControls text={articleText} defaultLang={navigator?.language} settings={settings} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{isExternalVideo ? (
|
{loading || !markdown && !html ? (
|
||||||
<>
|
<div className="reader" aria-busy="true">
|
||||||
<div className="reader-video">
|
<ContentSkeleton />
|
||||||
<ReactPlayer
|
</div>
|
||||||
url={selectedUrl as string}
|
|
||||||
controls
|
|
||||||
width="100%"
|
|
||||||
height="auto"
|
|
||||||
style={{
|
|
||||||
width: '100%',
|
|
||||||
height: 'auto',
|
|
||||||
aspectRatio: '16/9'
|
|
||||||
}}
|
|
||||||
onDuration={(d) => setVideoDurationSec(Math.floor(d))}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
{ytMeta?.description && (
|
|
||||||
<div className="large-text" style={{ color: '#ddd', padding: '0 0.75rem', whiteSpace: 'pre-wrap', marginBottom: '0.75rem' }}>
|
|
||||||
{ytMeta.description}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{ytMeta?.transcript && (
|
|
||||||
<div style={{ padding: '0 0.75rem 1rem 0.75rem' }}>
|
|
||||||
<h3 style={{ margin: '1rem 0 0.5rem 0', fontSize: '1rem', color: '#aaa' }}>Transcript</h3>
|
|
||||||
<div className="large-text" style={{ whiteSpace: 'pre-wrap', color: '#ddd' }}>
|
|
||||||
{ytMeta.transcript}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<div className="article-menu-container">
|
|
||||||
<div className="article-menu-wrapper" ref={videoMenuRef}>
|
|
||||||
<button
|
|
||||||
className="article-menu-btn"
|
|
||||||
onClick={toggleVideoMenu}
|
|
||||||
title="More options"
|
|
||||||
>
|
|
||||||
<FontAwesomeIcon icon={faEllipsisH} />
|
|
||||||
</button>
|
|
||||||
{showVideoMenu && (
|
|
||||||
<div className={`article-menu ${videoMenuOpenUpward ? 'open-upward' : ''}`}>
|
|
||||||
<button className="article-menu-item" onClick={handleOpenVideoExternal}>
|
|
||||||
<FontAwesomeIcon icon={faExternalLinkAlt} />
|
|
||||||
<span>Open Link</span>
|
|
||||||
</button>
|
|
||||||
<button className="article-menu-item" onClick={handleOpenVideoNative}>
|
|
||||||
<FontAwesomeIcon icon={faMobileAlt} />
|
|
||||||
<span>Open in Native App</span>
|
|
||||||
</button>
|
|
||||||
<button className="article-menu-item" onClick={handleCopyVideoUrl}>
|
|
||||||
<FontAwesomeIcon icon={faCopy} />
|
|
||||||
<span>Copy URL</span>
|
|
||||||
</button>
|
|
||||||
<button className="article-menu-item" onClick={handleShareVideoUrl}>
|
|
||||||
<FontAwesomeIcon icon={faShare} />
|
|
||||||
<span>Share</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{activeAccount && (
|
|
||||||
<div className="mark-as-read-container">
|
|
||||||
<button
|
|
||||||
className={`mark-as-read-btn ${isMarkedAsRead ? 'marked' : ''} ${showCheckAnimation ? 'animating' : ''}`}
|
|
||||||
onClick={handleMarkAsRead}
|
|
||||||
disabled={isCheckingReadStatus}
|
|
||||||
title={isMarkedAsRead ? 'Already Marked as Watched' : 'Mark as Watched'}
|
|
||||||
style={isMarkedAsRead ? { opacity: 0.85 } : undefined}
|
|
||||||
>
|
|
||||||
<FontAwesomeIcon
|
|
||||||
icon={isCheckingReadStatus ? faSpinner : isMarkedAsRead ? faCheckCircle : faBooks}
|
|
||||||
spin={isCheckingReadStatus}
|
|
||||||
/>
|
|
||||||
<span>
|
|
||||||
{isCheckingReadStatus ? 'Checking...' : isMarkedAsRead ? 'Marked as Watched' : 'Mark as Watched'}
|
|
||||||
</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
) : markdown || html ? (
|
) : markdown || html ? (
|
||||||
<>
|
<>
|
||||||
{markdown ? (
|
{markdown ? (
|
||||||
renderedMarkdownHtml && finalHtml ? (
|
renderedMarkdownHtml && finalHtml ? (
|
||||||
<VideoEmbedProcessor
|
<VideoEmbedProcessor
|
||||||
|
key={`content:${contentKey}`}
|
||||||
ref={contentRef}
|
ref={contentRef}
|
||||||
html={finalHtml}
|
html={finalHtml}
|
||||||
renderVideoLinksAsEmbeds={settings?.renderVideoLinksAsEmbeds === true && !isExternalVideo}
|
renderVideoLinksAsEmbeds={settings?.renderVideoLinksAsEmbeds === true}
|
||||||
className="reader-markdown"
|
className="reader-markdown"
|
||||||
onMouseUp={handleSelectionEnd}
|
|
||||||
onTouchEnd={handleSelectionEnd}
|
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className="reader-markdown">
|
<div className="reader-markdown">
|
||||||
<div className="loading-spinner">
|
<ContentSkeleton />
|
||||||
<FontAwesomeIcon icon={faSpinner} spin size="sm" />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
) : (
|
) : (
|
||||||
<VideoEmbedProcessor
|
<VideoEmbedProcessor
|
||||||
|
key={`content:${contentKey}`}
|
||||||
ref={contentRef}
|
ref={contentRef}
|
||||||
html={finalHtml || html || ''}
|
html={finalHtml || html || ''}
|
||||||
renderVideoLinksAsEmbeds={settings?.renderVideoLinksAsEmbeds === true && !isExternalVideo}
|
renderVideoLinksAsEmbeds={settings?.renderVideoLinksAsEmbeds === true}
|
||||||
className="reader-html"
|
className="reader-html"
|
||||||
onMouseUp={handleSelectionEnd}
|
|
||||||
onTouchEnd={handleSelectionEnd}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Article menu for external URLs */}
|
{/* Article menu for external URLs */}
|
||||||
{!isNostrArticle && !isExternalVideo && selectedUrl && (
|
{!isNostrArticle && selectedUrl && (
|
||||||
<div className="article-menu-container">
|
<div className="article-menu-container">
|
||||||
<div className="article-menu-wrapper" ref={externalMenuRef}>
|
<div className="article-menu-wrapper" ref={externalMenuRef}>
|
||||||
<button
|
<button
|
||||||
@@ -927,13 +859,16 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
<FontAwesomeIcon icon={faCopy} />
|
<FontAwesomeIcon icon={faCopy} />
|
||||||
<span>Copy URL</span>
|
<span>Copy URL</span>
|
||||||
</button>
|
</button>
|
||||||
<button
|
{/* Only show "Open Original" for actual external URLs, not nostr events */}
|
||||||
className="article-menu-item"
|
{!selectedUrl?.startsWith('nostr-event:') && (
|
||||||
onClick={handleOpenExternalUrl}
|
<button
|
||||||
>
|
className="article-menu-item"
|
||||||
<FontAwesomeIcon icon={faExternalLinkAlt} />
|
onClick={handleOpenExternalUrl}
|
||||||
<span>Open Original</span>
|
>
|
||||||
</button>
|
<FontAwesomeIcon icon={faExternalLinkAlt} />
|
||||||
|
<span>Open Original</span>
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
<button
|
<button
|
||||||
className="article-menu-item"
|
className="article-menu-item"
|
||||||
onClick={handleSearchExternalUrl}
|
onClick={handleSearchExternalUrl}
|
||||||
@@ -1048,11 +983,7 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
) : (
|
) : null}
|
||||||
<div className="reader empty">
|
|
||||||
<p>No readable content found for this URL.</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
import React from 'react'
|
|
||||||
import { useEventModel } from 'applesauce-react/hooks'
|
|
||||||
import { Models, Helpers } from 'applesauce-core'
|
|
||||||
import { decode } from 'nostr-tools/nip19'
|
|
||||||
import { extractNprofilePubkeys } from '../utils/helpers'
|
|
||||||
|
|
||||||
const { getPubkeyFromDecodeResult } = Helpers
|
|
||||||
|
|
||||||
interface Props { content: string }
|
|
||||||
|
|
||||||
const ContentWithResolvedProfiles: React.FC<Props> = ({ content }) => {
|
|
||||||
const matches = extractNprofilePubkeys(content)
|
|
||||||
const decoded = matches
|
|
||||||
.map((m) => {
|
|
||||||
try { return decode(m) } catch { return undefined as undefined }
|
|
||||||
})
|
|
||||||
.filter((v): v is ReturnType<typeof decode> => Boolean(v))
|
|
||||||
|
|
||||||
const lookups = decoded
|
|
||||||
.map((res) => getPubkeyFromDecodeResult(res))
|
|
||||||
.filter((v): v is string => typeof v === 'string')
|
|
||||||
|
|
||||||
const profiles = lookups.map((pubkey) => ({ pubkey, profile: useEventModel(Models.ProfileModel, [pubkey]) }))
|
|
||||||
|
|
||||||
let rendered = content
|
|
||||||
matches.forEach((m, i) => {
|
|
||||||
const pk = getPubkeyFromDecodeResult(decoded[i])
|
|
||||||
const found = profiles.find((p) => p.pubkey === pk)
|
|
||||||
const name = found?.profile?.name || found?.profile?.display_name || found?.profile?.nip05 || `${pk?.slice(0,8)}...`
|
|
||||||
if (name) rendered = rendered.replace(m, `@${name}`)
|
|
||||||
})
|
|
||||||
|
|
||||||
return <div className="bookmark-content">{rendered}</div>
|
|
||||||
}
|
|
||||||
|
|
||||||
export default ContentWithResolvedProfiles
|
|
||||||
|
|
||||||
|
|
||||||
@@ -781,9 +781,16 @@ const Debug: React.FC<DebugProps> = ({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Load deduplicated results via controller
|
// Load deduplicated results via controller (includes articles and external URLs)
|
||||||
const unsubProgress = readingProgressController.onProgress((progressMap) => {
|
const unsubProgress = readingProgressController.onProgress((progressMap) => {
|
||||||
setDeduplicatedProgressMap(new Map(progressMap))
|
setDeduplicatedProgressMap(new Map(progressMap))
|
||||||
|
|
||||||
|
// Regression guard: ensure keys include both naddr and raw URL forms when present
|
||||||
|
try {
|
||||||
|
const keys = Array.from(progressMap.keys())
|
||||||
|
const sample = keys.slice(0, 5).join(', ')
|
||||||
|
DebugBus.info('debug', `Progress keys sample: ${sample}`)
|
||||||
|
} catch { /* ignore */ }
|
||||||
})
|
})
|
||||||
|
|
||||||
// Run both in parallel
|
// Run both in parallel
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { useState, useEffect, useMemo, useCallback, useRef } from 'react'
|
import React, { useState, useEffect, useMemo, useCallback, useRef } from 'react'
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||||
import { faNewspaper, faHighlighter, faUser, faUserGroup, faNetworkWired, faArrowsRotate, faSpinner } from '@fortawesome/free-solid-svg-icons'
|
import { faPersonHiking, faNewspaper, faHighlighter, faUser, faUserGroup, faNetworkWired, faArrowsRotate } from '@fortawesome/free-solid-svg-icons'
|
||||||
import IconButton from './IconButton'
|
import IconButton from './IconButton'
|
||||||
import { BlogPostSkeleton, HighlightSkeleton } from './Skeletons'
|
import { BlogPostSkeleton, HighlightSkeleton } from './Skeletons'
|
||||||
import { Hooks } from 'applesauce-react'
|
import { Hooks } from 'applesauce-react'
|
||||||
@@ -82,11 +82,28 @@ const Explore: React.FC<ExploreProps> = ({ relayPool, eventStore, settings, acti
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Visibility filters (defaults from settings or nostrverse when logged out)
|
// Visibility filters - load from localStorage first, fallback to settings
|
||||||
const [visibility, setVisibility] = useState<HighlightVisibility>({
|
const [visibility, setVisibility] = useState<HighlightVisibility>(() => {
|
||||||
nostrverse: activeAccount ? (settings?.defaultExploreScopeNostrverse ?? false) : true,
|
// Try to load from localStorage first
|
||||||
friends: settings?.defaultExploreScopeFriends ?? true,
|
try {
|
||||||
mine: settings?.defaultExploreScopeMine ?? false
|
const saved = localStorage.getItem('exploreScopeVisibility')
|
||||||
|
if (saved) {
|
||||||
|
const parsed = JSON.parse(saved)
|
||||||
|
// Validate that at least one scope is enabled
|
||||||
|
if (parsed.nostrverse || parsed.friends || parsed.mine) {
|
||||||
|
return parsed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('Failed to load explore scope from localStorage:', err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to settings or defaults
|
||||||
|
return {
|
||||||
|
nostrverse: activeAccount ? (settings?.defaultExploreScopeNostrverse ?? false) : true,
|
||||||
|
friends: settings?.defaultExploreScopeFriends ?? true,
|
||||||
|
mine: settings?.defaultExploreScopeMine ?? false
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Ensure at least one scope remains active
|
// Ensure at least one scope remains active
|
||||||
@@ -96,6 +113,12 @@ const Explore: React.FC<ExploreProps> = ({ relayPool, eventStore, settings, acti
|
|||||||
if (!next.nostrverse && !next.friends && !next.mine) {
|
if (!next.nostrverse && !next.friends && !next.mine) {
|
||||||
return prev // ignore toggle that would disable all scopes
|
return prev // ignore toggle that would disable all scopes
|
||||||
}
|
}
|
||||||
|
// Persist to localStorage
|
||||||
|
try {
|
||||||
|
localStorage.setItem('exploreScopeVisibility', JSON.stringify(next))
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('Failed to save explore scope to localStorage:', err)
|
||||||
|
}
|
||||||
return next
|
return next
|
||||||
})
|
})
|
||||||
}, [])
|
}, [])
|
||||||
@@ -224,18 +247,44 @@ const Explore: React.FC<ExploreProps> = ({ relayPool, eventStore, settings, acti
|
|||||||
|
|
||||||
// Update visibility when settings/login state changes
|
// Update visibility when settings/login state changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// Check if user has a saved preference
|
||||||
|
const hasSavedPreference = (() => {
|
||||||
|
try {
|
||||||
|
return localStorage.getItem('exploreScopeVisibility') !== null
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
|
||||||
|
// Only reset to defaults if no saved preference exists
|
||||||
|
if (hasSavedPreference) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (!activeAccount) {
|
if (!activeAccount) {
|
||||||
// When logged out, show nostrverse by default
|
// When logged out, show nostrverse by default
|
||||||
setVisibility(prev => ({ ...prev, nostrverse: true, friends: false, mine: false }))
|
const defaultVisibility = { nostrverse: true, friends: false, mine: false }
|
||||||
|
setVisibility(defaultVisibility)
|
||||||
|
try {
|
||||||
|
localStorage.setItem('exploreScopeVisibility', JSON.stringify(defaultVisibility))
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('Failed to save explore scope to localStorage:', err)
|
||||||
|
}
|
||||||
setHasLoadedNostrverse(true) // logged out path loads nostrverse immediately
|
setHasLoadedNostrverse(true) // logged out path loads nostrverse immediately
|
||||||
setHasLoadedNostrverseHighlights(true)
|
setHasLoadedNostrverseHighlights(true)
|
||||||
} else {
|
} else {
|
||||||
// When logged in, use settings defaults immediately
|
// When logged in, use settings defaults immediately
|
||||||
setVisibility({
|
const defaultVisibility = {
|
||||||
nostrverse: settings?.defaultExploreScopeNostrverse ?? false,
|
nostrverse: settings?.defaultExploreScopeNostrverse ?? false,
|
||||||
friends: settings?.defaultExploreScopeFriends ?? true,
|
friends: settings?.defaultExploreScopeFriends ?? true,
|
||||||
mine: settings?.defaultExploreScopeMine ?? false
|
mine: settings?.defaultExploreScopeMine ?? false
|
||||||
})
|
}
|
||||||
|
setVisibility(defaultVisibility)
|
||||||
|
try {
|
||||||
|
localStorage.setItem('exploreScopeVisibility', JSON.stringify(defaultVisibility))
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('Failed to save explore scope to localStorage:', err)
|
||||||
|
}
|
||||||
setHasLoadedNostrverse(false)
|
setHasLoadedNostrverse(false)
|
||||||
setHasLoadedNostrverseHighlights(false)
|
setHasLoadedNostrverseHighlights(false)
|
||||||
}
|
}
|
||||||
@@ -523,8 +572,10 @@ const Explore: React.FC<ExploreProps> = ({ relayPool, eventStore, settings, acti
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
return filteredBlogPosts.length === 0 ? (
|
return filteredBlogPosts.length === 0 ? (
|
||||||
<div className="explore-loading" style={{ gridColumn: '1/-1', display: 'flex', justifyContent: 'center', alignItems: 'center', padding: '4rem', color: 'var(--text-secondary)' }}>
|
<div className="explore-grid">
|
||||||
<FontAwesomeIcon icon={faSpinner} spin size="2x" />
|
{Array.from({ length: 6 }).map((_, i) => (
|
||||||
|
<BlogPostSkeleton key={i} />
|
||||||
|
))}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="explore-grid">
|
<div className="explore-grid">
|
||||||
@@ -584,7 +635,7 @@ const Explore: React.FC<ExploreProps> = ({ relayPool, eventStore, settings, acti
|
|||||||
/>
|
/>
|
||||||
<div className="explore-header">
|
<div className="explore-header">
|
||||||
<h1>
|
<h1>
|
||||||
<FontAwesomeIcon icon={faNewspaper} />
|
<FontAwesomeIcon icon={faPersonHiking} />
|
||||||
Explore
|
Explore
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
@@ -656,7 +707,7 @@ const Explore: React.FC<ExploreProps> = ({ relayPool, eventStore, settings, acti
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div key={activeTab}>
|
<div>
|
||||||
{renderTabContent()}
|
{renderTabContent()}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export const HighlightButton = React.forwardRef<HighlightButtonRef, HighlightBut
|
|||||||
className="highlight-fab"
|
className="highlight-fab"
|
||||||
style={{
|
style={{
|
||||||
position: 'fixed',
|
position: 'fixed',
|
||||||
bottom: '32px',
|
bottom: '80px',
|
||||||
right: '32px',
|
right: '32px',
|
||||||
zIndex: 1000,
|
zIndex: 1000,
|
||||||
width: '56px',
|
width: '56px',
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { Models } from 'applesauce-core'
|
|||||||
import { nip19 } from 'nostr-tools'
|
import { nip19 } from 'nostr-tools'
|
||||||
import { fetchArticleTitle } from '../services/articleTitleResolver'
|
import { fetchArticleTitle } from '../services/articleTitleResolver'
|
||||||
import { Highlight } from '../types/highlights'
|
import { Highlight } from '../types/highlights'
|
||||||
|
import { getProfileDisplayName } from '../utils/nostrUriResolver'
|
||||||
|
|
||||||
interface HighlightCitationProps {
|
interface HighlightCitationProps {
|
||||||
highlight: Highlight
|
highlight: Highlight
|
||||||
@@ -79,7 +80,8 @@ export const HighlightCitation: React.FC<HighlightCitationProps> = ({
|
|||||||
loadTitle()
|
loadTitle()
|
||||||
}, [highlight.eventReference, relayPool])
|
}, [highlight.eventReference, relayPool])
|
||||||
|
|
||||||
const authorName = authorProfile?.name || authorProfile?.display_name
|
// Use centralized profile display name utility
|
||||||
|
const authorName = authorPubkey ? getProfileDisplayName(authorProfile, authorPubkey) : undefined
|
||||||
|
|
||||||
// For nostr-native content with article reference
|
// For nostr-native content with article reference
|
||||||
if (highlight.eventReference && (authorName || articleTitle)) {
|
if (highlight.eventReference && (authorName || articleTitle)) {
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import { useEventModel } from 'applesauce-react/hooks'
|
|||||||
import { Models, IEventStore } from 'applesauce-core'
|
import { Models, IEventStore } from 'applesauce-core'
|
||||||
import { RelayPool } from 'applesauce-relay'
|
import { RelayPool } from 'applesauce-relay'
|
||||||
import { Hooks } from 'applesauce-react'
|
import { Hooks } from 'applesauce-react'
|
||||||
import { onSyncStateChange, isEventSyncing } from '../services/offlineSyncService'
|
import { onSyncStateChange, isEventSyncing, isEventOfflineCreated } from '../services/offlineSyncService'
|
||||||
import { areAllRelaysLocal } from '../utils/helpers'
|
import { areAllRelaysLocal, isLocalRelay } from '../utils/helpers'
|
||||||
import { getActiveRelayUrls } from '../services/relayManager'
|
import { getActiveRelayUrls } from '../services/relayManager'
|
||||||
import { nip19 } from 'nostr-tools'
|
import { nip19 } from 'nostr-tools'
|
||||||
import { formatDateCompact } from '../utils/bookmarkUtils'
|
import { formatDateCompact } from '../utils/bookmarkUtils'
|
||||||
@@ -18,6 +18,7 @@ import CompactButton from './CompactButton'
|
|||||||
import { HighlightCitation } from './HighlightCitation'
|
import { HighlightCitation } from './HighlightCitation'
|
||||||
import { useNavigate } from 'react-router-dom'
|
import { useNavigate } from 'react-router-dom'
|
||||||
import NostrMentionLink from './NostrMentionLink'
|
import NostrMentionLink from './NostrMentionLink'
|
||||||
|
import { getProfileDisplayName } from '../utils/nostrUriResolver'
|
||||||
|
|
||||||
// Helper to detect if a URL is an image
|
// Helper to detect if a URL is an image
|
||||||
const isImageUrl = (url: string): boolean => {
|
const isImageUrl = (url: string): boolean => {
|
||||||
@@ -114,7 +115,6 @@ export const HighlightItem: React.FC<HighlightItemProps> = ({
|
|||||||
const itemRef = useRef<HTMLDivElement>(null)
|
const itemRef = useRef<HTMLDivElement>(null)
|
||||||
const menuRef = useRef<HTMLDivElement>(null)
|
const menuRef = useRef<HTMLDivElement>(null)
|
||||||
const [isSyncing, setIsSyncing] = useState(() => isEventSyncing(highlight.id))
|
const [isSyncing, setIsSyncing] = useState(() => isEventSyncing(highlight.id))
|
||||||
const [showOfflineIndicator, setShowOfflineIndicator] = useState(() => highlight.isOfflineCreated && !isSyncing)
|
|
||||||
const [isRebroadcasting, setIsRebroadcasting] = useState(false)
|
const [isRebroadcasting, setIsRebroadcasting] = useState(false)
|
||||||
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false)
|
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false)
|
||||||
const [isDeleting, setIsDeleting] = useState(false)
|
const [isDeleting, setIsDeleting] = useState(false)
|
||||||
@@ -128,17 +128,9 @@ export const HighlightItem: React.FC<HighlightItemProps> = ({
|
|||||||
|
|
||||||
// Get display name for the user
|
// Get display name for the user
|
||||||
const getUserDisplayName = () => {
|
const getUserDisplayName = () => {
|
||||||
if (profile?.name) return profile.name
|
return getProfileDisplayName(profile, highlight.pubkey)
|
||||||
if (profile?.display_name) return profile.display_name
|
|
||||||
return `${highlight.pubkey.slice(0, 8)}...` // fallback to short pubkey
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update offline indicator when highlight prop changes
|
|
||||||
useEffect(() => {
|
|
||||||
if (highlight.isOfflineCreated && !isSyncing) {
|
|
||||||
setShowOfflineIndicator(true)
|
|
||||||
}
|
|
||||||
}, [highlight.isOfflineCreated, isSyncing])
|
|
||||||
|
|
||||||
// Listen to sync state changes
|
// Listen to sync state changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -147,8 +139,6 @@ export const HighlightItem: React.FC<HighlightItemProps> = ({
|
|||||||
setIsSyncing(syncingState)
|
setIsSyncing(syncingState)
|
||||||
// When sync completes successfully, update highlight to show all relays
|
// When sync completes successfully, update highlight to show all relays
|
||||||
if (!syncingState) {
|
if (!syncingState) {
|
||||||
setShowOfflineIndicator(false)
|
|
||||||
|
|
||||||
// Update the highlight with all relays after successful sync
|
// Update the highlight with all relays after successful sync
|
||||||
if (onHighlightUpdate && highlight.isLocalOnly && relayPool) {
|
if (onHighlightUpdate && highlight.isLocalOnly && relayPool) {
|
||||||
const updatedHighlight = {
|
const updatedHighlight = {
|
||||||
@@ -212,12 +202,23 @@ export const HighlightItem: React.FC<HighlightItemProps> = ({
|
|||||||
pubkey,
|
pubkey,
|
||||||
identifier
|
identifier
|
||||||
})
|
})
|
||||||
navigate(`/a/${naddr}`)
|
// Pass highlight ID in navigation state to trigger scroll
|
||||||
|
navigate(`/a/${naddr}`, {
|
||||||
|
state: {
|
||||||
|
highlightId: highlight.id,
|
||||||
|
openHighlights: true
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (highlight.urlReference) {
|
} else if (highlight.urlReference) {
|
||||||
// Navigate to external URL
|
// Navigate to external URL with highlight ID to trigger scroll
|
||||||
navigate(`/r/${encodeURIComponent(highlight.urlReference)}`)
|
navigate(`/r/${encodeURIComponent(highlight.urlReference)}`, {
|
||||||
|
state: {
|
||||||
|
highlightId: highlight.id,
|
||||||
|
openHighlights: true
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,9 +282,6 @@ export const HighlightItem: React.FC<HighlightItemProps> = ({
|
|||||||
onHighlightUpdate(updatedHighlight)
|
onHighlightUpdate(updatedHighlight)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update local state
|
|
||||||
setShowOfflineIndicator(false)
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('❌ Failed to rebroadcast:', error)
|
console.error('❌ Failed to rebroadcast:', error)
|
||||||
} finally {
|
} finally {
|
||||||
@@ -302,8 +300,37 @@ export const HighlightItem: React.FC<HighlightItemProps> = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always show relay list, use plane icon for local-only
|
// Check if this highlight was only published to local relays
|
||||||
const isLocalOrOffline = highlight.isLocalOnly || showOfflineIndicator
|
let isLocalOnly = highlight.isLocalOnly
|
||||||
|
const publishedRelays = highlight.publishedRelays || []
|
||||||
|
|
||||||
|
// Fallback 1: Check if this highlight was marked for offline sync (flight mode)
|
||||||
|
if (isLocalOnly === undefined) {
|
||||||
|
if (isEventOfflineCreated(highlight.id)) {
|
||||||
|
isLocalOnly = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback 2: If publishedRelays only contains local relays, it's local-only
|
||||||
|
if (isLocalOnly === undefined && publishedRelays.length > 0) {
|
||||||
|
const hasOnlyLocalRelays = publishedRelays.every(url => isLocalRelay(url))
|
||||||
|
const hasRemoteRelays = publishedRelays.some(url => !isLocalRelay(url))
|
||||||
|
if (hasOnlyLocalRelays && !hasRemoteRelays) {
|
||||||
|
isLocalOnly = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// If isLocalOnly is true (from any fallback), show airplane icon
|
||||||
|
if (isLocalOnly === true) {
|
||||||
|
return {
|
||||||
|
icon: faPlane,
|
||||||
|
tooltip: publishedRelays.length > 0
|
||||||
|
? 'Local relays only - will sync when remote relays available'
|
||||||
|
: 'Created in flight mode - will sync when remote relays available',
|
||||||
|
spin: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Show highlighter icon with relay info if available
|
// Show highlighter icon with relay info if available
|
||||||
if (highlight.publishedRelays && highlight.publishedRelays.length > 0) {
|
if (highlight.publishedRelays && highlight.publishedRelays.length > 0) {
|
||||||
@@ -311,7 +338,7 @@ export const HighlightItem: React.FC<HighlightItemProps> = ({
|
|||||||
url.replace(/^wss?:\/\//, '').replace(/\/$/, '')
|
url.replace(/^wss?:\/\//, '').replace(/\/$/, '')
|
||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
icon: isLocalOrOffline ? faPlane : faHighlighter,
|
icon: faHighlighter,
|
||||||
tooltip: relayNames.join('\n'),
|
tooltip: relayNames.join('\n'),
|
||||||
spin: false
|
spin: false
|
||||||
}
|
}
|
||||||
@@ -422,7 +449,31 @@ export const HighlightItem: React.FC<HighlightItemProps> = ({
|
|||||||
title={new Date(highlight.created_at * 1000).toLocaleString()}
|
title={new Date(highlight.created_at * 1000).toLocaleString()}
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
window.location.href = highlightLinks.native
|
// Navigate within app using same logic as handleItemClick
|
||||||
|
if (highlight.eventReference) {
|
||||||
|
const parts = highlight.eventReference.split(':')
|
||||||
|
if (parts.length === 3 && parts[0] === '30023') {
|
||||||
|
const [, pubkey, identifier] = parts
|
||||||
|
const naddr = nip19.naddrEncode({
|
||||||
|
kind: 30023,
|
||||||
|
pubkey,
|
||||||
|
identifier
|
||||||
|
})
|
||||||
|
navigate(`/a/${naddr}`, {
|
||||||
|
state: {
|
||||||
|
highlightId: highlight.id,
|
||||||
|
openHighlights: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else if (highlight.urlReference) {
|
||||||
|
navigate(`/r/${encodeURIComponent(highlight.urlReference)}`, {
|
||||||
|
state: {
|
||||||
|
highlightId: highlight.id,
|
||||||
|
openHighlights: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{formatDateCompact(highlight.created_at)}
|
{formatDateCompact(highlight.created_at)}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ interface HighlightsPanelProps {
|
|||||||
relayPool?: RelayPool | null
|
relayPool?: RelayPool | null
|
||||||
eventStore?: IEventStore | null
|
eventStore?: IEventStore | null
|
||||||
settings?: UserSettings
|
settings?: UserSettings
|
||||||
|
isMobile?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export const HighlightsPanel: React.FC<HighlightsPanelProps> = ({
|
export const HighlightsPanel: React.FC<HighlightsPanelProps> = ({
|
||||||
@@ -56,7 +57,8 @@ export const HighlightsPanel: React.FC<HighlightsPanelProps> = ({
|
|||||||
followedPubkeys = new Set(),
|
followedPubkeys = new Set(),
|
||||||
relayPool,
|
relayPool,
|
||||||
eventStore,
|
eventStore,
|
||||||
settings
|
settings,
|
||||||
|
isMobile = false
|
||||||
}) => {
|
}) => {
|
||||||
const [showHighlights, setShowHighlights] = useState(true)
|
const [showHighlights, setShowHighlights] = useState(true)
|
||||||
const [localHighlights, setLocalHighlights] = useState(highlights)
|
const [localHighlights, setLocalHighlights] = useState(highlights)
|
||||||
@@ -116,15 +118,14 @@ export const HighlightsPanel: React.FC<HighlightsPanelProps> = ({
|
|||||||
return (
|
return (
|
||||||
<div className="highlights-container">
|
<div className="highlights-container">
|
||||||
<HighlightsPanelHeader
|
<HighlightsPanelHeader
|
||||||
loading={loading}
|
|
||||||
hasHighlights={filteredHighlights.length > 0}
|
hasHighlights={filteredHighlights.length > 0}
|
||||||
showHighlights={showHighlights}
|
showHighlights={showHighlights}
|
||||||
highlightVisibility={highlightVisibility}
|
highlightVisibility={highlightVisibility}
|
||||||
currentUserPubkey={currentUserPubkey}
|
currentUserPubkey={currentUserPubkey}
|
||||||
onToggleHighlights={handleToggleHighlights}
|
onToggleHighlights={handleToggleHighlights}
|
||||||
onRefresh={onRefresh}
|
|
||||||
onToggleCollapse={onToggleCollapse}
|
onToggleCollapse={onToggleCollapse}
|
||||||
onHighlightVisibilityChange={onHighlightVisibilityChange}
|
onHighlightVisibilityChange={onHighlightVisibilityChange}
|
||||||
|
isMobile={isMobile}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{loading && filteredHighlights.length === 0 ? (
|
{loading && filteredHighlights.length === 0 ? (
|
||||||
|
|||||||
@@ -1,35 +1,44 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { faChevronRight, faEye, faEyeSlash, faRotate, faUser, faUserGroup, faNetworkWired } from '@fortawesome/free-solid-svg-icons'
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||||
|
import { faChevronRight, faEye, faEyeSlash, faUser, faUserGroup, faNetworkWired } from '@fortawesome/free-solid-svg-icons'
|
||||||
import { HighlightVisibility } from '../HighlightsPanel'
|
import { HighlightVisibility } from '../HighlightsPanel'
|
||||||
import IconButton from '../IconButton'
|
import IconButton from '../IconButton'
|
||||||
|
|
||||||
interface HighlightsPanelHeaderProps {
|
interface HighlightsPanelHeaderProps {
|
||||||
loading: boolean
|
|
||||||
hasHighlights: boolean
|
hasHighlights: boolean
|
||||||
showHighlights: boolean
|
showHighlights: boolean
|
||||||
highlightVisibility: HighlightVisibility
|
highlightVisibility: HighlightVisibility
|
||||||
currentUserPubkey?: string
|
currentUserPubkey?: string
|
||||||
onToggleHighlights: () => void
|
onToggleHighlights: () => void
|
||||||
onRefresh?: () => void
|
|
||||||
onToggleCollapse: () => void
|
onToggleCollapse: () => void
|
||||||
onHighlightVisibilityChange?: (visibility: HighlightVisibility) => void
|
onHighlightVisibilityChange?: (visibility: HighlightVisibility) => void
|
||||||
|
isMobile?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const HighlightsPanelHeader: React.FC<HighlightsPanelHeaderProps> = ({
|
const HighlightsPanelHeader: React.FC<HighlightsPanelHeaderProps> = ({
|
||||||
loading,
|
|
||||||
hasHighlights,
|
hasHighlights,
|
||||||
showHighlights,
|
showHighlights,
|
||||||
highlightVisibility,
|
highlightVisibility,
|
||||||
currentUserPubkey,
|
currentUserPubkey,
|
||||||
onToggleHighlights,
|
onToggleHighlights,
|
||||||
onRefresh,
|
|
||||||
onToggleCollapse,
|
onToggleCollapse,
|
||||||
onHighlightVisibilityChange
|
onHighlightVisibilityChange,
|
||||||
|
isMobile = false
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<div className="highlights-header">
|
<div className="highlights-header">
|
||||||
<div className="highlights-actions">
|
<div className="highlights-actions">
|
||||||
<div className="highlights-actions-left">
|
<div className="highlights-actions-left">
|
||||||
|
{!isMobile && (
|
||||||
|
<button
|
||||||
|
onClick={onToggleCollapse}
|
||||||
|
className="toggle-highlights-btn"
|
||||||
|
title="Collapse highlights panel"
|
||||||
|
aria-label="Collapse highlights panel"
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon={faChevronRight} style={{ transform: 'rotate(180deg)' }} />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
{onHighlightVisibilityChange && (
|
{onHighlightVisibilityChange && (
|
||||||
<div className="highlight-level-toggles">
|
<div className="highlight-level-toggles">
|
||||||
<IconButton
|
<IconButton
|
||||||
@@ -80,17 +89,8 @@ const HighlightsPanelHeader: React.FC<HighlightsPanelHeaderProps> = ({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{onRefresh && (
|
</div>
|
||||||
<IconButton
|
<div className="highlights-actions-right">
|
||||||
icon={faRotate}
|
|
||||||
onClick={onRefresh}
|
|
||||||
title="Refresh highlights"
|
|
||||||
ariaLabel="Refresh highlights"
|
|
||||||
variant="ghost"
|
|
||||||
disabled={loading}
|
|
||||||
spin={loading}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{hasHighlights && (
|
{hasHighlights && (
|
||||||
<IconButton
|
<IconButton
|
||||||
icon={showHighlights ? faEye : faEyeSlash}
|
icon={showHighlights ? faEye : faEyeSlash}
|
||||||
@@ -101,14 +101,6 @@ const HighlightsPanelHeader: React.FC<HighlightsPanelHeaderProps> = ({
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<IconButton
|
|
||||||
icon={faChevronRight}
|
|
||||||
onClick={onToggleCollapse}
|
|
||||||
title="Collapse highlights panel"
|
|
||||||
ariaLabel="Collapse highlights panel"
|
|
||||||
variant="ghost"
|
|
||||||
style={{ transform: 'rotate(180deg)' }}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import React, { useState, useEffect, useCallback } from 'react'
|
import React, { useState, useEffect, useCallback } from 'react'
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||||
import { faHighlighter, faBookmark, faPenToSquare, faLink, faLayerGroup, faBars } from '@fortawesome/free-solid-svg-icons'
|
import { faHighlighter, faBookmark, faPenToSquare, faLink, faLayerGroup, faHeart } from '@fortawesome/free-solid-svg-icons'
|
||||||
|
import { faClock } from '@fortawesome/free-regular-svg-icons'
|
||||||
import { Hooks } from 'applesauce-react'
|
import { Hooks } from 'applesauce-react'
|
||||||
import { IEventStore } from 'applesauce-core'
|
import { IEventStore } from 'applesauce-core'
|
||||||
import { BlogPostSkeleton, HighlightSkeleton, BookmarkSkeleton } from './Skeletons'
|
import { BlogPostSkeleton, HighlightSkeleton, BookmarkSkeleton } from './Skeletons'
|
||||||
@@ -23,7 +24,8 @@ import { getCachedMeData, updateCachedHighlights } from '../services/meCache'
|
|||||||
import { faBooks } from '../icons/customIcons'
|
import { faBooks } from '../icons/customIcons'
|
||||||
import { usePullToRefresh } from 'use-pull-to-refresh'
|
import { usePullToRefresh } from 'use-pull-to-refresh'
|
||||||
import RefreshIndicator from './RefreshIndicator'
|
import RefreshIndicator from './RefreshIndicator'
|
||||||
import { groupIndividualBookmarks, hasContent, hasCreationDate } from '../utils/bookmarkUtils'
|
import { groupIndividualBookmarks, hasContent, hasCreationDate, sortIndividualBookmarks } from '../utils/bookmarkUtils'
|
||||||
|
import { dedupeBookmarksById } from '../services/bookmarkHelpers'
|
||||||
import BookmarkFilters, { BookmarkFilterType } from './BookmarkFilters'
|
import BookmarkFilters, { BookmarkFilterType } from './BookmarkFilters'
|
||||||
import { filterBookmarksByType } from '../utils/bookmarkTypeClassifier'
|
import { filterBookmarksByType } from '../utils/bookmarkTypeClassifier'
|
||||||
import ReadingProgressFilters, { ReadingProgressFilterType } from './ReadingProgressFilters'
|
import ReadingProgressFilters, { ReadingProgressFilterType } from './ReadingProgressFilters'
|
||||||
@@ -42,7 +44,7 @@ interface MeProps {
|
|||||||
settings: UserSettings
|
settings: UserSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
type TabType = 'highlights' | 'reading-list' | 'reads' | 'links' | 'writings'
|
type TabType = 'highlights' | 'bookmarks' | 'reads' | 'links' | 'writings'
|
||||||
|
|
||||||
// Valid reading progress filters
|
// Valid reading progress filters
|
||||||
const VALID_FILTERS: ReadingProgressFilterType[] = ['all', 'unopened', 'started', 'reading', 'completed', 'highlighted', 'archive']
|
const VALID_FILTERS: ReadingProgressFilterType[] = ['all', 'unopened', 'started', 'reading', 'completed', 'highlighted', 'archive']
|
||||||
@@ -143,15 +145,15 @@ const Me: React.FC<MeProps> = ({
|
|||||||
setReadingProgressFilter(filter)
|
setReadingProgressFilter(filter)
|
||||||
if (activeTab === 'reads') {
|
if (activeTab === 'reads') {
|
||||||
if (filter === 'all') {
|
if (filter === 'all') {
|
||||||
navigate('/me/reads', { replace: true })
|
navigate('/my/reads', { replace: true })
|
||||||
} else {
|
} else {
|
||||||
navigate(`/me/reads/${filter}`, { replace: true })
|
navigate(`/my/reads/${filter}`, { replace: true })
|
||||||
}
|
}
|
||||||
} else if (activeTab === 'links') {
|
} else if (activeTab === 'links') {
|
||||||
if (filter === 'all') {
|
if (filter === 'all') {
|
||||||
navigate('/me/links', { replace: true })
|
navigate('/my/links', { replace: true })
|
||||||
} else {
|
} else {
|
||||||
navigate(`/me/links/${filter}`, { replace: true })
|
navigate(`/my/links/${filter}`, { replace: true })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -229,9 +231,9 @@ const Me: React.FC<MeProps> = ({
|
|||||||
if (!viewingPubkey || !activeAccount) return
|
if (!viewingPubkey || !activeAccount) return
|
||||||
|
|
||||||
setLoadedTabs(prev => {
|
setLoadedTabs(prev => {
|
||||||
const hasBeenLoaded = prev.has('reading-list')
|
const hasBeenLoaded = prev.has('bookmarks')
|
||||||
if (!hasBeenLoaded) setLoading(true)
|
if (!hasBeenLoaded) setLoading(true)
|
||||||
return new Set(prev).add('reading-list')
|
return new Set(prev).add('bookmarks')
|
||||||
})
|
})
|
||||||
|
|
||||||
// Always turn off loading after a tick
|
// Always turn off loading after a tick
|
||||||
@@ -278,8 +280,8 @@ const Me: React.FC<MeProps> = ({
|
|||||||
try {
|
try {
|
||||||
if (!hasBeenLoaded) setLoading(true)
|
if (!hasBeenLoaded) setLoading(true)
|
||||||
|
|
||||||
// Derive links from bookmarks immediately (bookmarks come from centralized loading in App.tsx)
|
// Derive links from bookmarks with OpenGraph enhancement
|
||||||
const initialLinks = deriveLinksFromBookmarks(bookmarks)
|
const initialLinks = await deriveLinksFromBookmarks(bookmarks)
|
||||||
const initialMap = new Map(initialLinks.map(item => [item.id, item]))
|
const initialMap = new Map(initialLinks.map(item => [item.id, item]))
|
||||||
setLinksMap(initialMap)
|
setLinksMap(initialMap)
|
||||||
setLinks(initialLinks)
|
setLinks(initialLinks)
|
||||||
@@ -334,7 +336,7 @@ const Me: React.FC<MeProps> = ({
|
|||||||
case 'writings':
|
case 'writings':
|
||||||
loadWritingsTab()
|
loadWritingsTab()
|
||||||
break
|
break
|
||||||
case 'reading-list':
|
case 'bookmarks':
|
||||||
loadReadingListTab()
|
loadReadingListTab()
|
||||||
break
|
break
|
||||||
case 'reads':
|
case 'reads':
|
||||||
@@ -393,8 +395,7 @@ const Me: React.FC<MeProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getReadItemUrl = (item: ReadItem) => {
|
const getReadItemUrl = (item: ReadItem) => {
|
||||||
if (item.type === 'article') {
|
if (item.type === 'article' && item.id.startsWith('naddr1')) {
|
||||||
// ID is already in naddr format
|
|
||||||
return `/a/${item.id}`
|
return `/a/${item.id}`
|
||||||
} else if (item.url) {
|
} else if (item.url) {
|
||||||
return `/r/${encodeURIComponent(item.url)}`
|
return `/r/${encodeURIComponent(item.url)}`
|
||||||
@@ -418,7 +419,7 @@ const Me: React.FC<MeProps> = ({
|
|||||||
const mockEvent = {
|
const mockEvent = {
|
||||||
id: item.id,
|
id: item.id,
|
||||||
pubkey: item.author || '',
|
pubkey: item.author || '',
|
||||||
created_at: item.readingTimestamp || Math.floor(Date.now() / 1000),
|
created_at: item.readingTimestamp || 0,
|
||||||
kind: 1,
|
kind: 1,
|
||||||
tags: [] as string[][],
|
tags: [] as string[][],
|
||||||
content: item.title || item.url || 'Untitled',
|
content: item.title || item.url || 'Untitled',
|
||||||
@@ -437,19 +438,16 @@ const Me: React.FC<MeProps> = ({
|
|||||||
|
|
||||||
const handleSelectUrl = (url: string, bookmark?: { id: string; kind: number; tags: string[][]; pubkey: string }) => {
|
const handleSelectUrl = (url: string, bookmark?: { id: string; kind: number; tags: string[][]; pubkey: string }) => {
|
||||||
if (bookmark && bookmark.kind === 30023) {
|
if (bookmark && bookmark.kind === 30023) {
|
||||||
// For kind:30023 articles, navigate to the article route
|
|
||||||
const dTag = bookmark.tags.find(t => t[0] === 'd')?.[1] || ''
|
const dTag = bookmark.tags.find(t => t[0] === 'd')?.[1] || ''
|
||||||
if (dTag && bookmark.pubkey) {
|
if (dTag && bookmark.pubkey) {
|
||||||
const pointer = {
|
const naddr = nip19.naddrEncode({
|
||||||
identifier: dTag,
|
|
||||||
kind: 30023,
|
kind: 30023,
|
||||||
pubkey: bookmark.pubkey,
|
pubkey: bookmark.pubkey,
|
||||||
}
|
identifier: dTag
|
||||||
const naddr = nip19.naddrEncode(pointer)
|
})
|
||||||
navigate(`/a/${naddr}`)
|
navigate(`/a/${naddr}`)
|
||||||
}
|
}
|
||||||
} else if (url) {
|
} else if (url) {
|
||||||
// For regular URLs, navigate to the reader route
|
|
||||||
navigate(`/r/${encodeURIComponent(url)}`)
|
navigate(`/r/${encodeURIComponent(url)}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -490,8 +488,10 @@ const Me: React.FC<MeProps> = ({
|
|||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge and flatten all individual bookmarks
|
// Merge and flatten all individual bookmarks with deduplication
|
||||||
const allIndividualBookmarks = bookmarks.flatMap(b => b.individualBookmarks || [])
|
const allIndividualBookmarks = dedupeBookmarksById(
|
||||||
|
bookmarks.flatMap(b => b.individualBookmarks || [])
|
||||||
|
)
|
||||||
.filter(hasContent)
|
.filter(hasContent)
|
||||||
.filter(b => !settings?.hideBookmarksWithoutCreationDate || hasCreationDate(b))
|
.filter(b => !settings?.hideBookmarksWithoutCreationDate || hasCreationDate(b))
|
||||||
|
|
||||||
@@ -565,9 +565,21 @@ const Me: React.FC<MeProps> = ({
|
|||||||
? buildArchiveOnly(linksWithProgress, { kind: 'external' })
|
? buildArchiveOnly(linksWithProgress, { kind: 'external' })
|
||||||
: []
|
: []
|
||||||
|
|
||||||
|
const getFilterTitle = (filter: BookmarkFilterType): string => {
|
||||||
|
const titles: Record<BookmarkFilterType, string> = {
|
||||||
|
'all': 'All Bookmarks',
|
||||||
|
'article': 'Bookmarked Reads',
|
||||||
|
'external': 'Bookmarked Links',
|
||||||
|
'video': 'Bookmarked Videos',
|
||||||
|
'note': 'Bookmarked Notes',
|
||||||
|
'web': 'Web Bookmarks'
|
||||||
|
}
|
||||||
|
return titles[filter]
|
||||||
|
}
|
||||||
|
|
||||||
const sections: Array<{ key: string; title: string; items: IndividualBookmark[] }> =
|
const sections: Array<{ key: string; title: string; items: IndividualBookmark[] }> =
|
||||||
groupingMode === 'flat'
|
groupingMode === 'flat'
|
||||||
? [{ key: 'all', title: `All Bookmarks (${filteredBookmarks.length})`, items: filteredBookmarks }]
|
? [{ key: 'all', title: getFilterTitle(bookmarkFilter), items: sortIndividualBookmarks(filteredBookmarks) }]
|
||||||
: [
|
: [
|
||||||
{ key: 'nip51-private', title: 'Private Bookmarks', items: groups.nip51Private },
|
{ key: 'nip51-private', title: 'Private Bookmarks', items: groups.nip51Private },
|
||||||
{ key: 'nip51-public', title: 'My Bookmarks', items: groups.nip51Public },
|
{ key: 'nip51-public', title: 'My Bookmarks', items: groups.nip51Public },
|
||||||
@@ -609,7 +621,7 @@ const Me: React.FC<MeProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
||||||
case 'reading-list':
|
case 'bookmarks':
|
||||||
if (showSkeletons) {
|
if (showSkeletons) {
|
||||||
return (
|
return (
|
||||||
<div className="bookmarks-list">
|
<div className="bookmarks-list">
|
||||||
@@ -655,21 +667,26 @@ const Me: React.FC<MeProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)))}
|
)))}
|
||||||
<div className="view-mode-controls" style={{
|
<div className="view-mode-controls">
|
||||||
display: 'flex',
|
<div className="view-mode-left">
|
||||||
justifyContent: 'center',
|
<IconButton
|
||||||
gap: '0.5rem',
|
icon={faHeart}
|
||||||
padding: '1rem',
|
onClick={() => navigate('/support')}
|
||||||
marginTop: '1rem',
|
title="Support Boris"
|
||||||
borderTop: '1px solid var(--border-color)'
|
ariaLabel="Support"
|
||||||
}}>
|
variant="ghost"
|
||||||
<IconButton
|
style={{ color: 'rgb(251 146 60)' }}
|
||||||
icon={groupingMode === 'grouped' ? faLayerGroup : faBars}
|
/>
|
||||||
onClick={toggleGroupingMode}
|
<IconButton
|
||||||
title={groupingMode === 'grouped' ? 'Show flat chronological list' : 'Show grouped by source'}
|
icon={groupingMode === 'grouped' ? faLayerGroup : faClock}
|
||||||
ariaLabel={groupingMode === 'grouped' ? 'Switch to flat view' : 'Switch to grouped view'}
|
onClick={toggleGroupingMode}
|
||||||
variant="ghost"
|
title={groupingMode === 'grouped' ? 'Show flat chronological list' : 'Show grouped by source'}
|
||||||
/>
|
ariaLabel={groupingMode === 'grouped' ? 'Switch to flat view' : 'Switch to grouped view'}
|
||||||
|
variant="ghost"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="view-mode-right">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
@@ -854,15 +871,15 @@ const Me: React.FC<MeProps> = ({
|
|||||||
<button
|
<button
|
||||||
className={`me-tab ${activeTab === 'highlights' ? 'active' : ''}`}
|
className={`me-tab ${activeTab === 'highlights' ? 'active' : ''}`}
|
||||||
data-tab="highlights"
|
data-tab="highlights"
|
||||||
onClick={() => navigate('/me/highlights')}
|
onClick={() => navigate('/my/highlights')}
|
||||||
>
|
>
|
||||||
<FontAwesomeIcon icon={faHighlighter} />
|
<FontAwesomeIcon icon={faHighlighter} />
|
||||||
<span className="tab-label">Highlights</span>
|
<span className="tab-label">Highlights</span>
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className={`me-tab ${activeTab === 'reading-list' ? 'active' : ''}`}
|
className={`me-tab ${activeTab === 'bookmarks' ? 'active' : ''}`}
|
||||||
data-tab="reading-list"
|
data-tab="bookmarks"
|
||||||
onClick={() => navigate('/me/reading-list')}
|
onClick={() => navigate('/my/bookmarks')}
|
||||||
>
|
>
|
||||||
<FontAwesomeIcon icon={faBookmark} />
|
<FontAwesomeIcon icon={faBookmark} />
|
||||||
<span className="tab-label">Bookmarks</span>
|
<span className="tab-label">Bookmarks</span>
|
||||||
@@ -870,7 +887,7 @@ const Me: React.FC<MeProps> = ({
|
|||||||
<button
|
<button
|
||||||
className={`me-tab ${activeTab === 'reads' ? 'active' : ''}`}
|
className={`me-tab ${activeTab === 'reads' ? 'active' : ''}`}
|
||||||
data-tab="reads"
|
data-tab="reads"
|
||||||
onClick={() => navigate('/me/reads')}
|
onClick={() => navigate('/my/reads')}
|
||||||
>
|
>
|
||||||
<FontAwesomeIcon icon={faBooks} />
|
<FontAwesomeIcon icon={faBooks} />
|
||||||
<span className="tab-label">Reads</span>
|
<span className="tab-label">Reads</span>
|
||||||
@@ -878,7 +895,7 @@ const Me: React.FC<MeProps> = ({
|
|||||||
<button
|
<button
|
||||||
className={`me-tab ${activeTab === 'links' ? 'active' : ''}`}
|
className={`me-tab ${activeTab === 'links' ? 'active' : ''}`}
|
||||||
data-tab="links"
|
data-tab="links"
|
||||||
onClick={() => navigate('/me/links')}
|
onClick={() => navigate('/my/links')}
|
||||||
>
|
>
|
||||||
<FontAwesomeIcon icon={faLink} />
|
<FontAwesomeIcon icon={faLink} />
|
||||||
<span className="tab-label">Links</span>
|
<span className="tab-label">Links</span>
|
||||||
@@ -886,7 +903,7 @@ const Me: React.FC<MeProps> = ({
|
|||||||
<button
|
<button
|
||||||
className={`me-tab ${activeTab === 'writings' ? 'active' : ''}`}
|
className={`me-tab ${activeTab === 'writings' ? 'active' : ''}`}
|
||||||
data-tab="writings"
|
data-tab="writings"
|
||||||
onClick={() => navigate('/me/writings')}
|
onClick={() => navigate('/my/writings')}
|
||||||
>
|
>
|
||||||
<FontAwesomeIcon icon={faPenToSquare} />
|
<FontAwesomeIcon icon={faPenToSquare} />
|
||||||
<span className="tab-label">Writings</span>
|
<span className="tab-label">Writings</span>
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
import React from 'react'
|
import React, { useMemo } from 'react'
|
||||||
import { nip19 } from 'nostr-tools'
|
import { nip19 } from 'nostr-tools'
|
||||||
import { useEventModel } from 'applesauce-react/hooks'
|
import { useEventModel } from 'applesauce-react/hooks'
|
||||||
import { Models } from 'applesauce-core'
|
import { Hooks } from 'applesauce-react'
|
||||||
|
import { Models, Helpers } from 'applesauce-core'
|
||||||
|
import { getProfileDisplayName } from '../utils/nostrUriResolver'
|
||||||
|
import { isProfileInCacheOrStore } from '../utils/profileLoadingUtils'
|
||||||
|
|
||||||
|
const { getPubkeyFromDecodeResult } = Helpers
|
||||||
|
|
||||||
interface NostrMentionLinkProps {
|
interface NostrMentionLinkProps {
|
||||||
nostrUri: string
|
nostrUri: string
|
||||||
@@ -20,25 +25,31 @@ const NostrMentionLink: React.FC<NostrMentionLinkProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
// Decode the nostr URI first
|
// Decode the nostr URI first
|
||||||
let decoded: ReturnType<typeof nip19.decode> | null = null
|
let decoded: ReturnType<typeof nip19.decode> | null = null
|
||||||
let pubkey: string | undefined
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const identifier = nostrUri.replace(/^nostr:/, '')
|
const identifier = nostrUri.replace(/^nostr:/, '')
|
||||||
decoded = nip19.decode(identifier)
|
decoded = nip19.decode(identifier)
|
||||||
|
|
||||||
// Extract pubkey for profile fetching (works for npub and nprofile)
|
|
||||||
if (decoded.type === 'npub') {
|
|
||||||
pubkey = decoded.data
|
|
||||||
} else if (decoded.type === 'nprofile') {
|
|
||||||
pubkey = decoded.data.pubkey
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Decoding failed, will fallback to shortened identifier
|
// Decoding failed, will fallback to shortened identifier
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Extract pubkey for profile fetching using applesauce helper (works for npub and nprofile)
|
||||||
|
const pubkey = decoded ? getPubkeyFromDecodeResult(decoded) : undefined
|
||||||
|
|
||||||
|
const eventStore = Hooks.useEventStore()
|
||||||
// Fetch profile at top level (Rules of Hooks)
|
// Fetch profile at top level (Rules of Hooks)
|
||||||
const profile = useEventModel(Models.ProfileModel, pubkey ? [pubkey] : null)
|
const profile = useEventModel(Models.ProfileModel, pubkey ? [pubkey] : null)
|
||||||
|
|
||||||
|
// Check if profile is in cache or eventStore for loading detection
|
||||||
|
const isInCacheOrStore = useMemo(() => {
|
||||||
|
if (!pubkey) return false
|
||||||
|
return isProfileInCacheOrStore(pubkey, eventStore)
|
||||||
|
}, [pubkey, eventStore])
|
||||||
|
|
||||||
|
// Show loading if profile doesn't exist and not in cache/store (for npub/nprofile)
|
||||||
|
// pubkey will be undefined for non-profile types, so no need for explicit type check
|
||||||
|
const isLoading = !profile && pubkey && !isInCacheOrStore
|
||||||
|
|
||||||
// If decoding failed, show shortened identifier
|
// If decoding failed, show shortened identifier
|
||||||
if (!decoded) {
|
if (!decoded) {
|
||||||
const identifier = nostrUri.replace(/^nostr:/, '')
|
const identifier = nostrUri.replace(/^nostr:/, '')
|
||||||
@@ -49,37 +60,30 @@ const NostrMentionLink: React.FC<NostrMentionLinkProps> = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper function to render profile links (used for both npub and nprofile)
|
||||||
|
const renderProfileLink = (pubkey: string) => {
|
||||||
|
const npub = nip19.npubEncode(pubkey)
|
||||||
|
const displayName = getProfileDisplayName(profile, pubkey)
|
||||||
|
const linkClassName = isLoading ? `${className} profile-loading` : className
|
||||||
|
|
||||||
|
return (
|
||||||
|
<a
|
||||||
|
href={`/p/${npub}`}
|
||||||
|
className={linkClassName}
|
||||||
|
onClick={onClick}
|
||||||
|
>
|
||||||
|
@{displayName}
|
||||||
|
</a>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// Render based on decoded type
|
// Render based on decoded type
|
||||||
|
// If we have a pubkey (from npub/nprofile), render profile link directly
|
||||||
|
if (pubkey) {
|
||||||
|
return renderProfileLink(pubkey)
|
||||||
|
}
|
||||||
|
|
||||||
switch (decoded.type) {
|
switch (decoded.type) {
|
||||||
case 'npub': {
|
|
||||||
const pk = decoded.data
|
|
||||||
const displayName = profile?.name || profile?.display_name || profile?.nip05 || `${pk.slice(0, 8)}...`
|
|
||||||
|
|
||||||
return (
|
|
||||||
<a
|
|
||||||
href={`/p/${nip19.npubEncode(pk)}`}
|
|
||||||
className={className}
|
|
||||||
onClick={onClick}
|
|
||||||
>
|
|
||||||
@{displayName}
|
|
||||||
</a>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
case 'nprofile': {
|
|
||||||
const { pubkey: pk } = decoded.data
|
|
||||||
const displayName = profile?.name || profile?.display_name || profile?.nip05 || `${pk.slice(0, 8)}...`
|
|
||||||
const npub = nip19.npubEncode(pk)
|
|
||||||
|
|
||||||
return (
|
|
||||||
<a
|
|
||||||
href={`/p/${npub}`}
|
|
||||||
className={className}
|
|
||||||
onClick={onClick}
|
|
||||||
>
|
|
||||||
@{displayName}
|
|
||||||
</a>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
case 'naddr': {
|
case 'naddr': {
|
||||||
const { kind, pubkey: pk, identifier: addrIdentifier } = decoded.data
|
const { kind, pubkey: pk, identifier: addrIdentifier } = decoded.data
|
||||||
// Check if it's a blog post (kind:30023)
|
// Check if it's a blog post (kind:30023)
|
||||||
|
|||||||
@@ -6,10 +6,8 @@ import { RelayPool } from 'applesauce-relay'
|
|||||||
import { nip19 } from 'nostr-tools'
|
import { nip19 } from 'nostr-tools'
|
||||||
import { useNavigate } from 'react-router-dom'
|
import { useNavigate } from 'react-router-dom'
|
||||||
import { HighlightItem } from './HighlightItem'
|
import { HighlightItem } from './HighlightItem'
|
||||||
import { BlogPostPreview, fetchBlogPostsFromAuthors } from '../services/exploreService'
|
import { BlogPostPreview } from '../services/exploreService'
|
||||||
import { fetchHighlights } from '../services/highlightService'
|
|
||||||
import { KINDS } from '../config/kinds'
|
import { KINDS } from '../config/kinds'
|
||||||
import { getActiveRelayUrls } from '../services/relayManager'
|
|
||||||
import AuthorCard from './AuthorCard'
|
import AuthorCard from './AuthorCard'
|
||||||
import BlogPostCard from './BlogPostCard'
|
import BlogPostCard from './BlogPostCard'
|
||||||
import { BlogPostSkeleton, HighlightSkeleton } from './Skeletons'
|
import { BlogPostSkeleton, HighlightSkeleton } from './Skeletons'
|
||||||
@@ -20,6 +18,8 @@ import { usePullToRefresh } from 'use-pull-to-refresh'
|
|||||||
import RefreshIndicator from './RefreshIndicator'
|
import RefreshIndicator from './RefreshIndicator'
|
||||||
import { Hooks } from 'applesauce-react'
|
import { Hooks } from 'applesauce-react'
|
||||||
import { readingProgressController } from '../services/readingProgressController'
|
import { readingProgressController } from '../services/readingProgressController'
|
||||||
|
import { writingsController } from '../services/writingsController'
|
||||||
|
import { highlightsController } from '../services/highlightsController'
|
||||||
|
|
||||||
interface ProfileProps {
|
interface ProfileProps {
|
||||||
relayPool: RelayPool
|
relayPool: RelayPool
|
||||||
@@ -103,17 +103,16 @@ const Profile: React.FC<ProfileProps> = ({
|
|||||||
})
|
})
|
||||||
}, [activeAccount?.pubkey, relayPool, eventStore, refreshTrigger])
|
}, [activeAccount?.pubkey, relayPool, eventStore, refreshTrigger])
|
||||||
|
|
||||||
// Background fetch to populate event store (non-blocking)
|
// Background fetch via controllers to populate event store
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!pubkey || !relayPool || !eventStore) return
|
if (!pubkey || !relayPool || !eventStore) return
|
||||||
|
|
||||||
// Fetch all highlights and writings in background (no limits)
|
// Start controllers to fetch and populate event store
|
||||||
const relayUrls = getActiveRelayUrls(relayPool)
|
// Controllers handle streaming, deduplication, and storage
|
||||||
|
highlightsController.start({ relayPool, eventStore, pubkey })
|
||||||
fetchHighlights(relayPool, pubkey, undefined, undefined, false, eventStore)
|
|
||||||
.catch(err => console.warn('⚠️ [Profile] Failed to fetch highlights:', err))
|
.catch(err => console.warn('⚠️ [Profile] Failed to fetch highlights:', err))
|
||||||
|
|
||||||
fetchBlogPostsFromAuthors(relayPool, [pubkey], relayUrls, undefined, null, eventStore)
|
writingsController.start({ relayPool, eventStore, pubkey, force: refreshTrigger > 0 })
|
||||||
.catch(err => console.warn('⚠️ [Profile] Failed to fetch writings:', err))
|
.catch(err => console.warn('⚠️ [Profile] Failed to fetch writings:', err))
|
||||||
}, [pubkey, relayPool, eventStore, refreshTrigger])
|
}, [pubkey, relayPool, eventStore, refreshTrigger])
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ interface ReaderHeaderProps {
|
|||||||
settings?: UserSettings
|
settings?: UserSettings
|
||||||
highlights?: Highlight[]
|
highlights?: Highlight[]
|
||||||
highlightVisibility?: HighlightVisibility
|
highlightVisibility?: HighlightVisibility
|
||||||
|
onHighlightCountClick?: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const ReaderHeader: React.FC<ReaderHeaderProps> = ({
|
const ReaderHeader: React.FC<ReaderHeaderProps> = ({
|
||||||
@@ -32,7 +33,8 @@ const ReaderHeader: React.FC<ReaderHeaderProps> = ({
|
|||||||
highlightCount,
|
highlightCount,
|
||||||
settings,
|
settings,
|
||||||
highlights = [],
|
highlights = [],
|
||||||
highlightVisibility = { nostrverse: true, friends: true, mine: true }
|
highlightVisibility = { nostrverse: true, friends: true, mine: true },
|
||||||
|
onHighlightCountClick
|
||||||
}) => {
|
}) => {
|
||||||
const cachedImage = useImageCache(image)
|
const cachedImage = useImageCache(image)
|
||||||
const { textColor } = useAdaptiveTextColor(cachedImage)
|
const { textColor } = useAdaptiveTextColor(cachedImage)
|
||||||
@@ -78,7 +80,13 @@ const ReaderHeader: React.FC<ReaderHeaderProps> = ({
|
|||||||
<>
|
<>
|
||||||
<div className="reader-hero-image">
|
<div className="reader-hero-image">
|
||||||
{cachedImage ? (
|
{cachedImage ? (
|
||||||
<img src={cachedImage} alt={title || 'Article image'} />
|
<img
|
||||||
|
src={cachedImage}
|
||||||
|
alt={title || 'Article image'}
|
||||||
|
onError={(e) => {
|
||||||
|
console.error('[reader-header] Image failed to load:', cachedImage, e)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className="reader-hero-placeholder">
|
<div className="reader-hero-placeholder">
|
||||||
<FontAwesomeIcon icon={faNewspaper} />
|
<FontAwesomeIcon icon={faNewspaper} />
|
||||||
@@ -107,8 +115,10 @@ const ReaderHeader: React.FC<ReaderHeaderProps> = ({
|
|||||||
)}
|
)}
|
||||||
{hasHighlights && (
|
{hasHighlights && (
|
||||||
<div
|
<div
|
||||||
className="highlight-indicator"
|
className="highlight-indicator clickable"
|
||||||
style={getHighlightIndicatorStyles(true)}
|
style={getHighlightIndicatorStyles(true)}
|
||||||
|
onClick={onHighlightCountClick}
|
||||||
|
title="Open highlights sidebar"
|
||||||
>
|
>
|
||||||
<FontAwesomeIcon icon={faHighlighter} />
|
<FontAwesomeIcon icon={faHighlighter} />
|
||||||
<span>{highlightCount} highlight{highlightCount !== 1 ? 's' : ''}</span>
|
<span>{highlightCount} highlight{highlightCount !== 1 ? 's' : ''}</span>
|
||||||
@@ -152,8 +162,10 @@ const ReaderHeader: React.FC<ReaderHeaderProps> = ({
|
|||||||
)}
|
)}
|
||||||
{hasHighlights && (
|
{hasHighlights && (
|
||||||
<div
|
<div
|
||||||
className="highlight-indicator"
|
className="highlight-indicator clickable"
|
||||||
style={getHighlightIndicatorStyles(false)}
|
style={getHighlightIndicatorStyles(false)}
|
||||||
|
onClick={onHighlightCountClick}
|
||||||
|
title="Open highlights sidebar"
|
||||||
>
|
>
|
||||||
<FontAwesomeIcon icon={faHighlighter} />
|
<FontAwesomeIcon icon={faHighlighter} />
|
||||||
<span>{highlightCount} highlight{highlightCount !== 1 ? 's' : ''}</span>
|
<span>{highlightCount} highlight{highlightCount !== 1 ? 's' : ''}</span>
|
||||||
|
|||||||
58
src/components/ReadingProgressBar.tsx
Normal file
58
src/components/ReadingProgressBar.tsx
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
interface ReadingProgressBarProps {
|
||||||
|
readingProgress?: number
|
||||||
|
height?: number
|
||||||
|
marginTop?: string
|
||||||
|
marginBottom?: string
|
||||||
|
marginLeft?: string
|
||||||
|
className?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ReadingProgressBar: React.FC<ReadingProgressBarProps> = ({
|
||||||
|
readingProgress,
|
||||||
|
height = 1,
|
||||||
|
marginTop,
|
||||||
|
marginBottom,
|
||||||
|
marginLeft,
|
||||||
|
className
|
||||||
|
}) => {
|
||||||
|
// Calculate progress color
|
||||||
|
let progressColor = '#6366f1' // Default blue (reading)
|
||||||
|
if (readingProgress && readingProgress >= 0.95) {
|
||||||
|
progressColor = '#10b981' // Green (completed)
|
||||||
|
} else if (readingProgress && readingProgress > 0 && readingProgress <= 0.10) {
|
||||||
|
progressColor = 'var(--color-text)' // Neutral text color (started)
|
||||||
|
}
|
||||||
|
|
||||||
|
const progressWidth = readingProgress ? `${Math.round(readingProgress * 100)}%` : '0%'
|
||||||
|
const progressBackground = readingProgress ? progressColor : 'var(--color-border)'
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={className}
|
||||||
|
style={{
|
||||||
|
height: `${height}px`,
|
||||||
|
width: '100%',
|
||||||
|
background: 'var(--color-border)',
|
||||||
|
borderRadius: '0.5px',
|
||||||
|
overflow: 'hidden',
|
||||||
|
marginTop,
|
||||||
|
marginBottom,
|
||||||
|
marginLeft,
|
||||||
|
position: 'relative',
|
||||||
|
minHeight: `${height}px`
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
height: '100%',
|
||||||
|
width: progressWidth,
|
||||||
|
background: progressBackground,
|
||||||
|
transition: 'width 0.3s ease, background 0.3s ease',
|
||||||
|
minHeight: `${height}px`
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
import React from 'react'
|
import React, { useMemo } from 'react'
|
||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
import { useEventModel } from 'applesauce-react/hooks'
|
import { useEventModel } from 'applesauce-react/hooks'
|
||||||
|
import { Hooks } from 'applesauce-react'
|
||||||
import { Models, Helpers } from 'applesauce-core'
|
import { Models, Helpers } from 'applesauce-core'
|
||||||
import { decode, npubEncode } from 'nostr-tools/nip19'
|
import { decode, npubEncode } from 'nostr-tools/nip19'
|
||||||
|
import { getProfileDisplayName } from '../utils/nostrUriResolver'
|
||||||
|
import { isProfileInCacheOrStore } from '../utils/profileLoadingUtils'
|
||||||
|
|
||||||
const { getPubkeyFromDecodeResult } = Helpers
|
const { getPubkeyFromDecodeResult } = Helpers
|
||||||
|
|
||||||
@@ -19,15 +22,27 @@ const ResolvedMention: React.FC<ResolvedMentionProps> = ({ encoded }) => {
|
|||||||
// ignore; will fallback to showing the encoded value
|
// ignore; will fallback to showing the encoded value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const eventStore = Hooks.useEventStore()
|
||||||
const profile = pubkey ? useEventModel(Models.ProfileModel, [pubkey]) : undefined
|
const profile = pubkey ? useEventModel(Models.ProfileModel, [pubkey]) : undefined
|
||||||
const display = profile?.name || profile?.display_name || profile?.nip05 || (pubkey ? `${pubkey.slice(0, 8)}...` : encoded)
|
|
||||||
|
// Check if profile is in cache or eventStore
|
||||||
|
const isInCacheOrStore = useMemo(() => {
|
||||||
|
if (!pubkey) return false
|
||||||
|
return isProfileInCacheOrStore(pubkey, eventStore)
|
||||||
|
}, [pubkey, eventStore])
|
||||||
|
|
||||||
|
// Show loading if profile doesn't exist and not in cache/store
|
||||||
|
const isLoading = !profile && pubkey && !isInCacheOrStore
|
||||||
|
|
||||||
|
const display = pubkey ? getProfileDisplayName(profile, pubkey) : encoded
|
||||||
const npub = pubkey ? npubEncode(pubkey) : undefined
|
const npub = pubkey ? npubEncode(pubkey) : undefined
|
||||||
|
|
||||||
if (npub) {
|
if (npub) {
|
||||||
|
const className = isLoading ? 'nostr-mention profile-loading' : 'nostr-mention'
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
to={`/p/${npub}`}
|
to={`/p/${npub}`}
|
||||||
className="nostr-mention"
|
className={className}
|
||||||
>
|
>
|
||||||
@{display}
|
@{display}
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import NostrMentionLink from './NostrMentionLink'
|
import NostrMentionLink from './NostrMentionLink'
|
||||||
|
import { Tokens } from 'applesauce-content/helpers'
|
||||||
|
|
||||||
|
// Helper to add timestamps to error logs
|
||||||
|
const ts = () => {
|
||||||
|
const now = new Date()
|
||||||
|
const ms = now.getMilliseconds().toString().padStart(3, '0')
|
||||||
|
return `${now.toLocaleTimeString('en-US', { hour12: false })}.${ms}`
|
||||||
|
}
|
||||||
|
|
||||||
interface RichContentProps {
|
interface RichContentProps {
|
||||||
content: string
|
content: string
|
||||||
@@ -18,18 +26,31 @@ const RichContent: React.FC<RichContentProps> = ({
|
|||||||
content,
|
content,
|
||||||
className = 'bookmark-content'
|
className = 'bookmark-content'
|
||||||
}) => {
|
}) => {
|
||||||
// Pattern to match:
|
try {
|
||||||
// 1. nostr: URIs (nostr:npub1..., nostr:note1..., etc.)
|
// Pattern to match:
|
||||||
// 2. Plain nostr identifiers (npub1..., nprofile1..., note1..., etc.)
|
// 1. nostr: URIs (nostr:npub1..., nostr:note1..., etc.) using applesauce Tokens.nostrLink
|
||||||
// 3. http(s) URLs
|
// 2. http(s) URLs
|
||||||
const pattern = /(nostr:[a-z0-9]+|npub1[a-z0-9]+|nprofile1[a-z0-9]+|note1[a-z0-9]+|nevent1[a-z0-9]+|naddr1[a-z0-9]+|https?:\/\/[^\s]+)/gi
|
const nostrPattern = Tokens.nostrLink
|
||||||
|
const urlPattern = /https?:\/\/[^\s]+/gi
|
||||||
|
const combinedPattern = new RegExp(`(${nostrPattern.source}|${urlPattern.source})`, 'gi')
|
||||||
|
|
||||||
|
const parts = content.split(combinedPattern)
|
||||||
|
|
||||||
const parts = content.split(pattern)
|
// Helper to check if a string is a nostr identifier (without mutating regex state)
|
||||||
|
const isNostrIdentifier = (str: string): boolean => {
|
||||||
return (
|
const testPattern = new RegExp(nostrPattern.source, nostrPattern.flags)
|
||||||
|
return testPattern.test(str)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
<div className={className}>
|
<div className={className}>
|
||||||
{parts.map((part, index) => {
|
{parts.map((part, index) => {
|
||||||
// Handle nostr: URIs
|
// Skip empty or undefined parts
|
||||||
|
if (!part) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle nostr: URIs - Tokens.nostrLink matches both formats
|
||||||
if (part.startsWith('nostr:')) {
|
if (part.startsWith('nostr:')) {
|
||||||
return (
|
return (
|
||||||
<NostrMentionLink
|
<NostrMentionLink
|
||||||
@@ -39,10 +60,8 @@ const RichContent: React.FC<RichContentProps> = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle plain nostr identifiers (add nostr: prefix)
|
// Handle plain nostr identifiers (Tokens.nostrLink matches these too)
|
||||||
if (
|
if (isNostrIdentifier(part)) {
|
||||||
part.match(/^(npub1|nprofile1|note1|nevent1|naddr1)[a-z0-9]+$/i)
|
|
||||||
) {
|
|
||||||
return (
|
return (
|
||||||
<NostrMentionLink
|
<NostrMentionLink
|
||||||
key={index}
|
key={index}
|
||||||
@@ -70,7 +89,11 @@ const RichContent: React.FC<RichContentProps> = ({
|
|||||||
return <React.Fragment key={index}>{part}</React.Fragment>
|
return <React.Fragment key={index}>{part}</React.Fragment>
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`[${ts()}] [npub-resolve] RichContent: Error rendering:`, err)
|
||||||
|
return <div className={className}>Error rendering content</div>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default RichContent
|
export default RichContent
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export default function RouteDebug() {
|
|||||||
// Unexpected during deep-link refresh tests
|
// Unexpected during deep-link refresh tests
|
||||||
console.warn('[RouteDebug] unexpected root redirect', info)
|
console.warn('[RouteDebug] unexpected root redirect', info)
|
||||||
} else {
|
} else {
|
||||||
console.debug('[RouteDebug]', info)
|
// silent
|
||||||
}
|
}
|
||||||
}, [location, matchArticle])
|
}, [location, matchArticle])
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ const DEFAULT_SETTINGS: UserSettings = {
|
|||||||
fullWidthImages: true,
|
fullWidthImages: true,
|
||||||
renderVideoLinksAsEmbeds: true,
|
renderVideoLinksAsEmbeds: true,
|
||||||
syncReadingPosition: true,
|
syncReadingPosition: true,
|
||||||
|
autoScrollToReadingPosition: true,
|
||||||
autoMarkAsReadOnCompletion: false,
|
autoMarkAsReadOnCompletion: false,
|
||||||
hideBookmarksWithoutCreationDate: true,
|
hideBookmarksWithoutCreationDate: true,
|
||||||
ttsUseSystemLanguage: false,
|
ttsUseSystemLanguage: false,
|
||||||
|
|||||||
@@ -118,6 +118,19 @@ const LayoutBehaviorSettings: React.FC<LayoutBehaviorSettingsProps> = ({ setting
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="setting-group">
|
||||||
|
<label htmlFor="autoScrollToReadingPosition" className="checkbox-label">
|
||||||
|
<input
|
||||||
|
id="autoScrollToReadingPosition"
|
||||||
|
type="checkbox"
|
||||||
|
checked={settings.autoScrollToReadingPosition !== false}
|
||||||
|
onChange={(e) => onUpdate({ autoScrollToReadingPosition: e.target.checked })}
|
||||||
|
className="setting-checkbox"
|
||||||
|
/>
|
||||||
|
<span>Auto-scroll to saved reading position</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="setting-group">
|
<div className="setting-group">
|
||||||
<label htmlFor="autoMarkAsReadOnCompletion" className="checkbox-label">
|
<label htmlFor="autoMarkAsReadOnCompletion" className="checkbox-label">
|
||||||
<input
|
<input
|
||||||
|
|||||||
@@ -33,7 +33,13 @@ const PWASettings: React.FC<PWASettingsProps> = ({ settings, onUpdate, onClose }
|
|||||||
|
|
||||||
const handleLinkClick = (url: string) => {
|
const handleLinkClick = (url: string) => {
|
||||||
if (onClose) onClose()
|
if (onClose) onClose()
|
||||||
navigate(`/r/${encodeURIComponent(url)}`)
|
// If it's an internal route (starts with /), navigate directly
|
||||||
|
if (url.startsWith('/')) {
|
||||||
|
navigate(url)
|
||||||
|
} else {
|
||||||
|
// External URL: wrap with /r/ path
|
||||||
|
navigate(`/r/${encodeURIComponent(url)}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleClearCache = async () => {
|
const handleClearCache = async () => {
|
||||||
@@ -151,7 +157,7 @@ const PWASettings: React.FC<PWASettingsProps> = ({ settings, onUpdate, onClose }
|
|||||||
>
|
>
|
||||||
here
|
here
|
||||||
</a>
|
</a>
|
||||||
{' and '}
|
{', '}
|
||||||
<a
|
<a
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@@ -161,6 +167,16 @@ const PWASettings: React.FC<PWASettingsProps> = ({ settings, onUpdate, onClose }
|
|||||||
>
|
>
|
||||||
here
|
here
|
||||||
</a>
|
</a>
|
||||||
|
{', and '}
|
||||||
|
<a
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
handleLinkClick('/a/naddr1qvzqqqr4gupzq3svyhng9ld8sv44950j957j9vchdktj7cxumsep9mvvjthc2pjuqq9hyetvv9uj6um9w36hq9mgjg8')
|
||||||
|
}}
|
||||||
|
style={{ color: 'var(--accent, #8b5cf6)', cursor: 'pointer' }}
|
||||||
|
>
|
||||||
|
here
|
||||||
|
</a>
|
||||||
.
|
.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ export default function ShareTargetHandler({ relayPool }: ShareTargetHandlerProp
|
|||||||
getActiveRelayUrls(relayPool)
|
getActiveRelayUrls(relayPool)
|
||||||
)
|
)
|
||||||
showToast('Bookmark saved!')
|
showToast('Bookmark saved!')
|
||||||
navigate('/me/links')
|
navigate('/my/links')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to save shared bookmark:', err)
|
console.error('Failed to save shared bookmark:', err)
|
||||||
showToast('Failed to save bookmark')
|
showToast('Failed to save bookmark')
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
import React from 'react'
|
import React, { useState, useRef, useEffect } from 'react'
|
||||||
import { useNavigate } from 'react-router-dom'
|
import { useNavigate } from 'react-router-dom'
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||||
import { faChevronRight, faRightFromBracket, faUserCircle, faGear, faHome, faNewspaper, faTimes } from '@fortawesome/free-solid-svg-icons'
|
import { faChevronRight, faRightFromBracket, faUserCircle, faGear, faHome, faPersonHiking, faHighlighter, faBookmark, faPenToSquare, faLink } from '@fortawesome/free-solid-svg-icons'
|
||||||
import { Hooks } from 'applesauce-react'
|
import { Hooks } from 'applesauce-react'
|
||||||
import { useEventModel } from 'applesauce-react/hooks'
|
import { useEventModel } from 'applesauce-react/hooks'
|
||||||
import { Models } from 'applesauce-core'
|
import { Models } from 'applesauce-core'
|
||||||
import IconButton from './IconButton'
|
import IconButton from './IconButton'
|
||||||
|
import { faBooks } from '../icons/customIcons'
|
||||||
|
import { preloadImage } from '../hooks/useImageCache'
|
||||||
|
import { getProfileDisplayName } from '../utils/nostrUriResolver'
|
||||||
|
|
||||||
interface SidebarHeaderProps {
|
interface SidebarHeaderProps {
|
||||||
onToggleCollapse: () => void
|
onToggleCollapse: () => void
|
||||||
@@ -18,6 +21,8 @@ const SidebarHeader: React.FC<SidebarHeaderProps> = ({ onToggleCollapse, onLogou
|
|||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const activeAccount = Hooks.useActiveAccount()
|
const activeAccount = Hooks.useActiveAccount()
|
||||||
const profile = useEventModel(Models.ProfileModel, activeAccount ? [activeAccount.pubkey] : null)
|
const profile = useEventModel(Models.ProfileModel, activeAccount ? [activeAccount.pubkey] : null)
|
||||||
|
const [showProfileMenu, setShowProfileMenu] = useState(false)
|
||||||
|
const menuRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
const getProfileImage = () => {
|
const getProfileImage = () => {
|
||||||
return profile?.picture || null
|
return profile?.picture || null
|
||||||
@@ -25,81 +30,159 @@ const SidebarHeader: React.FC<SidebarHeaderProps> = ({ onToggleCollapse, onLogou
|
|||||||
|
|
||||||
const getUserDisplayName = () => {
|
const getUserDisplayName = () => {
|
||||||
if (!activeAccount) return 'Unknown User'
|
if (!activeAccount) return 'Unknown User'
|
||||||
if (profile?.name) return profile.name
|
return getProfileDisplayName(profile, activeAccount.pubkey)
|
||||||
if (profile?.display_name) return profile.display_name
|
|
||||||
if (profile?.nip05) return profile.nip05
|
|
||||||
return `${activeAccount.pubkey.slice(0, 8)}...${activeAccount.pubkey.slice(-8)}`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const profileImage = getProfileImage()
|
const profileImage = getProfileImage()
|
||||||
|
|
||||||
|
// Preload profile image for offline access
|
||||||
|
useEffect(() => {
|
||||||
|
if (profileImage) {
|
||||||
|
preloadImage(profileImage)
|
||||||
|
}
|
||||||
|
}, [profileImage])
|
||||||
|
|
||||||
|
// Close menu when clicking outside
|
||||||
|
useEffect(() => {
|
||||||
|
const handleClickOutside = (event: MouseEvent) => {
|
||||||
|
if (menuRef.current && !menuRef.current.contains(event.target as Node)) {
|
||||||
|
setShowProfileMenu(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showProfileMenu) {
|
||||||
|
document.addEventListener('mousedown', handleClickOutside)
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('mousedown', handleClickOutside)
|
||||||
|
}
|
||||||
|
}, [showProfileMenu])
|
||||||
|
|
||||||
|
const handleMenuItemClick = (action: () => void) => {
|
||||||
|
setShowProfileMenu(false)
|
||||||
|
// Close mobile sidebar when navigating on mobile
|
||||||
|
if (isMobile) {
|
||||||
|
onToggleCollapse()
|
||||||
|
}
|
||||||
|
action()
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="sidebar-header-bar">
|
<div className="sidebar-header-bar">
|
||||||
{isMobile ? (
|
<div className="sidebar-header-left">
|
||||||
|
{activeAccount && (
|
||||||
|
<div className="profile-menu-wrapper" ref={menuRef}>
|
||||||
|
<button
|
||||||
|
className="profile-avatar-button"
|
||||||
|
title={getUserDisplayName()}
|
||||||
|
onClick={() => setShowProfileMenu(!showProfileMenu)}
|
||||||
|
aria-label={`Profile: ${getUserDisplayName()}`}
|
||||||
|
>
|
||||||
|
{profileImage ? (
|
||||||
|
<img src={profileImage} alt={getUserDisplayName()} />
|
||||||
|
) : (
|
||||||
|
<FontAwesomeIcon icon={faUserCircle} />
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
{showProfileMenu && (
|
||||||
|
<div className="profile-dropdown-menu">
|
||||||
|
<button
|
||||||
|
className="profile-menu-item"
|
||||||
|
onClick={() => handleMenuItemClick(() => navigate('/my/highlights'))}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon={faHighlighter} />
|
||||||
|
<span>My Highlights</span>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="profile-menu-item"
|
||||||
|
onClick={() => handleMenuItemClick(() => navigate('/my/bookmarks'))}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon={faBookmark} />
|
||||||
|
<span>My Bookmarks</span>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="profile-menu-item"
|
||||||
|
onClick={() => handleMenuItemClick(() => navigate('/my/reads'))}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon={faBooks} />
|
||||||
|
<span>My Reads</span>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="profile-menu-item"
|
||||||
|
onClick={() => handleMenuItemClick(() => navigate('/my/links'))}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon={faLink} />
|
||||||
|
<span>My Links</span>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="profile-menu-item"
|
||||||
|
onClick={() => handleMenuItemClick(() => navigate('/my/writings'))}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon={faPenToSquare} />
|
||||||
|
<span>My Writings</span>
|
||||||
|
</button>
|
||||||
|
<div className="profile-menu-separator"></div>
|
||||||
|
<button
|
||||||
|
className="profile-menu-item"
|
||||||
|
onClick={() => handleMenuItemClick(onLogout)}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon={faRightFromBracket} />
|
||||||
|
<span>Logout</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<IconButton
|
<IconButton
|
||||||
icon={faTimes}
|
icon={faHome}
|
||||||
onClick={onToggleCollapse}
|
onClick={() => {
|
||||||
title="Close sidebar"
|
if (isMobile) {
|
||||||
ariaLabel="Close sidebar"
|
onToggleCollapse()
|
||||||
|
}
|
||||||
|
navigate('/')
|
||||||
|
}}
|
||||||
|
title="Home"
|
||||||
|
ariaLabel="Home"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
className="mobile-close-btn"
|
|
||||||
/>
|
/>
|
||||||
) : (
|
</div>
|
||||||
<button
|
|
||||||
onClick={onToggleCollapse}
|
|
||||||
className="toggle-sidebar-btn"
|
|
||||||
title="Collapse bookmarks sidebar"
|
|
||||||
aria-label="Collapse bookmarks sidebar"
|
|
||||||
>
|
|
||||||
<FontAwesomeIcon icon={faChevronRight} />
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
<div className="sidebar-header-right">
|
<div className="sidebar-header-right">
|
||||||
{activeAccount && (
|
|
||||||
<div
|
|
||||||
className="profile-avatar"
|
|
||||||
title={getUserDisplayName()}
|
|
||||||
onClick={() => navigate('/me')}
|
|
||||||
style={{ cursor: 'pointer' }}
|
|
||||||
>
|
|
||||||
{profileImage ? (
|
|
||||||
<img src={profileImage} alt={getUserDisplayName()} />
|
|
||||||
) : (
|
|
||||||
<FontAwesomeIcon icon={faUserCircle} />
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<IconButton
|
|
||||||
icon={faHome}
|
|
||||||
onClick={() => navigate('/')}
|
|
||||||
title="Home"
|
|
||||||
ariaLabel="Home"
|
|
||||||
variant="ghost"
|
|
||||||
/>
|
|
||||||
<IconButton
|
|
||||||
icon={faNewspaper}
|
|
||||||
onClick={() => navigate('/explore')}
|
|
||||||
title="Explore"
|
|
||||||
ariaLabel="Explore"
|
|
||||||
variant="ghost"
|
|
||||||
/>
|
|
||||||
<IconButton
|
|
||||||
icon={faGear}
|
|
||||||
onClick={onOpenSettings}
|
|
||||||
title="Settings"
|
|
||||||
ariaLabel="Settings"
|
|
||||||
variant="ghost"
|
|
||||||
/>
|
|
||||||
{activeAccount && (
|
|
||||||
<IconButton
|
<IconButton
|
||||||
icon={faRightFromBracket}
|
icon={faPersonHiking}
|
||||||
onClick={onLogout}
|
onClick={() => {
|
||||||
title="Logout"
|
if (isMobile) {
|
||||||
ariaLabel="Logout"
|
onToggleCollapse()
|
||||||
|
}
|
||||||
|
navigate('/explore')
|
||||||
|
}}
|
||||||
|
title="Explore"
|
||||||
|
ariaLabel="Explore"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
/>
|
/>
|
||||||
)}
|
<IconButton
|
||||||
|
icon={faGear}
|
||||||
|
onClick={() => {
|
||||||
|
if (isMobile) {
|
||||||
|
onToggleCollapse()
|
||||||
|
}
|
||||||
|
onOpenSettings()
|
||||||
|
}}
|
||||||
|
title="Settings"
|
||||||
|
ariaLabel="Settings"
|
||||||
|
variant="ghost"
|
||||||
|
/>
|
||||||
|
{!isMobile && (
|
||||||
|
<button
|
||||||
|
onClick={onToggleCollapse}
|
||||||
|
className="toggle-sidebar-btn"
|
||||||
|
title="Collapse bookmarks sidebar"
|
||||||
|
aria-label="Collapse bookmarks sidebar"
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon={faChevronRight} />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { Models } from 'applesauce-core'
|
|||||||
import { useEventModel } from 'applesauce-react/hooks'
|
import { useEventModel } from 'applesauce-react/hooks'
|
||||||
import { useNavigate } from 'react-router-dom'
|
import { useNavigate } from 'react-router-dom'
|
||||||
import { nip19 } from 'nostr-tools'
|
import { nip19 } from 'nostr-tools'
|
||||||
|
import { getProfileDisplayName } from '../utils/nostrUriResolver'
|
||||||
|
|
||||||
interface SupportProps {
|
interface SupportProps {
|
||||||
relayPool: RelayPool
|
relayPool: RelayPool
|
||||||
@@ -182,7 +183,7 @@ const SupporterCard: React.FC<SupporterCardProps> = ({ supporter, isWhale }) =>
|
|||||||
const profile = useEventModel(Models.ProfileModel, [supporter.pubkey])
|
const profile = useEventModel(Models.ProfileModel, [supporter.pubkey])
|
||||||
|
|
||||||
const picture = profile?.picture
|
const picture = profile?.picture
|
||||||
const name = profile?.name || profile?.display_name || `${supporter.pubkey.slice(0, 8)}...`
|
const name = getProfileDisplayName(profile, supporter.pubkey)
|
||||||
|
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
const npub = nip19.npubEncode(supporter.pubkey)
|
const npub = nip19.npubEncode(supporter.pubkey)
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ const TTSControls: React.FC<Props> = ({ text, defaultLang, className, settings }
|
|||||||
const lang = detect(text)
|
const lang = detect(text)
|
||||||
if (typeof lang === 'string' && lang.length >= 2) langOverride = lang.slice(0, 2)
|
if (typeof lang === 'string' && lang.length >= 2) langOverride = lang.slice(0, 2)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.debug('[tts][detect] failed', err)
|
// ignore detection errors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!langOverride && resolvedSystemLang) {
|
if (!langOverride && resolvedSystemLang) {
|
||||||
@@ -78,7 +78,6 @@ const TTSControls: React.FC<Props> = ({ text, defaultLang, className, settings }
|
|||||||
const currentIndex = SPEED_OPTIONS.indexOf(rate)
|
const currentIndex = SPEED_OPTIONS.indexOf(rate)
|
||||||
const nextIndex = (currentIndex + 1) % SPEED_OPTIONS.length
|
const nextIndex = (currentIndex + 1) % SPEED_OPTIONS.length
|
||||||
const next = SPEED_OPTIONS[nextIndex]
|
const next = SPEED_OPTIONS[nextIndex]
|
||||||
console.debug('[tts][ui] cycle speed', { from: rate, to: next, speaking, paused })
|
|
||||||
setRate(next)
|
setRate(next)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { RelayPool } from 'applesauce-relay'
|
|||||||
import { IEventStore } from 'applesauce-core'
|
import { IEventStore } from 'applesauce-core'
|
||||||
import { BookmarkList } from './BookmarkList'
|
import { BookmarkList } from './BookmarkList'
|
||||||
import ContentPanel from './ContentPanel'
|
import ContentPanel from './ContentPanel'
|
||||||
|
import VideoView from './VideoView'
|
||||||
import { HighlightsPanel } from './HighlightsPanel'
|
import { HighlightsPanel } from './HighlightsPanel'
|
||||||
import Settings from './Settings'
|
import Settings from './Settings'
|
||||||
import Toast from './Toast'
|
import Toast from './Toast'
|
||||||
@@ -19,6 +20,7 @@ import { HighlightVisibility } from './HighlightsPanel'
|
|||||||
import { HighlightButtonRef } from './HighlightButton'
|
import { HighlightButtonRef } from './HighlightButton'
|
||||||
import { BookmarkReference } from '../utils/contentLoader'
|
import { BookmarkReference } from '../utils/contentLoader'
|
||||||
import { useIsMobile } from '../hooks/useMediaQuery'
|
import { useIsMobile } from '../hooks/useMediaQuery'
|
||||||
|
import { classifyUrl } from '../utils/helpers'
|
||||||
import { useScrollDirection } from '../hooks/useScrollDirection'
|
import { useScrollDirection } from '../hooks/useScrollDirection'
|
||||||
import { IAccount } from 'applesauce-accounts'
|
import { IAccount } from 'applesauce-accounts'
|
||||||
import { NostrEvent } from 'nostr-tools'
|
import { NostrEvent } from 'nostr-tools'
|
||||||
@@ -134,15 +136,30 @@ const ThreePaneLayout: React.FC<ThreePaneLayoutProps> = (props) => {
|
|||||||
const showHighlightsButton = scrollDirection !== 'down' && !isAtTop
|
const showHighlightsButton = scrollDirection !== 'down' && !isAtTop
|
||||||
|
|
||||||
// Lock body scroll when mobile sidebar or highlights is open
|
// Lock body scroll when mobile sidebar or highlights is open
|
||||||
|
const savedScrollPosition = useRef<number>(0)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isMobile && (props.isSidebarOpen || !props.isHighlightsCollapsed)) {
|
if (isMobile && (props.isSidebarOpen || !props.isHighlightsCollapsed)) {
|
||||||
|
// Save current scroll position
|
||||||
|
savedScrollPosition.current = window.scrollY
|
||||||
|
document.body.style.top = `-${savedScrollPosition.current}px`
|
||||||
document.body.classList.add('mobile-sidebar-open')
|
document.body.classList.add('mobile-sidebar-open')
|
||||||
} else {
|
} else {
|
||||||
|
// Restore scroll position
|
||||||
document.body.classList.remove('mobile-sidebar-open')
|
document.body.classList.remove('mobile-sidebar-open')
|
||||||
|
document.body.style.top = ''
|
||||||
|
if (savedScrollPosition.current > 0) {
|
||||||
|
// Use requestAnimationFrame to ensure DOM has updated
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
window.scrollTo(0, savedScrollPosition.current)
|
||||||
|
savedScrollPosition.current = 0
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
document.body.classList.remove('mobile-sidebar-open')
|
document.body.classList.remove('mobile-sidebar-open')
|
||||||
|
document.body.style.top = ''
|
||||||
}
|
}
|
||||||
}, [isMobile, props.isSidebarOpen, props.isHighlightsCollapsed])
|
}, [isMobile, props.isSidebarOpen, props.isHighlightsCollapsed])
|
||||||
|
|
||||||
@@ -306,7 +323,7 @@ const ThreePaneLayout: React.FC<ThreePaneLayoutProps> = (props) => {
|
|||||||
<div
|
<div
|
||||||
ref={sidebarRef}
|
ref={sidebarRef}
|
||||||
className={`pane sidebar ${isMobile && props.isSidebarOpen ? 'mobile-open' : ''}`}
|
className={`pane sidebar ${isMobile && props.isSidebarOpen ? 'mobile-open' : ''}`}
|
||||||
aria-hidden={isMobile && !props.isSidebarOpen}
|
{...(isMobile && !props.isSidebarOpen ? { inert: '' } : {})}
|
||||||
>
|
>
|
||||||
<BookmarkList
|
<BookmarkList
|
||||||
bookmarks={props.bookmarks}
|
bookmarks={props.bookmarks}
|
||||||
@@ -358,42 +375,73 @@ const ThreePaneLayout: React.FC<ThreePaneLayoutProps> = (props) => {
|
|||||||
<>
|
<>
|
||||||
{props.support}
|
{props.support}
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (() => {
|
||||||
<ContentPanel
|
// Determine if this is a video URL
|
||||||
loading={props.readerLoading}
|
const isNostrArticle = props.selectedUrl && props.selectedUrl.startsWith('nostr:')
|
||||||
title={props.readerContent?.title}
|
const isExternalVideo = !isNostrArticle && !!props.selectedUrl && ['youtube', 'video'].includes(classifyUrl(props.selectedUrl).type)
|
||||||
html={props.readerContent?.html}
|
|
||||||
markdown={props.readerContent?.markdown}
|
if (isExternalVideo) {
|
||||||
image={props.readerContent?.image}
|
return (
|
||||||
summary={props.readerContent?.summary}
|
<VideoView
|
||||||
published={props.readerContent?.published}
|
videoUrl={props.selectedUrl!}
|
||||||
selectedUrl={props.selectedUrl}
|
title={props.readerContent?.title}
|
||||||
highlights={props.selectedUrl && props.selectedUrl.startsWith('nostr:')
|
image={props.readerContent?.image}
|
||||||
? props.highlights // article-specific highlights only
|
summary={props.readerContent?.summary}
|
||||||
: props.classifiedHighlights}
|
published={props.readerContent?.published}
|
||||||
showHighlights={props.showHighlights}
|
settings={props.settings}
|
||||||
highlightStyle={props.settings.highlightStyle || 'marker'}
|
relayPool={props.relayPool}
|
||||||
highlightColor={props.settings.highlightColor || '#ffff00'}
|
activeAccount={props.activeAccount}
|
||||||
onHighlightClick={props.onHighlightClick}
|
onOpenHighlights={() => {
|
||||||
selectedHighlightId={props.selectedHighlightId}
|
if (props.isHighlightsCollapsed) {
|
||||||
highlightVisibility={props.highlightVisibility}
|
props.onToggleHighlightsPanel()
|
||||||
onTextSelection={props.onTextSelection}
|
}
|
||||||
onClearSelection={props.onClearSelection}
|
}}
|
||||||
currentUserPubkey={props.currentUserPubkey}
|
/>
|
||||||
followedPubkeys={props.followedPubkeys}
|
)
|
||||||
settings={props.settings}
|
}
|
||||||
relayPool={props.relayPool}
|
|
||||||
activeAccount={props.activeAccount}
|
return (
|
||||||
currentArticle={props.currentArticle}
|
<ContentPanel
|
||||||
isSidebarCollapsed={props.isCollapsed}
|
loading={props.readerLoading}
|
||||||
isHighlightsCollapsed={props.isHighlightsCollapsed}
|
title={props.readerContent?.title}
|
||||||
/>
|
html={props.readerContent?.html}
|
||||||
)}
|
markdown={props.readerContent?.markdown}
|
||||||
|
image={props.readerContent?.image}
|
||||||
|
summary={props.readerContent?.summary}
|
||||||
|
published={props.readerContent?.published}
|
||||||
|
selectedUrl={props.selectedUrl}
|
||||||
|
highlights={props.selectedUrl && props.selectedUrl.startsWith('nostr:')
|
||||||
|
? props.highlights // article-specific highlights only
|
||||||
|
: props.classifiedHighlights}
|
||||||
|
showHighlights={props.showHighlights}
|
||||||
|
highlightStyle={props.settings.highlightStyle || 'marker'}
|
||||||
|
highlightColor={props.settings.highlightColor || '#ffff00'}
|
||||||
|
onHighlightClick={props.onHighlightClick}
|
||||||
|
selectedHighlightId={props.selectedHighlightId}
|
||||||
|
highlightVisibility={props.highlightVisibility}
|
||||||
|
onTextSelection={props.onTextSelection}
|
||||||
|
onClearSelection={props.onClearSelection}
|
||||||
|
currentUserPubkey={props.currentUserPubkey}
|
||||||
|
followedPubkeys={props.followedPubkeys}
|
||||||
|
settings={props.settings}
|
||||||
|
relayPool={props.relayPool}
|
||||||
|
activeAccount={props.activeAccount}
|
||||||
|
currentArticle={props.currentArticle}
|
||||||
|
isSidebarCollapsed={props.isCollapsed}
|
||||||
|
isHighlightsCollapsed={props.isHighlightsCollapsed}
|
||||||
|
onOpenHighlights={() => {
|
||||||
|
if (props.isHighlightsCollapsed) {
|
||||||
|
props.onToggleHighlightsPanel()
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
})()}
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
ref={highlightsRef}
|
ref={highlightsRef}
|
||||||
className={`pane highlights ${isMobile && !props.isHighlightsCollapsed ? 'mobile-open' : ''}`}
|
className={`pane highlights ${isMobile && !props.isHighlightsCollapsed ? 'mobile-open' : ''}`}
|
||||||
aria-hidden={isMobile && props.isHighlightsCollapsed}
|
{...(isMobile && props.isHighlightsCollapsed ? { inert: '' } : {})}
|
||||||
>
|
>
|
||||||
<HighlightsPanel
|
<HighlightsPanel
|
||||||
highlights={props.highlights}
|
highlights={props.highlights}
|
||||||
@@ -413,6 +461,7 @@ const ThreePaneLayout: React.FC<ThreePaneLayoutProps> = (props) => {
|
|||||||
relayPool={props.relayPool}
|
relayPool={props.relayPool}
|
||||||
eventStore={props.eventStore}
|
eventStore={props.eventStore}
|
||||||
settings={props.settings}
|
settings={props.settings}
|
||||||
|
isMobile={isMobile}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useMemo, forwardRef } from 'react'
|
import { useMemo, forwardRef } from 'react'
|
||||||
import ReactPlayer from 'react-player'
|
import ReactPlayer from 'react-player'
|
||||||
import { classifyUrl } from '../utils/helpers'
|
import { classifyUrl } from '../utils/helpers'
|
||||||
|
|
||||||
@@ -6,8 +6,6 @@ interface VideoEmbedProcessorProps {
|
|||||||
html: string
|
html: string
|
||||||
renderVideoLinksAsEmbeds: boolean
|
renderVideoLinksAsEmbeds: boolean
|
||||||
className?: string
|
className?: string
|
||||||
onMouseUp?: (e: React.MouseEvent) => void
|
|
||||||
onTouchEnd?: (e: React.TouchEvent) => void
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,13 +15,12 @@ interface VideoEmbedProcessorProps {
|
|||||||
const VideoEmbedProcessor = forwardRef<HTMLDivElement, VideoEmbedProcessorProps>(({
|
const VideoEmbedProcessor = forwardRef<HTMLDivElement, VideoEmbedProcessorProps>(({
|
||||||
html,
|
html,
|
||||||
renderVideoLinksAsEmbeds,
|
renderVideoLinksAsEmbeds,
|
||||||
className,
|
className
|
||||||
onMouseUp,
|
|
||||||
onTouchEnd
|
|
||||||
}, ref) => {
|
}, ref) => {
|
||||||
const processedHtml = useMemo(() => {
|
// Process HTML and extract video URLs in a single pass to keep them in sync
|
||||||
|
const { processedHtml, videoUrls } = useMemo(() => {
|
||||||
if (!renderVideoLinksAsEmbeds || !html) {
|
if (!renderVideoLinksAsEmbeds || !html) {
|
||||||
return html
|
return { processedHtml: html, videoUrls: [] }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process HTML in stages: <video> blocks, <img> tags with video src, and bare video URLs
|
// Process HTML in stages: <video> blocks, <img> tags with video src, and bare video URLs
|
||||||
@@ -86,71 +83,19 @@ const VideoEmbedProcessor = forwardRef<HTMLDivElement, VideoEmbedProcessorProps>
|
|||||||
|
|
||||||
const remainingUrls = [...fileVideoUrls, ...platformVideoUrls].filter(url => !collectedUrls.includes(url))
|
const remainingUrls = [...fileVideoUrls, ...platformVideoUrls].filter(url => !collectedUrls.includes(url))
|
||||||
|
|
||||||
let processedHtml = result
|
let finalHtml = result
|
||||||
remainingUrls.forEach((url) => {
|
remainingUrls.forEach((url) => {
|
||||||
const placeholder = `__VIDEO_EMBED_${placeholderIndex}__`
|
const placeholder = `__VIDEO_EMBED_${placeholderIndex}__`
|
||||||
processedHtml = processedHtml.replace(new RegExp(url.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), placeholder)
|
finalHtml = finalHtml.replace(new RegExp(url.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), placeholder)
|
||||||
collectedUrls.push(url)
|
collectedUrls.push(url)
|
||||||
placeholderIndex++
|
placeholderIndex++
|
||||||
})
|
})
|
||||||
|
|
||||||
// If nothing collected, return original html
|
// Return both processed HTML and collected URLs (in the same order as placeholders)
|
||||||
if (collectedUrls.length === 0) {
|
return {
|
||||||
return html
|
processedHtml: collectedUrls.length > 0 ? finalHtml : html,
|
||||||
|
videoUrls: collectedUrls
|
||||||
}
|
}
|
||||||
|
|
||||||
return processedHtml
|
|
||||||
}, [html, renderVideoLinksAsEmbeds])
|
|
||||||
|
|
||||||
const videoUrls = useMemo(() => {
|
|
||||||
if (!renderVideoLinksAsEmbeds || !html) {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
|
|
||||||
const urls: string[] = []
|
|
||||||
|
|
||||||
// 1) Extract from <video> blocks first (video src or nested source src)
|
|
||||||
const videoBlockPattern = /<video[^>]*>[\s\S]*?<\/video>/gi
|
|
||||||
const videoBlocks = html.match(videoBlockPattern) || []
|
|
||||||
videoBlocks.forEach((block) => {
|
|
||||||
let url: string | null = null
|
|
||||||
const videoSrcMatch = block.match(/<video[^>]*\s+src=["']?(https?:\/\/[^\s<>"']+\.(mp4|webm|ogg|mov|avi|mkv|m4v)[^\s<>"']*)["']?[^>]*>/i)
|
|
||||||
if (videoSrcMatch && videoSrcMatch[1]) {
|
|
||||||
url = videoSrcMatch[1]
|
|
||||||
} else {
|
|
||||||
const sourceSrcMatch = block.match(/<source[^>]*\s+src=["']?(https?:\/\/[^\s<>"']+\.(mp4|webm|ogg|mov|avi|mkv|m4v)[^\s<>"']*)["']?[^>]*>/i)
|
|
||||||
if (sourceSrcMatch && sourceSrcMatch[1]) {
|
|
||||||
url = sourceSrcMatch[1]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (url && !urls.includes(url)) urls.push(url)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 2) Extract from <img> tags with video src
|
|
||||||
const imgTagPattern = /<img[^>]*>/gi
|
|
||||||
const allImgTags = html.match(imgTagPattern) || []
|
|
||||||
allImgTags.forEach((imgTag) => {
|
|
||||||
const srcMatch = imgTag.match(/src=["']?(https?:\/\/[^\s<>"']+\.(mp4|webm|ogg|mov|avi|mkv|m4v)[^\s<>"']*)["']?/i)
|
|
||||||
if (srcMatch && srcMatch[1] && !urls.includes(srcMatch[1])) {
|
|
||||||
urls.push(srcMatch[1])
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// 3) Extract remaining direct file URLs and platform-classified video URLs
|
|
||||||
const fileVideoPattern = /https?:\/\/[^\s<>"']+\.(mp4|webm|ogg|mov|avi|mkv|m4v)(?:\?[^\s<>"']*)?/gi
|
|
||||||
const fileVideoUrls: string[] = html.match(fileVideoPattern) || []
|
|
||||||
fileVideoUrls.forEach(u => { if (!urls.includes(u)) urls.push(u) })
|
|
||||||
|
|
||||||
const allUrlPattern = /https?:\/\/[^\s<>"']+(?=\s|>|"|'|$)/gi
|
|
||||||
const allUrls: string[] = html.match(allUrlPattern) || []
|
|
||||||
allUrls.forEach(u => {
|
|
||||||
const classification = classifyUrl(u)
|
|
||||||
if (classification.type === 'video' && !urls.includes(u)) {
|
|
||||||
urls.push(u)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return urls
|
|
||||||
}, [html, renderVideoLinksAsEmbeds])
|
}, [html, renderVideoLinksAsEmbeds])
|
||||||
|
|
||||||
// If no video embedding is enabled, just render the HTML normally
|
// If no video embedding is enabled, just render the HTML normally
|
||||||
@@ -160,8 +105,6 @@ const VideoEmbedProcessor = forwardRef<HTMLDivElement, VideoEmbedProcessorProps>
|
|||||||
ref={ref}
|
ref={ref}
|
||||||
className={className}
|
className={className}
|
||||||
dangerouslySetInnerHTML={{ __html: processedHtml }}
|
dangerouslySetInnerHTML={{ __html: processedHtml }}
|
||||||
onMouseUp={onMouseUp}
|
|
||||||
onTouchEnd={onTouchEnd}
|
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -170,7 +113,7 @@ const VideoEmbedProcessor = forwardRef<HTMLDivElement, VideoEmbedProcessorProps>
|
|||||||
const parts = processedHtml.split(/(__VIDEO_EMBED_\d+__)/)
|
const parts = processedHtml.split(/(__VIDEO_EMBED_\d+__)/)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={ref} className={className} onMouseUp={onMouseUp} onTouchEnd={onTouchEnd}>
|
<div ref={ref} className={className}>
|
||||||
{parts.map((part, index) => {
|
{parts.map((part, index) => {
|
||||||
const videoMatch = part.match(/^__VIDEO_EMBED_(\d+)__$/)
|
const videoMatch = part.match(/^__VIDEO_EMBED_(\d+)__$/)
|
||||||
if (videoMatch) {
|
if (videoMatch) {
|
||||||
@@ -195,13 +138,16 @@ const VideoEmbedProcessor = forwardRef<HTMLDivElement, VideoEmbedProcessorProps>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regular HTML content
|
// Regular HTML content - only render if not empty
|
||||||
return (
|
if (part.trim()) {
|
||||||
<div
|
return (
|
||||||
key={index}
|
<div
|
||||||
dangerouslySetInnerHTML={{ __html: part }}
|
key={index}
|
||||||
/>
|
dangerouslySetInnerHTML={{ __html: part }}
|
||||||
)
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return null
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
320
src/components/VideoView.tsx
Normal file
320
src/components/VideoView.tsx
Normal file
@@ -0,0 +1,320 @@
|
|||||||
|
import React, { useState, useEffect, useRef } from 'react'
|
||||||
|
import ReactPlayer from 'react-player'
|
||||||
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||||
|
import { faEllipsisH, faExternalLinkAlt, faMobileAlt, faCopy, faShare, faCheckCircle } from '@fortawesome/free-solid-svg-icons'
|
||||||
|
import { RelayPool } from 'applesauce-relay'
|
||||||
|
import { IAccount } from 'applesauce-accounts'
|
||||||
|
import { UserSettings } from '../services/settingsService'
|
||||||
|
import { extractYouTubeId, getYouTubeMeta } from '../services/youtubeMetaService'
|
||||||
|
import { buildNativeVideoUrl } from '../utils/videoHelpers'
|
||||||
|
import { getYouTubeThumbnail } from '../utils/imagePreview'
|
||||||
|
|
||||||
|
// Helper function to get Vimeo thumbnail
|
||||||
|
const getVimeoThumbnail = (url: string): string | null => {
|
||||||
|
const vimeoMatch = url.match(/vimeo\.com\/(\d+)/)
|
||||||
|
if (!vimeoMatch) return null
|
||||||
|
|
||||||
|
const videoId = vimeoMatch[1]
|
||||||
|
return `https://vumbnail.com/${videoId}.jpg`
|
||||||
|
}
|
||||||
|
import {
|
||||||
|
createWebsiteReaction,
|
||||||
|
hasMarkedWebsiteAsRead
|
||||||
|
} from '../services/reactionService'
|
||||||
|
import { unarchiveWebsite } from '../services/unarchiveService'
|
||||||
|
import ReaderHeader from './ReaderHeader'
|
||||||
|
|
||||||
|
interface VideoViewProps {
|
||||||
|
videoUrl: string
|
||||||
|
title?: string
|
||||||
|
image?: string
|
||||||
|
summary?: string
|
||||||
|
published?: number
|
||||||
|
settings?: UserSettings
|
||||||
|
relayPool?: RelayPool | null
|
||||||
|
activeAccount?: IAccount | null
|
||||||
|
onOpenHighlights?: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
const VideoView: React.FC<VideoViewProps> = ({
|
||||||
|
videoUrl,
|
||||||
|
title,
|
||||||
|
image,
|
||||||
|
summary,
|
||||||
|
published,
|
||||||
|
settings,
|
||||||
|
relayPool,
|
||||||
|
activeAccount,
|
||||||
|
onOpenHighlights
|
||||||
|
}) => {
|
||||||
|
const [isMarkedAsWatched, setIsMarkedAsWatched] = useState(false)
|
||||||
|
const [isCheckingWatchedStatus, setIsCheckingWatchedStatus] = useState(false)
|
||||||
|
const [showCheckAnimation, setShowCheckAnimation] = useState(false)
|
||||||
|
const [showVideoMenu, setShowVideoMenu] = useState(false)
|
||||||
|
const [videoMenuOpenUpward, setVideoMenuOpenUpward] = useState(false)
|
||||||
|
const [videoDurationSec, setVideoDurationSec] = useState<number | null>(null)
|
||||||
|
const [ytMeta, setYtMeta] = useState<{ title?: string; description?: string; transcript?: string } | null>(null)
|
||||||
|
const videoMenuRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
|
// Load YouTube metadata when applicable
|
||||||
|
useEffect(() => {
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
if (!videoUrl) return setYtMeta(null)
|
||||||
|
const id = extractYouTubeId(videoUrl)
|
||||||
|
if (!id) return setYtMeta(null)
|
||||||
|
const locale = navigator?.language?.split('-')[0] || 'en'
|
||||||
|
const data = await getYouTubeMeta(id, locale)
|
||||||
|
if (data) setYtMeta({ title: data.title, description: data.description, transcript: data.transcript })
|
||||||
|
} catch {
|
||||||
|
setYtMeta(null)
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
}, [videoUrl])
|
||||||
|
|
||||||
|
// Check if video is marked as watched
|
||||||
|
useEffect(() => {
|
||||||
|
const checkWatchedStatus = async () => {
|
||||||
|
if (!activeAccount || !videoUrl) return
|
||||||
|
|
||||||
|
setIsCheckingWatchedStatus(true)
|
||||||
|
try {
|
||||||
|
const isWatched = relayPool ? await hasMarkedWebsiteAsRead(videoUrl, activeAccount.pubkey, relayPool) : false
|
||||||
|
setIsMarkedAsWatched(isWatched)
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Failed to check watched status:', error)
|
||||||
|
} finally {
|
||||||
|
setIsCheckingWatchedStatus(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkWatchedStatus()
|
||||||
|
}, [activeAccount, videoUrl, relayPool])
|
||||||
|
|
||||||
|
// Handle click outside to close menu
|
||||||
|
useEffect(() => {
|
||||||
|
const handleClickOutside = (event: MouseEvent) => {
|
||||||
|
const target = event.target as Node
|
||||||
|
if (videoMenuRef.current && !videoMenuRef.current.contains(target)) {
|
||||||
|
setShowVideoMenu(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showVideoMenu) {
|
||||||
|
document.addEventListener('mousedown', handleClickOutside)
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('mousedown', handleClickOutside)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [showVideoMenu])
|
||||||
|
|
||||||
|
// Check menu position for upward opening
|
||||||
|
useEffect(() => {
|
||||||
|
const checkMenuPosition = (menuRef: React.RefObject<HTMLDivElement>, setOpenUpward: (upward: boolean) => void) => {
|
||||||
|
if (!menuRef.current) return
|
||||||
|
|
||||||
|
const rect = menuRef.current.getBoundingClientRect()
|
||||||
|
const viewportHeight = window.innerHeight
|
||||||
|
const spaceBelow = viewportHeight - rect.bottom
|
||||||
|
const spaceAbove = rect.top
|
||||||
|
|
||||||
|
// Open upward if there's more space above and less space below
|
||||||
|
setOpenUpward(spaceAbove > spaceBelow && spaceBelow < 200)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showVideoMenu) {
|
||||||
|
checkMenuPosition(videoMenuRef, setVideoMenuOpenUpward)
|
||||||
|
}
|
||||||
|
}, [showVideoMenu])
|
||||||
|
|
||||||
|
const formatDuration = (totalSeconds: number): string => {
|
||||||
|
const hours = Math.floor(totalSeconds / 3600)
|
||||||
|
const minutes = Math.floor((totalSeconds % 3600) / 60)
|
||||||
|
const seconds = Math.floor(totalSeconds % 60)
|
||||||
|
const mm = hours > 0 ? String(minutes).padStart(2, '0') : String(minutes)
|
||||||
|
const ss = String(seconds).padStart(2, '0')
|
||||||
|
return hours > 0 ? `${hours}:${mm}:${ss}` : `${mm}:${ss}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleMarkAsWatched = async () => {
|
||||||
|
if (!activeAccount || !videoUrl || isCheckingWatchedStatus) return
|
||||||
|
|
||||||
|
setIsCheckingWatchedStatus(true)
|
||||||
|
setShowCheckAnimation(true)
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (isMarkedAsWatched) {
|
||||||
|
// Unmark as watched
|
||||||
|
if (relayPool) {
|
||||||
|
await unarchiveWebsite(videoUrl, activeAccount, relayPool)
|
||||||
|
}
|
||||||
|
setIsMarkedAsWatched(false)
|
||||||
|
} else {
|
||||||
|
// Mark as watched
|
||||||
|
if (relayPool) {
|
||||||
|
await createWebsiteReaction(videoUrl, activeAccount, relayPool)
|
||||||
|
}
|
||||||
|
setIsMarkedAsWatched(true)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Failed to update watched status:', error)
|
||||||
|
} finally {
|
||||||
|
setIsCheckingWatchedStatus(false)
|
||||||
|
setTimeout(() => setShowCheckAnimation(false), 1000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const toggleVideoMenu = () => setShowVideoMenu(v => !v)
|
||||||
|
|
||||||
|
const handleOpenVideoExternal = () => {
|
||||||
|
window.open(videoUrl, '_blank', 'noopener,noreferrer')
|
||||||
|
setShowVideoMenu(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleOpenVideoNative = () => {
|
||||||
|
const native = buildNativeVideoUrl(videoUrl)
|
||||||
|
if (native) {
|
||||||
|
window.location.href = native
|
||||||
|
} else {
|
||||||
|
window.location.href = videoUrl
|
||||||
|
}
|
||||||
|
setShowVideoMenu(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCopyVideoUrl = async () => {
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(videoUrl)
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Clipboard copy failed', e)
|
||||||
|
} finally {
|
||||||
|
setShowVideoMenu(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleShareVideoUrl = async () => {
|
||||||
|
try {
|
||||||
|
if ((navigator as { share?: (d: { title?: string; url?: string }) => Promise<void> }).share) {
|
||||||
|
await (navigator as { share: (d: { title?: string; url?: string }) => Promise<void> }).share({
|
||||||
|
title: ytMeta?.title || title || 'Video',
|
||||||
|
url: videoUrl
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
await navigator.clipboard.writeText(videoUrl)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Share failed', e)
|
||||||
|
} finally {
|
||||||
|
setShowVideoMenu(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const displayTitle = ytMeta?.title || title
|
||||||
|
const displaySummary = ytMeta?.description || summary
|
||||||
|
const durationText = videoDurationSec !== null ? formatDuration(videoDurationSec) : null
|
||||||
|
|
||||||
|
// Get video thumbnail for cover image
|
||||||
|
const youtubeThumbnail = getYouTubeThumbnail(videoUrl)
|
||||||
|
const vimeoThumbnail = getVimeoThumbnail(videoUrl)
|
||||||
|
const videoThumbnail = youtubeThumbnail || vimeoThumbnail
|
||||||
|
const displayImage = videoThumbnail || image
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ReaderHeader
|
||||||
|
title={displayTitle}
|
||||||
|
image={displayImage}
|
||||||
|
summary={displaySummary}
|
||||||
|
published={published}
|
||||||
|
readingTimeText={durationText}
|
||||||
|
hasHighlights={false}
|
||||||
|
highlightCount={0}
|
||||||
|
settings={settings}
|
||||||
|
highlights={[]}
|
||||||
|
highlightVisibility={{ nostrverse: true, friends: true, mine: true }}
|
||||||
|
onHighlightCountClick={onOpenHighlights}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="reader-video">
|
||||||
|
<ReactPlayer
|
||||||
|
url={videoUrl}
|
||||||
|
controls
|
||||||
|
width="100%"
|
||||||
|
height="auto"
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
height: 'auto',
|
||||||
|
aspectRatio: '16/9'
|
||||||
|
}}
|
||||||
|
onDuration={(d) => setVideoDurationSec(Math.floor(d))}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{displaySummary && (
|
||||||
|
<div className="large-text" style={{ color: '#ddd', padding: '0 0.75rem', whiteSpace: 'pre-wrap', marginBottom: '0.75rem' }}>
|
||||||
|
{displaySummary}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{ytMeta?.transcript && (
|
||||||
|
<div style={{ padding: '0 0.75rem 1rem 0.75rem' }}>
|
||||||
|
<h3 style={{ margin: '1rem 0 0.5rem 0', fontSize: '1rem', color: '#aaa' }}>Transcript</h3>
|
||||||
|
<div className="large-text" style={{ whiteSpace: 'pre-wrap', color: '#ddd' }}>
|
||||||
|
{ytMeta.transcript}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="article-menu-container">
|
||||||
|
<div className="article-menu-wrapper" ref={videoMenuRef}>
|
||||||
|
<button
|
||||||
|
className="article-menu-btn"
|
||||||
|
onClick={toggleVideoMenu}
|
||||||
|
title="More options"
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon={faEllipsisH} />
|
||||||
|
</button>
|
||||||
|
{showVideoMenu && (
|
||||||
|
<div className={`article-menu ${videoMenuOpenUpward ? 'open-upward' : ''}`}>
|
||||||
|
<button className="article-menu-item" onClick={handleOpenVideoExternal}>
|
||||||
|
<FontAwesomeIcon icon={faExternalLinkAlt} />
|
||||||
|
<span>Open Link</span>
|
||||||
|
</button>
|
||||||
|
<button className="article-menu-item" onClick={handleOpenVideoNative}>
|
||||||
|
<FontAwesomeIcon icon={faMobileAlt} />
|
||||||
|
<span>Open in Native App</span>
|
||||||
|
</button>
|
||||||
|
<button className="article-menu-item" onClick={handleCopyVideoUrl}>
|
||||||
|
<FontAwesomeIcon icon={faCopy} />
|
||||||
|
<span>Copy URL</span>
|
||||||
|
</button>
|
||||||
|
<button className="article-menu-item" onClick={handleShareVideoUrl}>
|
||||||
|
<FontAwesomeIcon icon={faShare} />
|
||||||
|
<span>Share</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{activeAccount && (
|
||||||
|
<div className="mark-as-read-container">
|
||||||
|
<button
|
||||||
|
className={`mark-as-read-btn ${isMarkedAsWatched ? 'marked' : ''} ${showCheckAnimation ? 'animating' : ''}`}
|
||||||
|
onClick={handleMarkAsWatched}
|
||||||
|
disabled={isCheckingWatchedStatus}
|
||||||
|
title={isMarkedAsWatched ? 'Already Marked as Watched' : 'Mark as Watched'}
|
||||||
|
style={isMarkedAsWatched ? { opacity: 0.85 } : undefined}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon
|
||||||
|
icon={faCheckCircle}
|
||||||
|
className={isMarkedAsWatched ? 'check-icon' : 'check-icon-empty'}
|
||||||
|
/>
|
||||||
|
<span>{isMarkedAsWatched ? 'Watched' : 'Mark as Watched'}</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default VideoView
|
||||||
@@ -1,15 +1,31 @@
|
|||||||
import { useEffect, useRef, Dispatch, SetStateAction } from 'react'
|
import { useEffect, useRef, useState, Dispatch, SetStateAction } from 'react'
|
||||||
|
import { useLocation } from 'react-router-dom'
|
||||||
import { RelayPool } from 'applesauce-relay'
|
import { RelayPool } from 'applesauce-relay'
|
||||||
import { fetchArticleByNaddr } from '../services/articleService'
|
import type { IEventStore } from 'applesauce-core'
|
||||||
|
import { nip19 } from 'nostr-tools'
|
||||||
|
import { AddressPointer } from 'nostr-tools/nip19'
|
||||||
|
import { Helpers } from 'applesauce-core'
|
||||||
|
import { queryEvents } from '../services/dataFetch'
|
||||||
|
import { fetchArticleByNaddr, getFromCache, saveToCache } from '../services/articleService'
|
||||||
import { fetchHighlightsForArticle } from '../services/highlightService'
|
import { fetchHighlightsForArticle } from '../services/highlightService'
|
||||||
|
import { preloadImage } from './useImageCache'
|
||||||
import { ReadableContent } from '../services/readerService'
|
import { ReadableContent } from '../services/readerService'
|
||||||
import { Highlight } from '../types/highlights'
|
import { Highlight } from '../types/highlights'
|
||||||
import { NostrEvent } from 'nostr-tools'
|
import { NostrEvent } from 'nostr-tools'
|
||||||
import { UserSettings } from '../services/settingsService'
|
import { UserSettings } from '../services/settingsService'
|
||||||
|
import { useDocumentTitle } from './useDocumentTitle'
|
||||||
|
|
||||||
|
interface PreviewData {
|
||||||
|
title: string
|
||||||
|
image?: string
|
||||||
|
summary?: string
|
||||||
|
published?: number
|
||||||
|
}
|
||||||
|
|
||||||
interface UseArticleLoaderProps {
|
interface UseArticleLoaderProps {
|
||||||
naddr: string | undefined
|
naddr: string | undefined
|
||||||
relayPool: RelayPool | null
|
relayPool: RelayPool | null
|
||||||
|
eventStore?: IEventStore | null
|
||||||
setSelectedUrl: (url: string) => void
|
setSelectedUrl: (url: string) => void
|
||||||
setReaderContent: (content: ReadableContent | undefined) => void
|
setReaderContent: (content: ReadableContent | undefined) => void
|
||||||
setReaderLoading: (loading: boolean) => void
|
setReaderLoading: (loading: boolean) => void
|
||||||
@@ -25,6 +41,7 @@ interface UseArticleLoaderProps {
|
|||||||
export function useArticleLoader({
|
export function useArticleLoader({
|
||||||
naddr,
|
naddr,
|
||||||
relayPool,
|
relayPool,
|
||||||
|
eventStore,
|
||||||
setSelectedUrl,
|
setSelectedUrl,
|
||||||
setReaderContent,
|
setReaderContent,
|
||||||
setReaderLoading,
|
setReaderLoading,
|
||||||
@@ -36,75 +53,453 @@ export function useArticleLoader({
|
|||||||
setCurrentArticle,
|
setCurrentArticle,
|
||||||
settings
|
settings
|
||||||
}: UseArticleLoaderProps) {
|
}: UseArticleLoaderProps) {
|
||||||
|
const location = useLocation()
|
||||||
const mountedRef = useRef(true)
|
const mountedRef = useRef(true)
|
||||||
|
// Hold latest settings without retriggering effect
|
||||||
|
const settingsRef = useRef<UserSettings | undefined>(settings)
|
||||||
|
useEffect(() => {
|
||||||
|
settingsRef.current = settings
|
||||||
|
}, [settings])
|
||||||
|
// Track in-flight request to prevent stale updates from previous naddr
|
||||||
|
const currentRequestIdRef = useRef(0)
|
||||||
|
|
||||||
|
// Extract preview data from navigation state (from blog post cards)
|
||||||
|
const previewData = (location.state as { previewData?: PreviewData })?.previewData
|
||||||
|
|
||||||
|
// Track the current article title for document title
|
||||||
|
const [currentTitle, setCurrentTitle] = useState<string | undefined>()
|
||||||
|
useDocumentTitle({ title: currentTitle })
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
mountedRef.current = true
|
mountedRef.current = true
|
||||||
|
|
||||||
if (!relayPool || !naddr) return
|
// First check: naddr is required
|
||||||
|
if (!naddr) {
|
||||||
|
setReaderContent(undefined)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const loadArticle = async () => {
|
// Clear readerContent immediately to prevent showing stale content from previous article
|
||||||
if (!mountedRef.current) return
|
// This ensures images from previous articles don't flash briefly
|
||||||
|
setReaderContent(undefined)
|
||||||
|
|
||||||
|
// Synchronously check cache sources BEFORE checking relayPool
|
||||||
|
// This prevents showing loading skeletons when content is immediately available
|
||||||
|
// and fixes the race condition where relayPool isn't ready yet
|
||||||
|
let foundInCache = false
|
||||||
|
try {
|
||||||
|
// Check localStorage cache first (synchronous, doesn't need relayPool)
|
||||||
|
const cachedArticle = getFromCache(naddr)
|
||||||
|
if (cachedArticle) {
|
||||||
|
foundInCache = true
|
||||||
|
const title = cachedArticle.title || 'Untitled Article'
|
||||||
|
setCurrentTitle(title)
|
||||||
|
setReaderContent({
|
||||||
|
title,
|
||||||
|
markdown: cachedArticle.markdown,
|
||||||
|
image: cachedArticle.image,
|
||||||
|
summary: cachedArticle.summary,
|
||||||
|
published: cachedArticle.published,
|
||||||
|
url: `nostr:${naddr}`
|
||||||
|
})
|
||||||
|
const dTag = cachedArticle.event.tags.find(t => t[0] === 'd')?.[1] || ''
|
||||||
|
const articleCoordinate = `${cachedArticle.event.kind}:${cachedArticle.author}:${dTag}`
|
||||||
|
setCurrentArticleCoordinate(articleCoordinate)
|
||||||
|
setCurrentArticleEventId(cachedArticle.event.id)
|
||||||
|
setCurrentArticle?.(cachedArticle.event)
|
||||||
|
setReaderLoading(false)
|
||||||
|
setSelectedUrl(`nostr:${naddr}`)
|
||||||
|
setIsCollapsed(true)
|
||||||
|
|
||||||
|
// Preload image if available to ensure it's cached by Service Worker
|
||||||
|
// This ensures images are available when offline
|
||||||
|
if (cachedArticle.image) {
|
||||||
|
preloadImage(cachedArticle.image)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store in EventStore for future lookups
|
||||||
|
if (eventStore) {
|
||||||
|
try {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
eventStore.add?.(cachedArticle.event as unknown as any)
|
||||||
|
} catch {
|
||||||
|
// Silently ignore store errors
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch highlights in background (don't block UI)
|
||||||
|
// Only fetch highlights if relayPool is available
|
||||||
|
if (mountedRef.current && relayPool) {
|
||||||
|
const dTag = cachedArticle.event.tags.find((t: string[]) => t[0] === 'd')?.[1] || ''
|
||||||
|
const coord = dTag ? `${cachedArticle.event.kind}:${cachedArticle.author}:${dTag}` : undefined
|
||||||
|
const eventId = cachedArticle.event.id
|
||||||
|
|
||||||
|
if (coord && eventId) {
|
||||||
|
setHighlightsLoading(true)
|
||||||
|
fetchHighlightsForArticle(
|
||||||
|
relayPool,
|
||||||
|
coord,
|
||||||
|
eventId,
|
||||||
|
(highlight) => {
|
||||||
|
if (!mountedRef.current) return
|
||||||
|
setHighlights((prev: Highlight[]) => {
|
||||||
|
if (prev.some((h: Highlight) => h.id === highlight.id)) return prev
|
||||||
|
const next = [highlight, ...prev]
|
||||||
|
return next.sort((a, b) => b.created_at - a.created_at)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
settings,
|
||||||
|
false,
|
||||||
|
eventStore || undefined
|
||||||
|
).then(() => {
|
||||||
|
if (mountedRef.current) {
|
||||||
|
setHighlightsLoading(false)
|
||||||
|
}
|
||||||
|
}).catch(() => {
|
||||||
|
if (mountedRef.current) {
|
||||||
|
setHighlightsLoading(false)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return early - we have cached content, no need to query relays
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
// If cache check fails, fall through to async loading
|
||||||
|
console.warn('[article-loader] Cache check failed:', err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check EventStore synchronously (also doesn't need relayPool)
|
||||||
|
let foundInEventStore = false
|
||||||
|
if (eventStore && !foundInCache) {
|
||||||
|
try {
|
||||||
|
// Decode naddr to get the coordinate
|
||||||
|
const decoded = nip19.decode(naddr)
|
||||||
|
if (decoded.type === 'naddr') {
|
||||||
|
const pointer = decoded.data as AddressPointer
|
||||||
|
const coordinate = `${pointer.kind}:${pointer.pubkey}:${pointer.identifier}`
|
||||||
|
const storedEvent = eventStore.getEvent?.(coordinate)
|
||||||
|
if (storedEvent) {
|
||||||
|
foundInEventStore = true
|
||||||
|
const title = Helpers.getArticleTitle(storedEvent) || 'Untitled Article'
|
||||||
|
setCurrentTitle(title)
|
||||||
|
const image = Helpers.getArticleImage(storedEvent)
|
||||||
|
const summary = Helpers.getArticleSummary(storedEvent)
|
||||||
|
const published = Helpers.getArticlePublished(storedEvent)
|
||||||
|
setReaderContent({
|
||||||
|
title,
|
||||||
|
markdown: storedEvent.content,
|
||||||
|
image,
|
||||||
|
summary,
|
||||||
|
published,
|
||||||
|
url: `nostr:${naddr}`
|
||||||
|
})
|
||||||
|
const dTag = storedEvent.tags.find(t => t[0] === 'd')?.[1] || ''
|
||||||
|
const articleCoordinate = `${storedEvent.kind}:${storedEvent.pubkey}:${dTag}`
|
||||||
|
setCurrentArticleCoordinate(articleCoordinate)
|
||||||
|
setCurrentArticleEventId(storedEvent.id)
|
||||||
|
setCurrentArticle?.(storedEvent)
|
||||||
|
setReaderLoading(false)
|
||||||
|
setSelectedUrl(`nostr:${naddr}`)
|
||||||
|
setIsCollapsed(true)
|
||||||
|
|
||||||
|
// Fetch highlights in background if relayPool is available
|
||||||
|
if (relayPool) {
|
||||||
|
const coord = dTag ? `${storedEvent.kind}:${storedEvent.pubkey}:${dTag}` : undefined
|
||||||
|
const eventId = storedEvent.id
|
||||||
|
|
||||||
|
if (coord && eventId) {
|
||||||
|
setHighlightsLoading(true)
|
||||||
|
fetchHighlightsForArticle(
|
||||||
|
relayPool,
|
||||||
|
coord,
|
||||||
|
eventId,
|
||||||
|
(highlight) => {
|
||||||
|
if (!mountedRef.current) return
|
||||||
|
setHighlights((prev: Highlight[]) => {
|
||||||
|
if (prev.some((h: Highlight) => h.id === highlight.id)) return prev
|
||||||
|
const next = [highlight, ...prev]
|
||||||
|
return next.sort((a, b) => b.created_at - a.created_at)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
settings,
|
||||||
|
false,
|
||||||
|
eventStore || undefined
|
||||||
|
).then(() => {
|
||||||
|
if (mountedRef.current) {
|
||||||
|
setHighlightsLoading(false)
|
||||||
|
}
|
||||||
|
}).catch(() => {
|
||||||
|
if (mountedRef.current) {
|
||||||
|
setHighlightsLoading(false)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return early - we have EventStore content, no need to query relays yet
|
||||||
|
// But we might want to fetch from relays in background if relayPool becomes available
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
// Ignore store errors, fall through to relay query
|
||||||
|
console.warn('[article-loader] EventStore check failed:', err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only return early if we have no content AND no relayPool to fetch from
|
||||||
|
if (!relayPool && !foundInCache && !foundInEventStore) {
|
||||||
setReaderLoading(true)
|
setReaderLoading(true)
|
||||||
setReaderContent(undefined)
|
setReaderContent(undefined)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we have relayPool, proceed with async loading
|
||||||
|
if (!relayPool) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const loadArticle = async () => {
|
||||||
|
const requestId = ++currentRequestIdRef.current
|
||||||
|
|
||||||
|
if (!mountedRef.current) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
setSelectedUrl(`nostr:${naddr}`)
|
setSelectedUrl(`nostr:${naddr}`)
|
||||||
setIsCollapsed(true)
|
setIsCollapsed(true)
|
||||||
|
|
||||||
try {
|
// Don't clear highlights yet - let the smart filtering logic handle it
|
||||||
const article = await fetchArticleByNaddr(relayPool, naddr, false, settings)
|
// when we know the article coordinate
|
||||||
|
setHighlightsLoading(false) // Don't show loading yet
|
||||||
if (!mountedRef.current) return
|
|
||||||
|
// Note: Cache and EventStore were already checked synchronously above
|
||||||
|
// This async function only runs if we need to fetch from relays
|
||||||
|
|
||||||
|
// At this point, we've checked EventStore and cache - neither had content
|
||||||
|
// Only show loading skeleton if we also don't have preview data
|
||||||
|
if (previewData) {
|
||||||
|
// If we have preview data from navigation, show it immediately (no skeleton!)
|
||||||
|
setCurrentTitle(previewData.title)
|
||||||
setReaderContent({
|
setReaderContent({
|
||||||
title: article.title,
|
title: previewData.title,
|
||||||
markdown: article.markdown,
|
markdown: '', // Will be loaded from relay
|
||||||
image: article.image,
|
image: previewData.image,
|
||||||
summary: article.summary,
|
summary: previewData.summary,
|
||||||
published: article.published,
|
published: previewData.published,
|
||||||
url: `nostr:${naddr}`
|
url: `nostr:${naddr}`
|
||||||
})
|
})
|
||||||
|
setReaderLoading(false) // Turn off loading immediately - we have the preview!
|
||||||
|
|
||||||
const dTag = article.event.tags.find(t => t[0] === 'd')?.[1] || ''
|
// Don't preload image here - it should already be cached from BlogPostCard
|
||||||
const articleCoordinate = `${article.event.kind}:${article.author}:${dTag}`
|
// Preloading again would be redundant and could cause unnecessary network requests
|
||||||
|
} else {
|
||||||
setCurrentArticleCoordinate(articleCoordinate)
|
// No cache, no EventStore, no preview data - need to load from relays
|
||||||
setCurrentArticleEventId(article.event.id)
|
setReaderLoading(true)
|
||||||
setCurrentArticle?.(article.event)
|
setReaderContent(undefined)
|
||||||
setReaderLoading(false)
|
}
|
||||||
|
|
||||||
// Fetch highlights asynchronously without blocking article display
|
try {
|
||||||
|
// Decode naddr to filter
|
||||||
|
const decoded = nip19.decode(naddr)
|
||||||
|
if (decoded.type !== 'naddr') {
|
||||||
|
throw new Error('Invalid naddr format')
|
||||||
|
}
|
||||||
|
const pointer = decoded.data as AddressPointer
|
||||||
|
const filter = {
|
||||||
|
kinds: [pointer.kind],
|
||||||
|
authors: [pointer.pubkey],
|
||||||
|
'#d': [pointer.identifier]
|
||||||
|
}
|
||||||
|
|
||||||
|
let firstEmitted = false
|
||||||
|
let latestEvent: NostrEvent | null = null
|
||||||
|
|
||||||
|
// Stream local-first via queryEvents; rely on EOSE (no timeouts)
|
||||||
|
const events = await queryEvents(relayPool, filter, {
|
||||||
|
onEvent: (evt) => {
|
||||||
|
if (!mountedRef.current) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (currentRequestIdRef.current !== requestId) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store in event store for future local reads
|
||||||
|
try {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
eventStore?.add?.(evt as unknown as any)
|
||||||
|
} catch {
|
||||||
|
// Silently ignore store errors
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keep latest by created_at
|
||||||
|
if (!latestEvent || evt.created_at > latestEvent.created_at) {
|
||||||
|
latestEvent = evt
|
||||||
|
}
|
||||||
|
|
||||||
|
// Emit immediately on first event
|
||||||
|
if (!firstEmitted) {
|
||||||
|
firstEmitted = true
|
||||||
|
const title = Helpers.getArticleTitle(evt) || 'Untitled Article'
|
||||||
|
const image = Helpers.getArticleImage(evt)
|
||||||
|
const summary = Helpers.getArticleSummary(evt)
|
||||||
|
const published = Helpers.getArticlePublished(evt)
|
||||||
|
|
||||||
|
setCurrentTitle(title)
|
||||||
|
setReaderContent({
|
||||||
|
title,
|
||||||
|
markdown: evt.content,
|
||||||
|
image,
|
||||||
|
summary,
|
||||||
|
published,
|
||||||
|
url: `nostr:${naddr}`
|
||||||
|
})
|
||||||
|
const dTag = evt.tags.find(t => t[0] === 'd')?.[1] || ''
|
||||||
|
const articleCoordinate = `${evt.kind}:${evt.pubkey}:${dTag}`
|
||||||
|
setCurrentArticleCoordinate(articleCoordinate)
|
||||||
|
setCurrentArticleEventId(evt.id)
|
||||||
|
setCurrentArticle?.(evt)
|
||||||
|
setReaderLoading(false)
|
||||||
|
|
||||||
|
// Save to cache immediately when we get the first event
|
||||||
|
// Don't wait for queryEvents to complete in case it hangs
|
||||||
|
const articleContent = {
|
||||||
|
title,
|
||||||
|
markdown: evt.content,
|
||||||
|
image,
|
||||||
|
summary,
|
||||||
|
published,
|
||||||
|
author: evt.pubkey,
|
||||||
|
event: evt
|
||||||
|
}
|
||||||
|
saveToCache(naddr, articleContent, settings)
|
||||||
|
|
||||||
|
// Preload image to ensure it's cached by Service Worker
|
||||||
|
if (image) {
|
||||||
|
preloadImage(image)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!mountedRef.current || currentRequestIdRef.current !== requestId) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finalize with newest version if it's newer than what we first rendered
|
||||||
|
const finalEvent = (events.sort((a, b) => b.created_at - a.created_at)[0]) || latestEvent
|
||||||
|
if (finalEvent) {
|
||||||
|
const title = Helpers.getArticleTitle(finalEvent) || 'Untitled Article'
|
||||||
|
const image = Helpers.getArticleImage(finalEvent)
|
||||||
|
const summary = Helpers.getArticleSummary(finalEvent)
|
||||||
|
const published = Helpers.getArticlePublished(finalEvent)
|
||||||
|
|
||||||
|
setCurrentTitle(title)
|
||||||
|
setReaderContent({
|
||||||
|
title,
|
||||||
|
markdown: finalEvent.content,
|
||||||
|
image,
|
||||||
|
summary,
|
||||||
|
published,
|
||||||
|
url: `nostr:${naddr}`
|
||||||
|
})
|
||||||
|
|
||||||
|
const dTag = finalEvent.tags.find(t => t[0] === 'd')?.[1] || ''
|
||||||
|
const articleCoordinate = `${finalEvent.kind}:${finalEvent.pubkey}:${dTag}`
|
||||||
|
setCurrentArticleCoordinate(articleCoordinate)
|
||||||
|
setCurrentArticleEventId(finalEvent.id)
|
||||||
|
setCurrentArticle?.(finalEvent)
|
||||||
|
|
||||||
|
// Save to cache for future loads (if we haven't already saved from first event)
|
||||||
|
// Only save if this is a different/newer event than what we first rendered
|
||||||
|
// Note: We already saved from first event, so only save if this is different
|
||||||
|
if (!firstEmitted) {
|
||||||
|
// First event wasn't emitted, so save now
|
||||||
|
const articleContent = {
|
||||||
|
title,
|
||||||
|
markdown: finalEvent.content,
|
||||||
|
image,
|
||||||
|
summary,
|
||||||
|
published,
|
||||||
|
author: finalEvent.pubkey,
|
||||||
|
event: finalEvent
|
||||||
|
}
|
||||||
|
saveToCache(naddr, articleContent)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// As a last resort, fall back to the legacy helper (which includes cache)
|
||||||
|
const article = await fetchArticleByNaddr(relayPool, naddr, false, settingsRef.current)
|
||||||
|
if (!mountedRef.current || currentRequestIdRef.current !== requestId) return
|
||||||
|
setCurrentTitle(article.title)
|
||||||
|
setReaderContent({
|
||||||
|
title: article.title,
|
||||||
|
markdown: article.markdown,
|
||||||
|
image: article.image,
|
||||||
|
summary: article.summary,
|
||||||
|
published: article.published,
|
||||||
|
url: `nostr:${naddr}`
|
||||||
|
})
|
||||||
|
const dTag = article.event.tags.find(t => t[0] === 'd')?.[1] || ''
|
||||||
|
const articleCoordinate = `${article.event.kind}:${article.author}:${dTag}`
|
||||||
|
setCurrentArticleCoordinate(articleCoordinate)
|
||||||
|
setCurrentArticleEventId(article.event.id)
|
||||||
|
setCurrentArticle?.(article.event)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch highlights after content is shown
|
||||||
try {
|
try {
|
||||||
if (!mountedRef.current) return
|
if (!mountedRef.current) return
|
||||||
|
|
||||||
setHighlightsLoading(true)
|
const le = latestEvent as NostrEvent | null
|
||||||
setHighlights([])
|
const dTag = le ? (le.tags.find((t: string[]) => t[0] === 'd')?.[1] || '') : ''
|
||||||
|
const coord = le && dTag ? `${le.kind}:${le.pubkey}:${dTag}` : undefined
|
||||||
|
const eventId = le ? le.id : undefined
|
||||||
|
|
||||||
await fetchHighlightsForArticle(
|
if (coord && eventId) {
|
||||||
relayPool,
|
setHighlightsLoading(true)
|
||||||
articleCoordinate,
|
// Clear highlights that don't belong to this article coordinate
|
||||||
article.event.id,
|
setHighlights((prev) => {
|
||||||
(highlight) => {
|
return prev.filter(h => {
|
||||||
if (!mountedRef.current) return
|
// Keep highlights that match this article coordinate or event ID
|
||||||
|
return h.eventReference === coord || h.eventReference === eventId
|
||||||
setHighlights((prev: Highlight[]) => {
|
|
||||||
if (prev.some((h: Highlight) => h.id === highlight.id)) return prev
|
|
||||||
const next = [highlight, ...prev]
|
|
||||||
return next.sort((a, b) => b.created_at - a.created_at)
|
|
||||||
})
|
})
|
||||||
},
|
})
|
||||||
settings
|
await fetchHighlightsForArticle(
|
||||||
)
|
relayPool,
|
||||||
|
coord,
|
||||||
|
eventId,
|
||||||
|
(highlight) => {
|
||||||
|
if (!mountedRef.current) return
|
||||||
|
if (currentRequestIdRef.current !== requestId) return
|
||||||
|
setHighlights((prev: Highlight[]) => {
|
||||||
|
if (prev.some((h: Highlight) => h.id === highlight.id)) return prev
|
||||||
|
const next = [highlight, ...prev]
|
||||||
|
return next.sort((a, b) => b.created_at - a.created_at)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
settingsRef.current,
|
||||||
|
false, // force
|
||||||
|
eventStore || undefined
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
// No article event to fetch highlights for - clear and don't show loading
|
||||||
|
setHighlights([])
|
||||||
|
setHighlightsLoading(false)
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to fetch highlights:', err)
|
console.error('Failed to fetch highlights:', err)
|
||||||
} finally {
|
} finally {
|
||||||
if (mountedRef.current) {
|
if (mountedRef.current && currentRequestIdRef.current === requestId) {
|
||||||
setHighlightsLoading(false)
|
setHighlightsLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to load article:', err)
|
console.error('Failed to load article:', err)
|
||||||
if (mountedRef.current) {
|
if (mountedRef.current && currentRequestIdRef.current === requestId) {
|
||||||
setReaderContent({
|
setReaderContent({
|
||||||
title: 'Error Loading Article',
|
title: 'Error Loading Article',
|
||||||
html: `<p>Failed to load article: ${err instanceof Error ? err.message : 'Unknown error'}</p>`,
|
html: `<p>Failed to load article: ${err instanceof Error ? err.message : 'Unknown error'}</p>`,
|
||||||
@@ -120,18 +515,13 @@ export function useArticleLoader({
|
|||||||
return () => {
|
return () => {
|
||||||
mountedRef.current = false
|
mountedRef.current = false
|
||||||
}
|
}
|
||||||
|
// Include relayPool in dependencies so effect re-runs when it becomes available
|
||||||
|
// This fixes the race condition where articles don't load on direct navigation
|
||||||
|
// We guard against unnecessary re-renders by checking cache/EventStore first
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [
|
}, [
|
||||||
naddr,
|
naddr,
|
||||||
relayPool,
|
previewData,
|
||||||
settings,
|
relayPool
|
||||||
setSelectedUrl,
|
|
||||||
setReaderContent,
|
|
||||||
setReaderLoading,
|
|
||||||
setIsCollapsed,
|
|
||||||
setHighlights,
|
|
||||||
setHighlightsLoading,
|
|
||||||
setCurrentArticleCoordinate,
|
|
||||||
setCurrentArticleEventId,
|
|
||||||
setCurrentArticle
|
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,7 +158,10 @@ export const useBookmarksData = ({
|
|||||||
|
|
||||||
// Fetch article-specific highlights when viewing an article
|
// Fetch article-specific highlights when viewing an article
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!relayPool || !activeAccount) return
|
if (!relayPool || !activeAccount) {
|
||||||
|
setHighlightsLoading(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
// Fetch article-specific highlights when viewing an article
|
// Fetch article-specific highlights when viewing an article
|
||||||
// External URLs have their highlights fetched by useExternalUrlLoader
|
// External URLs have their highlights fetched by useExternalUrlLoader
|
||||||
if (effectiveArticleCoordinate && !externalUrl) {
|
if (effectiveArticleCoordinate && !externalUrl) {
|
||||||
@@ -167,6 +170,9 @@ export const useBookmarksData = ({
|
|||||||
// Clear article highlights when not viewing an article
|
// Clear article highlights when not viewing an article
|
||||||
setArticleHighlights([])
|
setArticleHighlights([])
|
||||||
setHighlightsLoading(false)
|
setHighlightsLoading(false)
|
||||||
|
} else {
|
||||||
|
// For external URLs or other cases, loading is not needed
|
||||||
|
setHighlightsLoading(false)
|
||||||
}
|
}
|
||||||
}, [relayPool, activeAccount, effectiveArticleCoordinate, naddr, externalUrl, handleFetchHighlights])
|
}, [relayPool, activeAccount, effectiveArticleCoordinate, naddr, externalUrl, handleFetchHighlights])
|
||||||
|
|
||||||
|
|||||||
35
src/hooks/useDocumentTitle.ts
Normal file
35
src/hooks/useDocumentTitle.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import { useEffect, useRef } from 'react'
|
||||||
|
|
||||||
|
const DEFAULT_TITLE = 'Boris - Read, Highlight, Explore'
|
||||||
|
|
||||||
|
interface UseDocumentTitleProps {
|
||||||
|
title?: string
|
||||||
|
fallback?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useDocumentTitle({ title, fallback }: UseDocumentTitleProps) {
|
||||||
|
const originalTitleRef = useRef<string>(document.title)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Store the original title on first mount
|
||||||
|
if (originalTitleRef.current === DEFAULT_TITLE) {
|
||||||
|
originalTitleRef.current = document.title
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the new title if provided, otherwise use fallback or default
|
||||||
|
const newTitle = title || fallback || DEFAULT_TITLE
|
||||||
|
document.title = newTitle
|
||||||
|
|
||||||
|
// Cleanup: restore original title when component unmounts
|
||||||
|
return () => {
|
||||||
|
document.title = originalTitleRef.current
|
||||||
|
}
|
||||||
|
}, [title, fallback])
|
||||||
|
|
||||||
|
// Return a function to manually reset to default
|
||||||
|
const resetTitle = () => {
|
||||||
|
document.title = DEFAULT_TITLE
|
||||||
|
}
|
||||||
|
|
||||||
|
return { resetTitle }
|
||||||
|
}
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
import { useEffect, useCallback } from 'react'
|
import { useEffect, useCallback, useState } from 'react'
|
||||||
import { RelayPool } from 'applesauce-relay'
|
import { RelayPool } from 'applesauce-relay'
|
||||||
import { IEventStore } from 'applesauce-core'
|
import { IEventStore } from 'applesauce-core'
|
||||||
import { NostrEvent } from 'nostr-tools'
|
import { NostrEvent } from 'nostr-tools'
|
||||||
import { ReadableContent } from '../services/readerService'
|
import { ReadableContent } from '../services/readerService'
|
||||||
import { eventManager } from '../services/eventManager'
|
import { eventManager } from '../services/eventManager'
|
||||||
import { fetchProfiles } from '../services/profileService'
|
import { fetchProfiles } from '../services/profileService'
|
||||||
|
import { useDocumentTitle } from './useDocumentTitle'
|
||||||
|
import { getNpubFallbackDisplay } from '../utils/nostrUriResolver'
|
||||||
|
import { extractProfileDisplayName } from '../utils/profileUtils'
|
||||||
|
|
||||||
interface UseEventLoaderProps {
|
interface UseEventLoaderProps {
|
||||||
eventId?: string
|
eventId?: string
|
||||||
@@ -25,6 +28,9 @@ export function useEventLoader({
|
|||||||
setReaderLoading,
|
setReaderLoading,
|
||||||
setIsCollapsed
|
setIsCollapsed
|
||||||
}: UseEventLoaderProps) {
|
}: UseEventLoaderProps) {
|
||||||
|
// Track the current event title for document title
|
||||||
|
const [currentTitle, setCurrentTitle] = useState<string | undefined>()
|
||||||
|
useDocumentTitle({ title: currentTitle })
|
||||||
const displayEvent = useCallback((event: NostrEvent) => {
|
const displayEvent = useCallback((event: NostrEvent) => {
|
||||||
// Escape HTML in content and convert newlines to breaks for plain text display
|
// Escape HTML in content and convert newlines to breaks for plain text display
|
||||||
const escapedContent = event.content
|
const escapedContent = event.content
|
||||||
@@ -36,7 +42,7 @@ export function useEventLoader({
|
|||||||
// Initial title
|
// Initial title
|
||||||
let title = `Note (${event.kind})`
|
let title = `Note (${event.kind})`
|
||||||
if (event.kind === 1) {
|
if (event.kind === 1) {
|
||||||
title = `Note by @${event.pubkey.slice(0, 8)}...`
|
title = `Note by ${getNpubFallbackDisplay(event.pubkey)}`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit immediately
|
// Emit immediately
|
||||||
@@ -46,6 +52,7 @@ export function useEventLoader({
|
|||||||
title,
|
title,
|
||||||
published: event.created_at
|
published: event.created_at
|
||||||
}
|
}
|
||||||
|
setCurrentTitle(title)
|
||||||
setReaderContent(baseContent)
|
setReaderContent(baseContent)
|
||||||
|
|
||||||
// Background: resolve author profile for kind:1 and update title
|
// Background: resolve author profile for kind:1 and update title
|
||||||
@@ -57,11 +64,12 @@ export function useEventLoader({
|
|||||||
// First, try to get from event store cache
|
// First, try to get from event store cache
|
||||||
const storedProfile = eventStore.getEvent(event.pubkey + ':0')
|
const storedProfile = eventStore.getEvent(event.pubkey + ':0')
|
||||||
if (storedProfile) {
|
if (storedProfile) {
|
||||||
try {
|
const displayName = extractProfileDisplayName(storedProfile as NostrEvent)
|
||||||
const obj = JSON.parse(storedProfile.content || '{}') as { name?: string; display_name?: string; nip05?: string }
|
if (displayName && !displayName.startsWith('@')) {
|
||||||
resolved = obj.display_name || obj.name || obj.nip05 || ''
|
// Remove @ prefix if present (we'll add it when displaying)
|
||||||
} catch {
|
resolved = displayName
|
||||||
// ignore parse errors
|
} else if (displayName) {
|
||||||
|
resolved = displayName.substring(1) // Remove @ prefix
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,17 +78,19 @@ export function useEventLoader({
|
|||||||
const profiles = await fetchProfiles(relayPool, eventStore as unknown as IEventStore, [event.pubkey])
|
const profiles = await fetchProfiles(relayPool, eventStore as unknown as IEventStore, [event.pubkey])
|
||||||
if (profiles && profiles.length > 0) {
|
if (profiles && profiles.length > 0) {
|
||||||
const latest = profiles.sort((a, b) => (b.created_at || 0) - (a.created_at || 0))[0]
|
const latest = profiles.sort((a, b) => (b.created_at || 0) - (a.created_at || 0))[0]
|
||||||
try {
|
const displayName = extractProfileDisplayName(latest)
|
||||||
const obj = JSON.parse(latest.content || '{}') as { name?: string; display_name?: string; nip05?: string }
|
if (displayName && !displayName.startsWith('@')) {
|
||||||
resolved = obj.display_name || obj.name || obj.nip05 || ''
|
resolved = displayName
|
||||||
} catch {
|
} else if (displayName) {
|
||||||
// ignore parse errors
|
resolved = displayName.substring(1) // Remove @ prefix
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resolved) {
|
if (resolved) {
|
||||||
setReaderContent({ ...baseContent, title: `Note by @${resolved}` })
|
const updatedTitle = `Note by @${resolved}`
|
||||||
|
setCurrentTitle(updatedTitle)
|
||||||
|
setReaderContent({ ...baseContent, title: updatedTitle })
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// ignore profile failures; keep fallback title
|
// ignore profile failures; keep fallback title
|
||||||
@@ -119,6 +129,7 @@ export function useEventLoader({
|
|||||||
html: `<div style="padding: 1rem; color: var(--color-error, red);">Failed to load event: ${err instanceof Error ? err.message : 'Unknown error'}</div>`,
|
html: `<div style="padding: 1rem; color: var(--color-error, red);">Failed to load event: ${err instanceof Error ? err.message : 'Unknown error'}</div>`,
|
||||||
title: 'Error'
|
title: 'Error'
|
||||||
}
|
}
|
||||||
|
setCurrentTitle('Error')
|
||||||
setReaderContent(errorContent)
|
setReaderContent(errorContent)
|
||||||
setReaderLoading(false)
|
setReaderLoading(false)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useRef, useMemo } from 'react'
|
import { useEffect, useRef, useMemo, useState } from 'react'
|
||||||
import { RelayPool } from 'applesauce-relay'
|
import { RelayPool } from 'applesauce-relay'
|
||||||
import { IEventStore } from 'applesauce-core'
|
import { IEventStore } from 'applesauce-core'
|
||||||
import { fetchReadableContent, ReadableContent } from '../services/readerService'
|
import { fetchReadableContent, ReadableContent } from '../services/readerService'
|
||||||
@@ -7,6 +7,7 @@ import { Highlight } from '../types/highlights'
|
|||||||
import { useStoreTimeline } from './useStoreTimeline'
|
import { useStoreTimeline } from './useStoreTimeline'
|
||||||
import { eventToHighlight } from '../services/highlightEventProcessor'
|
import { eventToHighlight } from '../services/highlightEventProcessor'
|
||||||
import { KINDS } from '../config/kinds'
|
import { KINDS } from '../config/kinds'
|
||||||
|
import { useDocumentTitle } from './useDocumentTitle'
|
||||||
|
|
||||||
// Helper to extract filename from URL
|
// Helper to extract filename from URL
|
||||||
function getFilenameFromUrl(url: string): string {
|
function getFilenameFromUrl(url: string): string {
|
||||||
@@ -49,6 +50,12 @@ export function useExternalUrlLoader({
|
|||||||
setCurrentArticleEventId
|
setCurrentArticleEventId
|
||||||
}: UseExternalUrlLoaderProps) {
|
}: UseExternalUrlLoaderProps) {
|
||||||
const mountedRef = useRef(true)
|
const mountedRef = useRef(true)
|
||||||
|
// Track in-flight request to prevent stale updates when switching quickly
|
||||||
|
const currentRequestIdRef = useRef(0)
|
||||||
|
|
||||||
|
// Track the current content title for document title
|
||||||
|
const [currentTitle, setCurrentTitle] = useState<string | undefined>()
|
||||||
|
useDocumentTitle({ title: currentTitle })
|
||||||
|
|
||||||
// Load cached URL-specific highlights from event store
|
// Load cached URL-specific highlights from event store
|
||||||
const urlFilter = useMemo(() => {
|
const urlFilter = useMemo(() => {
|
||||||
@@ -70,6 +77,7 @@ export function useExternalUrlLoader({
|
|||||||
if (!relayPool || !url) return
|
if (!relayPool || !url) return
|
||||||
|
|
||||||
const loadExternalUrl = async () => {
|
const loadExternalUrl = async () => {
|
||||||
|
const requestId = ++currentRequestIdRef.current
|
||||||
if (!mountedRef.current) return
|
if (!mountedRef.current) return
|
||||||
|
|
||||||
setReaderLoading(true)
|
setReaderLoading(true)
|
||||||
@@ -83,7 +91,9 @@ export function useExternalUrlLoader({
|
|||||||
const content = await fetchReadableContent(url)
|
const content = await fetchReadableContent(url)
|
||||||
|
|
||||||
if (!mountedRef.current) return
|
if (!mountedRef.current) return
|
||||||
|
if (currentRequestIdRef.current !== requestId) return
|
||||||
|
|
||||||
|
setCurrentTitle(content.title)
|
||||||
setReaderContent(content)
|
setReaderContent(content)
|
||||||
setReaderLoading(false)
|
setReaderLoading(false)
|
||||||
|
|
||||||
@@ -114,6 +124,7 @@ export function useExternalUrlLoader({
|
|||||||
url,
|
url,
|
||||||
(highlight) => {
|
(highlight) => {
|
||||||
if (!mountedRef.current) return
|
if (!mountedRef.current) return
|
||||||
|
if (currentRequestIdRef.current !== requestId) return
|
||||||
|
|
||||||
if (seen.has(highlight.id)) return
|
if (seen.has(highlight.id)) return
|
||||||
seen.add(highlight.id)
|
seen.add(highlight.id)
|
||||||
@@ -131,13 +142,13 @@ export function useExternalUrlLoader({
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to fetch highlights:', err)
|
console.error('Failed to fetch highlights:', err)
|
||||||
} finally {
|
} finally {
|
||||||
if (mountedRef.current) {
|
if (mountedRef.current && currentRequestIdRef.current === requestId) {
|
||||||
setHighlightsLoading(false)
|
setHighlightsLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to load external URL:', err)
|
console.error('Failed to load external URL:', err)
|
||||||
if (mountedRef.current) {
|
if (mountedRef.current && currentRequestIdRef.current === requestId) {
|
||||||
const filename = getFilenameFromUrl(url)
|
const filename = getFilenameFromUrl(url)
|
||||||
setReaderContent({
|
setReaderContent({
|
||||||
title: filename,
|
title: filename,
|
||||||
@@ -154,19 +165,12 @@ export function useExternalUrlLoader({
|
|||||||
return () => {
|
return () => {
|
||||||
mountedRef.current = false
|
mountedRef.current = false
|
||||||
}
|
}
|
||||||
|
// Dependencies intentionally excluded to prevent re-renders when relay/eventStore state changes
|
||||||
|
// This fixes the loading skeleton appearing when going offline (flight mode)
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [
|
}, [
|
||||||
url,
|
url,
|
||||||
relayPool,
|
cachedUrlHighlights
|
||||||
eventStore,
|
|
||||||
cachedUrlHighlights,
|
|
||||||
setReaderContent,
|
|
||||||
setReaderLoading,
|
|
||||||
setIsCollapsed,
|
|
||||||
setSelectedUrl,
|
|
||||||
setHighlights,
|
|
||||||
setCurrentArticleCoordinate,
|
|
||||||
setCurrentArticleEventId,
|
|
||||||
setHighlightsLoading
|
|
||||||
])
|
])
|
||||||
|
|
||||||
// Keep UI highlights synced with cached store updates without reloading content
|
// Keep UI highlights synced with cached store updates without reloading content
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Highlight } from '../types/highlights'
|
|||||||
import { HighlightVisibility } from '../components/HighlightsPanel'
|
import { HighlightVisibility } from '../components/HighlightsPanel'
|
||||||
import { normalizeUrl } from '../utils/urlHelpers'
|
import { normalizeUrl } from '../utils/urlHelpers'
|
||||||
import { classifyHighlights } from '../utils/highlightClassification'
|
import { classifyHighlights } from '../utils/highlightClassification'
|
||||||
|
import { nip19 } from 'nostr-tools'
|
||||||
|
|
||||||
interface UseFilteredHighlightsParams {
|
interface UseFilteredHighlightsParams {
|
||||||
highlights: Highlight[]
|
highlights: Highlight[]
|
||||||
@@ -24,8 +25,29 @@ export const useFilteredHighlights = ({
|
|||||||
|
|
||||||
let urlFiltered = highlights
|
let urlFiltered = highlights
|
||||||
|
|
||||||
// For Nostr articles, we already fetched highlights specifically for this article
|
// Filter highlights based on URL type
|
||||||
if (!selectedUrl.startsWith('nostr:')) {
|
if (selectedUrl.startsWith('nostr:')) {
|
||||||
|
// For Nostr articles, extract the article coordinate and filter by eventReference
|
||||||
|
try {
|
||||||
|
const decoded = nip19.decode(selectedUrl.replace('nostr:', ''))
|
||||||
|
if (decoded.type === 'naddr') {
|
||||||
|
const ptr = decoded.data as { kind: number; pubkey: string; identifier: string }
|
||||||
|
const articleCoordinate = `${ptr.kind}:${ptr.pubkey}:${ptr.identifier}`
|
||||||
|
|
||||||
|
urlFiltered = highlights.filter(h => {
|
||||||
|
// Keep highlights that match this article coordinate
|
||||||
|
return h.eventReference === articleCoordinate
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// Not a valid naddr, clear all highlights
|
||||||
|
urlFiltered = []
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Invalid naddr, clear all highlights
|
||||||
|
urlFiltered = []
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// For web URLs, filter by URL matching
|
||||||
const normalizedSelected = normalizeUrl(selectedUrl)
|
const normalizedSelected = normalizeUrl(selectedUrl)
|
||||||
|
|
||||||
urlFiltered = highlights.filter(h => {
|
urlFiltered = highlights.filter(h => {
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ export const useHighlightCreation = ({
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const handleCreateHighlight = useCallback(async (text: string) => {
|
const handleCreateHighlight = useCallback(async (text: string) => {
|
||||||
|
|
||||||
if (!activeAccount || !relayPool || !eventStore) {
|
if (!activeAccount || !relayPool || !eventStore) {
|
||||||
console.error('Missing requirements for highlight creation')
|
console.error('Missing requirements for highlight creation')
|
||||||
return
|
return
|
||||||
@@ -60,7 +61,6 @@ export const useHighlightCreation = ({
|
|||||||
? currentArticle.content
|
? currentArticle.content
|
||||||
: readerContent?.markdown || readerContent?.html
|
: readerContent?.markdown || readerContent?.html
|
||||||
|
|
||||||
|
|
||||||
const newHighlight = await createHighlight(
|
const newHighlight = await createHighlight(
|
||||||
text,
|
text,
|
||||||
source,
|
source,
|
||||||
@@ -73,7 +73,6 @@ export const useHighlightCreation = ({
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Highlight created successfully
|
// Highlight created successfully
|
||||||
|
|
||||||
// Clear the browser's text selection immediately to allow DOM update
|
// Clear the browser's text selection immediately to allow DOM update
|
||||||
const selection = window.getSelection()
|
const selection = window.getSelection()
|
||||||
if (selection) {
|
if (selection) {
|
||||||
|
|||||||
@@ -93,26 +93,37 @@ export const useHighlightInteractions = ({
|
|||||||
return () => clearTimeout(timeoutId)
|
return () => clearTimeout(timeoutId)
|
||||||
}, [selectedHighlightId, contentVersion])
|
}, [selectedHighlightId, contentVersion])
|
||||||
|
|
||||||
// Handle text selection (works for both mouse and touch)
|
// Shared function to check and handle text selection
|
||||||
const handleSelectionEnd = useCallback(() => {
|
const checkSelection = useCallback(() => {
|
||||||
setTimeout(() => {
|
const selection = window.getSelection()
|
||||||
const selection = window.getSelection()
|
if (!selection || selection.rangeCount === 0) {
|
||||||
if (!selection || selection.rangeCount === 0) {
|
onClearSelection?.()
|
||||||
onClearSelection?.()
|
return
|
||||||
return
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const range = selection.getRangeAt(0)
|
const range = selection.getRangeAt(0)
|
||||||
const text = selection.toString().trim()
|
const text = selection.toString().trim()
|
||||||
|
|
||||||
if (text.length > 0 && contentRef.current?.contains(range.commonAncestorContainer)) {
|
if (text.length > 0 && contentRef.current?.contains(range.commonAncestorContainer)) {
|
||||||
onTextSelection?.(text)
|
onTextSelection?.(text)
|
||||||
} else {
|
} else {
|
||||||
onClearSelection?.()
|
onClearSelection?.()
|
||||||
}
|
}
|
||||||
}, 10)
|
|
||||||
}, [onTextSelection, onClearSelection])
|
}, [onTextSelection, onClearSelection])
|
||||||
|
|
||||||
return { contentRef, handleSelectionEnd }
|
// Listen to selectionchange events for immediate detection (works reliably on mobile)
|
||||||
|
useEffect(() => {
|
||||||
|
const handleSelectionChange = () => {
|
||||||
|
// Use requestAnimationFrame to ensure selection is checked after browser updates
|
||||||
|
requestAnimationFrame(checkSelection)
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('selectionchange', handleSelectionChange)
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('selectionchange', handleSelectionChange)
|
||||||
|
}
|
||||||
|
}, [checkSelection])
|
||||||
|
|
||||||
|
return { contentRef }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ export function useImageCache(
|
|||||||
imageUrl: string | undefined
|
imageUrl: string | undefined
|
||||||
): string | undefined {
|
): string | undefined {
|
||||||
// Service Worker handles everything - just return the URL as-is
|
// Service Worker handles everything - just return the URL as-is
|
||||||
|
// The Service Worker will intercept fetch requests and cache them
|
||||||
|
// Make sure images use standard <img src> tags for SW interception
|
||||||
return imageUrl
|
return imageUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,3 +28,26 @@ export function useCacheImageOnLoad(
|
|||||||
void imageUrl
|
void imageUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Preload an image URL to ensure it's cached by the Service Worker
|
||||||
|
* This is useful when loading content from cache - we want to ensure
|
||||||
|
* images are cached before going offline
|
||||||
|
*/
|
||||||
|
export function preloadImage(imageUrl: string | undefined): void {
|
||||||
|
if (!imageUrl) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a link element with rel=prefetch or use Image object to trigger fetch
|
||||||
|
// Service Worker will intercept and cache the request
|
||||||
|
const img = new Image()
|
||||||
|
img.src = imageUrl
|
||||||
|
|
||||||
|
// Also try using fetch to explicitly trigger Service Worker
|
||||||
|
// This ensures the image is cached even if <img> tag hasn't rendered yet
|
||||||
|
fetch(imageUrl, { mode: 'no-cors' }).catch(() => {
|
||||||
|
// Ignore errors - image might not be CORS-enabled, but SW will still cache it
|
||||||
|
// The Image() approach above will work for most cases
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import React, { useState, useEffect, useRef } from 'react'
|
import React, { useState, useEffect, useRef, useMemo } from 'react'
|
||||||
import { RelayPool } from 'applesauce-relay'
|
import { RelayPool } from 'applesauce-relay'
|
||||||
import { extractNaddrUris, replaceNostrUrisInMarkdown, replaceNostrUrisInMarkdownWithTitles } from '../utils/nostrUriResolver'
|
import { extractNaddrUris, replaceNostrUrisInMarkdownWithProfileLabels, addLoadingClassToProfileLinks } from '../utils/nostrUriResolver'
|
||||||
import { fetchArticleTitles } from '../services/articleTitleResolver'
|
import { fetchArticleTitles } from '../services/articleTitleResolver'
|
||||||
|
import { useProfileLabels } from './useProfileLabels'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook to convert markdown to HTML using a hidden ReactMarkdown component
|
* Hook to convert markdown to HTML using a hidden ReactMarkdown component
|
||||||
@@ -18,56 +19,129 @@ export const useMarkdownToHTML = (
|
|||||||
const previewRef = useRef<HTMLDivElement>(null)
|
const previewRef = useRef<HTMLDivElement>(null)
|
||||||
const [renderedHtml, setRenderedHtml] = useState<string>('')
|
const [renderedHtml, setRenderedHtml] = useState<string>('')
|
||||||
const [processedMarkdown, setProcessedMarkdown] = useState<string>('')
|
const [processedMarkdown, setProcessedMarkdown] = useState<string>('')
|
||||||
|
const [articleTitles, setArticleTitles] = useState<Map<string, string>>(new Map())
|
||||||
|
|
||||||
|
// Resolve profile labels progressively as profiles load
|
||||||
|
const { labels: profileLabels, loading: profileLoading } = useProfileLabels(markdown || '', relayPool)
|
||||||
|
|
||||||
|
// Create stable dependencies based on Map contents, not Map objects
|
||||||
|
// This prevents unnecessary reprocessing when Maps are recreated with same content
|
||||||
|
const profileLabelsKey = useMemo(() => {
|
||||||
|
const key = Array.from(profileLabels.entries()).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => `${k}:${v}`).join('|')
|
||||||
|
return key
|
||||||
|
}, [profileLabels])
|
||||||
|
|
||||||
|
const profileLoadingKey = useMemo(() => {
|
||||||
|
return Array.from(profileLoading.entries())
|
||||||
|
.filter(([, loading]) => loading)
|
||||||
|
.sort(([a], [b]) => a.localeCompare(b))
|
||||||
|
.map(([k]) => k)
|
||||||
|
.join('|')
|
||||||
|
}, [profileLoading])
|
||||||
|
|
||||||
|
const articleTitlesKey = useMemo(() => {
|
||||||
|
return Array.from(articleTitles.entries()).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => `${k}:${v}`).join('|')
|
||||||
|
}, [articleTitles])
|
||||||
|
|
||||||
|
// Keep refs to latest Maps for processing without causing re-renders
|
||||||
|
const profileLabelsRef = useRef(profileLabels)
|
||||||
|
const profileLoadingRef = useRef(profileLoading)
|
||||||
|
const articleTitlesRef = useRef(articleTitles)
|
||||||
|
|
||||||
|
// Ref to track second RAF ID for HTML extraction cleanup
|
||||||
|
const htmlExtractionRafIdRef = useRef<number | null>(null)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!markdown) {
|
profileLabelsRef.current = profileLabels
|
||||||
setRenderedHtml('')
|
profileLoadingRef.current = profileLoading
|
||||||
setProcessedMarkdown('')
|
articleTitlesRef.current = articleTitles
|
||||||
|
}, [profileLabels, profileLoading, articleTitles])
|
||||||
|
|
||||||
|
// Fetch article titles
|
||||||
|
useEffect(() => {
|
||||||
|
if (!markdown || !relayPool) {
|
||||||
|
setArticleTitles(new Map())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let isCancelled = false
|
let isCancelled = false
|
||||||
|
|
||||||
const processMarkdown = async () => {
|
const fetchTitles = async () => {
|
||||||
// Extract all naddr references
|
|
||||||
const naddrs = extractNaddrUris(markdown)
|
const naddrs = extractNaddrUris(markdown)
|
||||||
|
if (naddrs.length === 0) {
|
||||||
let processed: string
|
setArticleTitles(new Map())
|
||||||
|
return
|
||||||
if (naddrs.length > 0 && relayPool) {
|
|
||||||
// Fetch article titles for all naddrs
|
|
||||||
try {
|
|
||||||
const articleTitles = await fetchArticleTitles(relayPool, naddrs)
|
|
||||||
|
|
||||||
if (isCancelled) return
|
|
||||||
|
|
||||||
// Replace nostr URIs with resolved titles
|
|
||||||
processed = replaceNostrUrisInMarkdownWithTitles(markdown, articleTitles)
|
|
||||||
} catch (error) {
|
|
||||||
console.warn('Failed to fetch article titles:', error)
|
|
||||||
// Fall back to basic replacement
|
|
||||||
processed = replaceNostrUrisInMarkdown(markdown)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// No articles to resolve, use basic replacement
|
|
||||||
processed = replaceNostrUrisInMarkdown(markdown)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isCancelled) return
|
|
||||||
|
|
||||||
setProcessedMarkdown(processed)
|
|
||||||
|
|
||||||
|
try {
|
||||||
const rafId = requestAnimationFrame(() => {
|
const titlesMap = await fetchArticleTitles(relayPool!, naddrs)
|
||||||
if (previewRef.current && !isCancelled) {
|
if (!isCancelled) {
|
||||||
const html = previewRef.current.innerHTML
|
setArticleTitles(titlesMap)
|
||||||
setRenderedHtml(html)
|
|
||||||
} else if (!isCancelled) {
|
|
||||||
console.warn('⚠️ markdownPreviewRef.current is null')
|
|
||||||
}
|
}
|
||||||
})
|
} catch {
|
||||||
|
if (!isCancelled) setArticleTitles(new Map())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return () => cancelAnimationFrame(rafId)
|
fetchTitles()
|
||||||
|
return () => { isCancelled = true }
|
||||||
|
}, [markdown, relayPool])
|
||||||
|
|
||||||
|
// Track previous markdown and processed state to detect actual content changes
|
||||||
|
const previousMarkdownRef = useRef<string | undefined>(markdown)
|
||||||
|
const processedMarkdownRef = useRef<string>(processedMarkdown)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
processedMarkdownRef.current = processedMarkdown
|
||||||
|
}, [processedMarkdown])
|
||||||
|
|
||||||
|
// Process markdown with progressive profile labels and article titles
|
||||||
|
// Use stable string keys instead of Map objects to prevent excessive reprocessing
|
||||||
|
useEffect(() => {
|
||||||
|
if (!markdown) {
|
||||||
|
setRenderedHtml('')
|
||||||
|
setProcessedMarkdown('')
|
||||||
|
previousMarkdownRef.current = markdown
|
||||||
|
processedMarkdownRef.current = ''
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let isCancelled = false
|
||||||
|
|
||||||
|
const processMarkdown = () => {
|
||||||
|
try {
|
||||||
|
// Replace nostr URIs with profile labels (progressive) and article titles
|
||||||
|
// Use refs to get latest values without causing dependency changes
|
||||||
|
const processed = replaceNostrUrisInMarkdownWithProfileLabels(
|
||||||
|
markdown,
|
||||||
|
profileLabelsRef.current,
|
||||||
|
articleTitlesRef.current,
|
||||||
|
profileLoadingRef.current
|
||||||
|
)
|
||||||
|
|
||||||
|
if (isCancelled) return
|
||||||
|
|
||||||
|
setProcessedMarkdown(processed)
|
||||||
|
processedMarkdownRef.current = processed
|
||||||
|
// HTML extraction will happen in separate useEffect that watches processedMarkdown
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`[markdown-to-html] Error processing markdown:`, error)
|
||||||
|
if (!isCancelled) {
|
||||||
|
setProcessedMarkdown(markdown) // Fallback to original
|
||||||
|
processedMarkdownRef.current = markdown
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only clear previous content if this is the first processing or markdown changed
|
||||||
|
// For profile updates, just reprocess without clearing to avoid flicker
|
||||||
|
const isMarkdownChange = previousMarkdownRef.current !== markdown
|
||||||
|
previousMarkdownRef.current = markdown
|
||||||
|
|
||||||
|
if (isMarkdownChange || !processedMarkdownRef.current) {
|
||||||
|
setRenderedHtml('')
|
||||||
|
setProcessedMarkdown('')
|
||||||
|
processedMarkdownRef.current = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
processMarkdown()
|
processMarkdown()
|
||||||
@@ -75,7 +149,44 @@ export const useMarkdownToHTML = (
|
|||||||
return () => {
|
return () => {
|
||||||
isCancelled = true
|
isCancelled = true
|
||||||
}
|
}
|
||||||
}, [markdown, relayPool])
|
}, [markdown, profileLabelsKey, profileLoadingKey, articleTitlesKey])
|
||||||
|
|
||||||
|
// Extract HTML after processedMarkdown renders
|
||||||
|
// This useEffect watches processedMarkdown and extracts HTML once ReactMarkdown has rendered it
|
||||||
|
useEffect(() => {
|
||||||
|
if (!processedMarkdown || !markdown) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let isCancelled = false
|
||||||
|
|
||||||
|
// Use double RAF to ensure ReactMarkdown has finished rendering:
|
||||||
|
// First RAF: let React complete its render cycle
|
||||||
|
// Second RAF: extract HTML after DOM has updated
|
||||||
|
const rafId1 = requestAnimationFrame(() => {
|
||||||
|
htmlExtractionRafIdRef.current = requestAnimationFrame(() => {
|
||||||
|
if (previewRef.current && !isCancelled) {
|
||||||
|
let html = previewRef.current.innerHTML
|
||||||
|
|
||||||
|
// Post-process HTML to add loading class to profile links
|
||||||
|
html = addLoadingClassToProfileLinks(html, profileLoadingRef.current)
|
||||||
|
|
||||||
|
setRenderedHtml(html)
|
||||||
|
} else if (!isCancelled && processedMarkdown) {
|
||||||
|
console.warn('⚠️ markdownPreviewRef.current is null but processedMarkdown exists')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
isCancelled = true
|
||||||
|
cancelAnimationFrame(rafId1)
|
||||||
|
if (htmlExtractionRafIdRef.current !== null) {
|
||||||
|
cancelAnimationFrame(htmlExtractionRafIdRef.current)
|
||||||
|
htmlExtractionRafIdRef.current = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [processedMarkdown, markdown])
|
||||||
|
|
||||||
return { renderedHtml, previewRef, processedMarkdown }
|
return { renderedHtml, previewRef, processedMarkdown }
|
||||||
}
|
}
|
||||||
|
|||||||
324
src/hooks/useProfileLabels.ts
Normal file
324
src/hooks/useProfileLabels.ts
Normal file
@@ -0,0 +1,324 @@
|
|||||||
|
import { useMemo, useState, useEffect, useRef, useCallback } from 'react'
|
||||||
|
import { Hooks } from 'applesauce-react'
|
||||||
|
import { Helpers, IEventStore } from 'applesauce-core'
|
||||||
|
import { getContentPointers } from 'applesauce-factory/helpers'
|
||||||
|
import { RelayPool } from 'applesauce-relay'
|
||||||
|
import { NostrEvent } from 'nostr-tools'
|
||||||
|
import { fetchProfiles, loadCachedProfiles } from '../services/profileService'
|
||||||
|
import { getNpubFallbackDisplay } from '../utils/nostrUriResolver'
|
||||||
|
import { extractProfileDisplayName } from '../utils/profileUtils'
|
||||||
|
|
||||||
|
const { getPubkeyFromDecodeResult, encodeDecodeResult } = Helpers
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook to resolve profile labels from content containing npub/nprofile identifiers
|
||||||
|
* Returns an object with labels Map and loading Map that updates progressively as profiles load
|
||||||
|
*/
|
||||||
|
export function useProfileLabels(
|
||||||
|
content: string,
|
||||||
|
relayPool?: RelayPool | null
|
||||||
|
): { labels: Map<string, string>; loading: Map<string, boolean> } {
|
||||||
|
const eventStore = Hooks.useEventStore()
|
||||||
|
|
||||||
|
// Extract profile pointers (npub and nprofile) using applesauce helpers
|
||||||
|
const profileData = useMemo(() => {
|
||||||
|
try {
|
||||||
|
const pointers = getContentPointers(content)
|
||||||
|
const filtered = pointers.filter(p => p.type === 'npub' || p.type === 'nprofile')
|
||||||
|
const result: Array<{ pubkey: string; encoded: string }> = []
|
||||||
|
filtered.forEach(pointer => {
|
||||||
|
try {
|
||||||
|
const pubkey = getPubkeyFromDecodeResult(pointer)
|
||||||
|
const encoded = encodeDecodeResult(pointer)
|
||||||
|
if (pubkey && encoded) {
|
||||||
|
result.push({ pubkey, encoded: encoded as string })
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Ignore errors, continue processing other pointers
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return result
|
||||||
|
} catch (error) {
|
||||||
|
console.warn(`[profile-labels] Error extracting profile pointers:`, error)
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}, [content])
|
||||||
|
|
||||||
|
// Initialize labels synchronously from cache on first render to avoid delay
|
||||||
|
// Use pubkey (hex) as the key instead of encoded string for canonical identification
|
||||||
|
const initialLabels = useMemo(() => {
|
||||||
|
if (profileData.length === 0) {
|
||||||
|
return new Map<string, string>()
|
||||||
|
}
|
||||||
|
|
||||||
|
const allPubkeys = profileData.map(({ pubkey }) => pubkey)
|
||||||
|
const cachedProfiles = loadCachedProfiles(allPubkeys)
|
||||||
|
const labels = new Map<string, string>()
|
||||||
|
|
||||||
|
profileData.forEach(({ pubkey }) => {
|
||||||
|
const cachedProfile = cachedProfiles.get(pubkey)
|
||||||
|
if (cachedProfile) {
|
||||||
|
const displayName = extractProfileDisplayName(cachedProfile)
|
||||||
|
if (displayName) {
|
||||||
|
// Add @ prefix (extractProfileDisplayName returns name without @)
|
||||||
|
const label = `@${displayName}`
|
||||||
|
labels.set(pubkey, label)
|
||||||
|
} else {
|
||||||
|
// Use fallback npub display if profile has no name (add @ prefix)
|
||||||
|
const fallback = getNpubFallbackDisplay(pubkey)
|
||||||
|
labels.set(pubkey, `@${fallback}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return labels
|
||||||
|
}, [profileData])
|
||||||
|
|
||||||
|
const [profileLabels, setProfileLabels] = useState<Map<string, string>>(initialLabels)
|
||||||
|
const [profileLoading, setProfileLoading] = useState<Map<string, boolean>>(new Map())
|
||||||
|
|
||||||
|
// Batching strategy: Collect profile updates and apply them in batches via RAF to prevent UI flicker
|
||||||
|
// when many profiles resolve simultaneously. We use refs to avoid stale closures in async callbacks.
|
||||||
|
// Use pubkey (hex) as the key for canonical identification
|
||||||
|
const pendingUpdatesRef = useRef<Map<string, string>>(new Map())
|
||||||
|
const rafScheduledRef = useRef<number | null>(null)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to apply pending batched updates to state
|
||||||
|
* Cancels any scheduled RAF and applies updates synchronously
|
||||||
|
*/
|
||||||
|
const applyPendingUpdates = () => {
|
||||||
|
const pendingUpdates = pendingUpdatesRef.current
|
||||||
|
if (pendingUpdates.size === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel scheduled RAF since we're applying synchronously
|
||||||
|
if (rafScheduledRef.current !== null) {
|
||||||
|
cancelAnimationFrame(rafScheduledRef.current)
|
||||||
|
rafScheduledRef.current = null
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply all pending updates in one batch
|
||||||
|
setProfileLabels(prevLabels => {
|
||||||
|
const updatedLabels = new Map(prevLabels)
|
||||||
|
for (const [pubkey, label] of pendingUpdates.entries()) {
|
||||||
|
updatedLabels.set(pubkey, label)
|
||||||
|
}
|
||||||
|
pendingUpdates.clear()
|
||||||
|
return updatedLabels
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to schedule a batched update via RAF (if not already scheduled)
|
||||||
|
* This prevents multiple RAF calls when many profiles resolve at once
|
||||||
|
* Wrapped in useCallback for stable reference in dependency arrays
|
||||||
|
*/
|
||||||
|
const scheduleBatchedUpdate = useCallback(() => {
|
||||||
|
if (rafScheduledRef.current === null) {
|
||||||
|
rafScheduledRef.current = requestAnimationFrame(() => {
|
||||||
|
applyPendingUpdates()
|
||||||
|
rafScheduledRef.current = null
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, []) // Empty deps: only uses refs which are stable
|
||||||
|
|
||||||
|
// Sync state when initialLabels changes (e.g., when content changes)
|
||||||
|
// This ensures we start with the correct cached labels even if profiles haven't loaded yet
|
||||||
|
useEffect(() => {
|
||||||
|
// Use a functional update to access current state without including it in dependencies
|
||||||
|
setProfileLabels(prevLabels => {
|
||||||
|
const currentPubkeys = new Set(Array.from(prevLabels.keys()))
|
||||||
|
const newPubkeys = new Set(profileData.map(p => p.pubkey))
|
||||||
|
|
||||||
|
// If the content changed significantly (different set of profiles), reset state
|
||||||
|
const hasDifferentProfiles =
|
||||||
|
currentPubkeys.size !== newPubkeys.size ||
|
||||||
|
!Array.from(newPubkeys).every(pk => currentPubkeys.has(pk))
|
||||||
|
|
||||||
|
if (hasDifferentProfiles) {
|
||||||
|
// Clear pending updates and cancel RAF for old profiles
|
||||||
|
pendingUpdatesRef.current.clear()
|
||||||
|
if (rafScheduledRef.current !== null) {
|
||||||
|
cancelAnimationFrame(rafScheduledRef.current)
|
||||||
|
rafScheduledRef.current = null
|
||||||
|
}
|
||||||
|
// Reset to initial labels
|
||||||
|
return new Map(initialLabels)
|
||||||
|
} else {
|
||||||
|
// Same profiles, merge initial labels with existing state
|
||||||
|
// IMPORTANT: Preserve existing labels (from pending updates) and only add initial labels if missing
|
||||||
|
const merged = new Map(prevLabels)
|
||||||
|
for (const [pubkey, label] of initialLabels.entries()) {
|
||||||
|
// Only add initial label if we don't already have a label for this pubkey
|
||||||
|
// This preserves labels that were added via applyPendingUpdates
|
||||||
|
if (!merged.has(pubkey)) {
|
||||||
|
merged.set(pubkey, label)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return merged
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Reset loading state when content changes significantly
|
||||||
|
setProfileLoading(prevLoading => {
|
||||||
|
const currentPubkeys = new Set(Array.from(prevLoading.keys()))
|
||||||
|
const newPubkeys = new Set(profileData.map(p => p.pubkey))
|
||||||
|
|
||||||
|
const hasDifferentProfiles =
|
||||||
|
currentPubkeys.size !== newPubkeys.size ||
|
||||||
|
!Array.from(newPubkeys).every(pk => currentPubkeys.has(pk))
|
||||||
|
|
||||||
|
if (hasDifferentProfiles) {
|
||||||
|
return new Map()
|
||||||
|
}
|
||||||
|
return prevLoading
|
||||||
|
})
|
||||||
|
}, [initialLabels, profileData])
|
||||||
|
|
||||||
|
// Build initial labels: localStorage cache -> eventStore -> fetch from relays
|
||||||
|
useEffect(() => {
|
||||||
|
// Extract all pubkeys
|
||||||
|
const allPubkeys = profileData.map(({ pubkey }) => pubkey)
|
||||||
|
|
||||||
|
if (allPubkeys.length === 0) {
|
||||||
|
setProfileLabels(new Map())
|
||||||
|
setProfileLoading(new Map())
|
||||||
|
// Clear pending updates and cancel RAF when clearing labels
|
||||||
|
pendingUpdatesRef.current.clear()
|
||||||
|
if (rafScheduledRef.current !== null) {
|
||||||
|
cancelAnimationFrame(rafScheduledRef.current)
|
||||||
|
rafScheduledRef.current = null
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add cached profiles to EventStore for consistency
|
||||||
|
const cachedProfiles = loadCachedProfiles(allPubkeys)
|
||||||
|
if (eventStore) {
|
||||||
|
for (const profile of cachedProfiles.values()) {
|
||||||
|
eventStore.add(profile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build labels from localStorage cache and eventStore
|
||||||
|
// initialLabels already has all cached profiles, so we only need to check eventStore
|
||||||
|
// Use pubkey (hex) as the key for canonical identification
|
||||||
|
const labels = new Map<string, string>(initialLabels)
|
||||||
|
const loading = new Map<string, boolean>()
|
||||||
|
|
||||||
|
const pubkeysToFetch: string[] = []
|
||||||
|
|
||||||
|
profileData.forEach(({ pubkey }) => {
|
||||||
|
// Skip if already resolved from initial cache
|
||||||
|
if (labels.has(pubkey)) {
|
||||||
|
loading.set(pubkey, false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check EventStore for profiles that weren't in cache
|
||||||
|
const eventStoreProfile = eventStore?.getEvent(pubkey + ':0')
|
||||||
|
|
||||||
|
if (eventStoreProfile && eventStore) {
|
||||||
|
// Extract display name using centralized utility
|
||||||
|
const displayName = extractProfileDisplayName(eventStoreProfile as NostrEvent)
|
||||||
|
if (displayName) {
|
||||||
|
// Add @ prefix (extractProfileDisplayName returns name without @)
|
||||||
|
const label = `@${displayName}`
|
||||||
|
labels.set(pubkey, label)
|
||||||
|
} else {
|
||||||
|
// Use fallback npub display if profile has no name (add @ prefix)
|
||||||
|
const fallback = getNpubFallbackDisplay(pubkey)
|
||||||
|
labels.set(pubkey, `@${fallback}`)
|
||||||
|
}
|
||||||
|
loading.set(pubkey, false)
|
||||||
|
} else {
|
||||||
|
// No profile found yet, will use fallback after fetch or keep empty
|
||||||
|
// We'll set fallback labels for missing profiles at the end
|
||||||
|
// Mark as loading since we'll fetch it
|
||||||
|
pubkeysToFetch.push(pubkey)
|
||||||
|
loading.set(pubkey, true)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Don't set fallback labels in the Map - we'll use fallback directly when rendering
|
||||||
|
// This allows us to distinguish between "no label yet" (use fallback) vs "resolved label" (use Map value)
|
||||||
|
|
||||||
|
setProfileLabels(new Map(labels))
|
||||||
|
setProfileLoading(new Map(loading))
|
||||||
|
|
||||||
|
// Fetch missing profiles asynchronously with reactive updates
|
||||||
|
if (pubkeysToFetch.length > 0 && relayPool && eventStore) {
|
||||||
|
|
||||||
|
// Reactive callback: collects profile updates and batches them via RAF to prevent flicker
|
||||||
|
// Strategy: Apply label immediately when profile resolves, but still batch for multiple profiles
|
||||||
|
const handleProfileEvent = (event: NostrEvent) => {
|
||||||
|
// Use pubkey directly as the key
|
||||||
|
const pubkey = event.pubkey
|
||||||
|
|
||||||
|
// Determine the label for this profile using centralized utility
|
||||||
|
// Add @ prefix (both extractProfileDisplayName and getNpubFallbackDisplay return names without @)
|
||||||
|
const displayName = extractProfileDisplayName(event)
|
||||||
|
const label = displayName ? `@${displayName}` : `@${getNpubFallbackDisplay(pubkey)}`
|
||||||
|
|
||||||
|
// Apply label immediately to prevent race condition with loading state
|
||||||
|
// This ensures labels are available when isLoading becomes false
|
||||||
|
setProfileLabels(prevLabels => {
|
||||||
|
const updated = new Map(prevLabels)
|
||||||
|
updated.set(pubkey, label)
|
||||||
|
return updated
|
||||||
|
})
|
||||||
|
|
||||||
|
// Clear loading state for this profile when it resolves
|
||||||
|
setProfileLoading(prevLoading => {
|
||||||
|
const updated = new Map(prevLoading)
|
||||||
|
updated.set(pubkey, false)
|
||||||
|
return updated
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchProfiles(relayPool, eventStore as unknown as IEventStore, pubkeysToFetch, undefined, handleProfileEvent)
|
||||||
|
.then(() => {
|
||||||
|
// After EOSE: apply any remaining pending updates immediately
|
||||||
|
// This ensures all profile updates are applied even if RAF hasn't fired yet
|
||||||
|
applyPendingUpdates()
|
||||||
|
|
||||||
|
// Clear loading state for all fetched profiles
|
||||||
|
setProfileLoading(prevLoading => {
|
||||||
|
const updated = new Map(prevLoading)
|
||||||
|
pubkeysToFetch.forEach(pubkey => {
|
||||||
|
updated.set(pubkey, false)
|
||||||
|
})
|
||||||
|
return updated
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(`[profile-labels] Error fetching profiles:`, error)
|
||||||
|
// Silently handle fetch errors, but still clear any pending updates
|
||||||
|
pendingUpdatesRef.current.clear()
|
||||||
|
if (rafScheduledRef.current !== null) {
|
||||||
|
cancelAnimationFrame(rafScheduledRef.current)
|
||||||
|
rafScheduledRef.current = null
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear loading state on error (show fallback)
|
||||||
|
setProfileLoading(prevLoading => {
|
||||||
|
const updated = new Map(prevLoading)
|
||||||
|
pubkeysToFetch.forEach(pubkey => {
|
||||||
|
updated.set(pubkey, false)
|
||||||
|
})
|
||||||
|
return updated
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// Cleanup: apply any pending updates before unmount to avoid losing them
|
||||||
|
return () => {
|
||||||
|
applyPendingUpdates()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [profileData, eventStore, relayPool, initialLabels, scheduleBatchedUpdate])
|
||||||
|
|
||||||
|
return { labels: profileLabels, loading: profileLoading }
|
||||||
|
}
|
||||||
|
|
||||||
@@ -7,7 +7,6 @@ interface UseReadingPositionOptions {
|
|||||||
readingCompleteThreshold?: number // Default 0.95 (95%) - matches filter threshold
|
readingCompleteThreshold?: number // Default 0.95 (95%) - matches filter threshold
|
||||||
syncEnabled?: boolean // Whether to sync positions to Nostr
|
syncEnabled?: boolean // Whether to sync positions to Nostr
|
||||||
onSave?: (position: number) => void // Callback for saving position
|
onSave?: (position: number) => void // Callback for saving position
|
||||||
autoSaveInterval?: number // Auto-save interval in ms (default 5000)
|
|
||||||
completionHoldMs?: number // How long to hold at 100% before firing complete (default 2000)
|
completionHoldMs?: number // How long to hold at 100% before firing complete (default 2000)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,98 +17,69 @@ export const useReadingPosition = ({
|
|||||||
readingCompleteThreshold = 0.95, // Match filter threshold for consistency
|
readingCompleteThreshold = 0.95, // Match filter threshold for consistency
|
||||||
syncEnabled = false,
|
syncEnabled = false,
|
||||||
onSave,
|
onSave,
|
||||||
autoSaveInterval = 5000,
|
|
||||||
completionHoldMs = 2000
|
completionHoldMs = 2000
|
||||||
}: UseReadingPositionOptions = {}) => {
|
}: UseReadingPositionOptions = {}) => {
|
||||||
const [position, setPosition] = useState(0)
|
const [position, setPosition] = useState(0)
|
||||||
const positionRef = useRef(0)
|
const positionRef = useRef(0)
|
||||||
const [isReadingComplete, setIsReadingComplete] = useState(false)
|
const [isReadingComplete, setIsReadingComplete] = useState(false)
|
||||||
const hasTriggeredComplete = useRef(false)
|
const hasTriggeredComplete = useRef(false)
|
||||||
const lastSavedPosition = useRef(0)
|
|
||||||
const saveTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
const saveTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
||||||
const hasSavedOnce = useRef(false)
|
|
||||||
const completionTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
const completionTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
||||||
const lastSavedAtRef = useRef<number>(0)
|
const suppressUntilRef = useRef<number>(0)
|
||||||
|
const pendingPositionRef = useRef<number>(0) // Track latest position for throttled save
|
||||||
|
const lastSaved100Ref = useRef(false) // Track if we've saved 100% to avoid duplicate saves
|
||||||
|
|
||||||
|
// Store callbacks in refs to avoid them being dependencies
|
||||||
|
const onPositionChangeRef = useRef(onPositionChange)
|
||||||
|
const onReadingCompleteRef = useRef(onReadingComplete)
|
||||||
|
const onSaveRef = useRef(onSave)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
onPositionChangeRef.current = onPositionChange
|
||||||
|
onReadingCompleteRef.current = onReadingComplete
|
||||||
|
onSaveRef.current = onSave
|
||||||
|
}, [onPositionChange, onReadingComplete, onSave])
|
||||||
|
|
||||||
// Debounced save function
|
// Suppress auto-saves for a given duration (used after programmatic restore)
|
||||||
|
const suppressSavesFor = useCallback((ms: number) => {
|
||||||
|
const until = Date.now() + ms
|
||||||
|
suppressUntilRef.current = until
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
// Throttled save function - saves at 1s intervals during scrolling
|
||||||
const scheduleSave = useCallback((currentPosition: number) => {
|
const scheduleSave = useCallback((currentPosition: number) => {
|
||||||
if (!syncEnabled || !onSave) {
|
if (!syncEnabled || !onSaveRef.current) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always save instantly when we reach completion (1.0)
|
// Always save instantly when we reach completion (1.0)
|
||||||
if (currentPosition === 1 && lastSavedPosition.current < 1) {
|
if (currentPosition === 1 && !lastSaved100Ref.current) {
|
||||||
if (saveTimerRef.current) {
|
if (saveTimerRef.current) {
|
||||||
clearTimeout(saveTimerRef.current)
|
clearTimeout(saveTimerRef.current)
|
||||||
saveTimerRef.current = null
|
saveTimerRef.current = null
|
||||||
}
|
}
|
||||||
lastSavedPosition.current = 1
|
lastSaved100Ref.current = true
|
||||||
hasSavedOnce.current = true
|
onSaveRef.current(1)
|
||||||
lastSavedAtRef.current = Date.now()
|
|
||||||
onSave(1)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Require at least 5% progress change to consider saving
|
// Always update the pending position (latest position to save)
|
||||||
const MIN_DELTA = 0.05
|
pendingPositionRef.current = currentPosition
|
||||||
const hasSignificantChange = Math.abs(currentPosition - lastSavedPosition.current) >= MIN_DELTA
|
|
||||||
|
|
||||||
// Enforce a minimum interval between saves (15s) to avoid spamming
|
// Throttle: only schedule a save if one isn't already pending
|
||||||
const MIN_INTERVAL_MS = 15000
|
// This ensures saves happen at regular 1s intervals during continuous scrolling
|
||||||
const nowMs = Date.now()
|
|
||||||
const enoughTimeElapsed = nowMs - lastSavedAtRef.current >= MIN_INTERVAL_MS
|
|
||||||
|
|
||||||
// Allow the very first meaningful save (when crossing 5%) regardless of interval
|
|
||||||
const isFirstMeaningful = !hasSavedOnce.current && currentPosition >= MIN_DELTA
|
|
||||||
|
|
||||||
if (!hasSignificantChange && !isFirstMeaningful) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// If interval hasn't elapsed yet, delay until autoSaveInterval but still cap frequency
|
|
||||||
if (!enoughTimeElapsed && !isFirstMeaningful) {
|
|
||||||
// Clear and reschedule within the remaining window, but not sooner than MIN_INTERVAL_MS
|
|
||||||
if (saveTimerRef.current) {
|
|
||||||
clearTimeout(saveTimerRef.current)
|
|
||||||
}
|
|
||||||
const remaining = Math.max(0, MIN_INTERVAL_MS - (nowMs - lastSavedAtRef.current))
|
|
||||||
const delay = Math.max(autoSaveInterval, remaining)
|
|
||||||
saveTimerRef.current = setTimeout(() => {
|
|
||||||
lastSavedPosition.current = currentPosition
|
|
||||||
hasSavedOnce.current = true
|
|
||||||
lastSavedAtRef.current = Date.now()
|
|
||||||
onSave(currentPosition)
|
|
||||||
}, delay)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear existing timer
|
|
||||||
if (saveTimerRef.current) {
|
if (saveTimerRef.current) {
|
||||||
clearTimeout(saveTimerRef.current)
|
return // Already have a save scheduled, don't reset the timer
|
||||||
}
|
}
|
||||||
|
|
||||||
// Schedule new save using the larger of autoSaveInterval and MIN_INTERVAL_MS
|
const THROTTLE_MS = 1000
|
||||||
const delay = Math.max(autoSaveInterval, MIN_INTERVAL_MS)
|
|
||||||
saveTimerRef.current = setTimeout(() => {
|
saveTimerRef.current = setTimeout(() => {
|
||||||
lastSavedPosition.current = currentPosition
|
// Save the latest position, not the one from when timer was scheduled
|
||||||
hasSavedOnce.current = true
|
const positionToSave = pendingPositionRef.current
|
||||||
lastSavedAtRef.current = Date.now()
|
onSaveRef.current?.(positionToSave)
|
||||||
onSave(currentPosition)
|
|
||||||
}, delay)
|
|
||||||
}, [syncEnabled, onSave, autoSaveInterval])
|
|
||||||
|
|
||||||
// Immediate save function
|
|
||||||
const saveNow = useCallback(() => {
|
|
||||||
if (!syncEnabled || !onSave) return
|
|
||||||
if (saveTimerRef.current) {
|
|
||||||
clearTimeout(saveTimerRef.current)
|
|
||||||
saveTimerRef.current = null
|
saveTimerRef.current = null
|
||||||
}
|
}, THROTTLE_MS)
|
||||||
lastSavedPosition.current = position
|
}, [syncEnabled])
|
||||||
hasSavedOnce.current = true
|
|
||||||
lastSavedAtRef.current = Date.now()
|
|
||||||
onSave(position)
|
|
||||||
}, [syncEnabled, onSave, position])
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!enabled) return
|
if (!enabled) return
|
||||||
@@ -123,21 +93,27 @@ export const useReadingPosition = ({
|
|||||||
const windowHeight = window.innerHeight
|
const windowHeight = window.innerHeight
|
||||||
const documentHeight = document.documentElement.scrollHeight
|
const documentHeight = document.documentElement.scrollHeight
|
||||||
|
|
||||||
|
// Ignore if document is too small (likely during page transition)
|
||||||
|
if (documentHeight < 100) return
|
||||||
|
|
||||||
// Calculate position based on how much of the content has been scrolled through
|
// Calculate position based on how much of the content has been scrolled through
|
||||||
// Add a small threshold (5px) to account for rounding and make it easier to reach 100%
|
|
||||||
const maxScroll = documentHeight - windowHeight
|
const maxScroll = documentHeight - windowHeight
|
||||||
const scrollProgress = maxScroll > 0 ? scrollTop / maxScroll : 0
|
const scrollProgress = maxScroll > 0 ? scrollTop / maxScroll : 0
|
||||||
|
|
||||||
// If we're within 5px of the bottom, consider it 100%
|
// Only consider it 100% if we're truly at the bottom AND have scrolled significantly
|
||||||
const isAtBottom = scrollTop + windowHeight >= documentHeight - 5
|
// This prevents false 100% during page transitions
|
||||||
|
const isAtBottom = scrollTop + windowHeight >= documentHeight - 5 && scrollTop > 100
|
||||||
const clampedProgress = isAtBottom ? 1 : Math.max(0, Math.min(1, scrollProgress))
|
const clampedProgress = isAtBottom ? 1 : Math.max(0, Math.min(1, scrollProgress))
|
||||||
|
|
||||||
setPosition(clampedProgress)
|
setPosition(clampedProgress)
|
||||||
positionRef.current = clampedProgress
|
positionRef.current = clampedProgress
|
||||||
onPositionChange?.(clampedProgress)
|
onPositionChangeRef.current?.(clampedProgress)
|
||||||
|
|
||||||
// Schedule auto-save if sync is enabled
|
// Schedule auto-save if sync is enabled (unless suppressed)
|
||||||
scheduleSave(clampedProgress)
|
if (Date.now() >= suppressUntilRef.current) {
|
||||||
|
scheduleSave(clampedProgress)
|
||||||
|
}
|
||||||
|
// Note: Suppression is silent to avoid log spam during scrolling
|
||||||
|
|
||||||
// Completion detection with 2s hold at 100%
|
// Completion detection with 2s hold at 100%
|
||||||
if (!hasTriggeredComplete.current) {
|
if (!hasTriggeredComplete.current) {
|
||||||
@@ -148,7 +124,7 @@ export const useReadingPosition = ({
|
|||||||
if (!hasTriggeredComplete.current && positionRef.current === 1) {
|
if (!hasTriggeredComplete.current && positionRef.current === 1) {
|
||||||
setIsReadingComplete(true)
|
setIsReadingComplete(true)
|
||||||
hasTriggeredComplete.current = true
|
hasTriggeredComplete.current = true
|
||||||
onReadingComplete?.()
|
onReadingCompleteRef.current?.()
|
||||||
}
|
}
|
||||||
completionTimerRef.current = null
|
completionTimerRef.current = null
|
||||||
}, completionHoldMs)
|
}, completionHoldMs)
|
||||||
@@ -162,7 +138,7 @@ export const useReadingPosition = ({
|
|||||||
if (clampedProgress >= readingCompleteThreshold) {
|
if (clampedProgress >= readingCompleteThreshold) {
|
||||||
setIsReadingComplete(true)
|
setIsReadingComplete(true)
|
||||||
hasTriggeredComplete.current = true
|
hasTriggeredComplete.current = true
|
||||||
onReadingComplete?.()
|
onReadingCompleteRef.current?.()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,23 +156,20 @@ export const useReadingPosition = ({
|
|||||||
window.removeEventListener('scroll', handleScroll)
|
window.removeEventListener('scroll', handleScroll)
|
||||||
window.removeEventListener('resize', handleScroll)
|
window.removeEventListener('resize', handleScroll)
|
||||||
|
|
||||||
// Clear save timer on unmount
|
// DON'T clear save timer - let it complete even if tracking is temporarily disabled
|
||||||
if (saveTimerRef.current) {
|
// Only clear completion timer since that's tied to the current scroll session
|
||||||
clearTimeout(saveTimerRef.current)
|
|
||||||
}
|
|
||||||
if (completionTimerRef.current) {
|
if (completionTimerRef.current) {
|
||||||
clearTimeout(completionTimerRef.current)
|
clearTimeout(completionTimerRef.current)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [enabled, onPositionChange, onReadingComplete, readingCompleteThreshold, scheduleSave, completionHoldMs])
|
}, [enabled, readingCompleteThreshold, scheduleSave, completionHoldMs])
|
||||||
|
|
||||||
// Reset reading complete state when enabled changes
|
// Reset reading complete state when enabled changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
setIsReadingComplete(false)
|
setIsReadingComplete(false)
|
||||||
hasTriggeredComplete.current = false
|
hasTriggeredComplete.current = false
|
||||||
hasSavedOnce.current = false
|
lastSaved100Ref.current = false
|
||||||
lastSavedPosition.current = 0
|
|
||||||
if (completionTimerRef.current) {
|
if (completionTimerRef.current) {
|
||||||
clearTimeout(completionTimerRef.current)
|
clearTimeout(completionTimerRef.current)
|
||||||
completionTimerRef.current = null
|
completionTimerRef.current = null
|
||||||
@@ -208,6 +181,6 @@ export const useReadingPosition = ({
|
|||||||
position,
|
position,
|
||||||
isReadingComplete,
|
isReadingComplete,
|
||||||
progressPercentage: Math.round(position * 100),
|
progressPercentage: Math.round(position * 100),
|
||||||
saveNow
|
suppressSavesFor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { IEventStore } from 'applesauce-core'
|
|||||||
import { RelayPool } from 'applesauce-relay'
|
import { RelayPool } from 'applesauce-relay'
|
||||||
import { EventFactory } from 'applesauce-factory'
|
import { EventFactory } from 'applesauce-factory'
|
||||||
import { AccountManager } from 'applesauce-accounts'
|
import { AccountManager } from 'applesauce-accounts'
|
||||||
import { UserSettings, loadSettings, saveSettings, watchSettings } from '../services/settingsService'
|
import { UserSettings, saveSettings, watchSettings, startSettingsStream } from '../services/settingsService'
|
||||||
import { loadFont, getFontFamily } from '../utils/fontLoader'
|
import { loadFont, getFontFamily } from '../utils/fontLoader'
|
||||||
import { applyTheme } from '../utils/theme'
|
import { applyTheme } from '../utils/theme'
|
||||||
import { RELAYS } from '../config/relays'
|
import { RELAYS } from '../config/relays'
|
||||||
@@ -20,26 +20,24 @@ export function useSettings({ relayPool, eventStore, pubkey, accountManager }: U
|
|||||||
const [toastMessage, setToastMessage] = useState<string | null>(null)
|
const [toastMessage, setToastMessage] = useState<string | null>(null)
|
||||||
const [toastType, setToastType] = useState<'success' | 'error'>('success')
|
const [toastType, setToastType] = useState<'success' | 'error'>('success')
|
||||||
|
|
||||||
// Load settings and set up subscription
|
// Load settings and set up streaming subscription (non-blocking, EOSE-driven)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!relayPool || !pubkey || !eventStore) return
|
if (!relayPool || !pubkey || !eventStore) return
|
||||||
|
|
||||||
const loadAndWatch = async () => {
|
// Start settings stream: seed from store, stream updates to store in background
|
||||||
try {
|
const stopNetwork = startSettingsStream(relayPool, eventStore, pubkey, RELAYS, (loadedSettings) => {
|
||||||
const loadedSettings = await loadSettings(relayPool, eventStore, pubkey, RELAYS)
|
if (loadedSettings) setSettings({ renderVideoLinksAsEmbeds: true, hideBotArticlesByName: true, ...loadedSettings })
|
||||||
if (loadedSettings) setSettings({ renderVideoLinksAsEmbeds: true, hideBotArticlesByName: true, ...loadedSettings })
|
})
|
||||||
} catch (err) {
|
|
||||||
console.error('Failed to load settings:', err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
loadAndWatch()
|
|
||||||
|
|
||||||
|
// Also watch store reactively for any further updates
|
||||||
const subscription = watchSettings(eventStore, pubkey, (loadedSettings) => {
|
const subscription = watchSettings(eventStore, pubkey, (loadedSettings) => {
|
||||||
if (loadedSettings) setSettings({ renderVideoLinksAsEmbeds: true, hideBotArticlesByName: true, ...loadedSettings })
|
if (loadedSettings) setSettings({ renderVideoLinksAsEmbeds: true, hideBotArticlesByName: true, ...loadedSettings })
|
||||||
})
|
})
|
||||||
|
|
||||||
return () => subscription.unsubscribe()
|
return () => {
|
||||||
|
subscription.unsubscribe()
|
||||||
|
stopNetwork()
|
||||||
|
}
|
||||||
}, [relayPool, pubkey, eventStore])
|
}, [relayPool, pubkey, eventStore])
|
||||||
|
|
||||||
// Apply settings to document
|
// Apply settings to document
|
||||||
@@ -73,8 +71,9 @@ export function useSettings({ relayPool, eventStore, pubkey, accountManager }: U
|
|||||||
// Set paragraph alignment
|
// Set paragraph alignment
|
||||||
root.setProperty('--paragraph-alignment', settings.paragraphAlignment || 'justify')
|
root.setProperty('--paragraph-alignment', settings.paragraphAlignment || 'justify')
|
||||||
|
|
||||||
// Set image max-width based on full-width setting
|
// Set image width and max-height based on full-width setting
|
||||||
root.setProperty('--image-max-width', settings.fullWidthImages ? 'none' : '100%')
|
root.setProperty('--image-width', settings.fullWidthImages ? '100%' : 'auto')
|
||||||
|
root.setProperty('--image-max-height', settings.fullWidthImages ? 'none' : '70vh')
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ export function useTextToSpeech(options: UseTTSOptions = {}): UseTTS {
|
|||||||
// Update rate when defaultRate option changes
|
// Update rate when defaultRate option changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (options.defaultRate !== undefined) {
|
if (options.defaultRate !== undefined) {
|
||||||
console.debug('[tts] defaultRate changed ->', options.defaultRate)
|
|
||||||
setRate(options.defaultRate)
|
setRate(options.defaultRate)
|
||||||
}
|
}
|
||||||
}, [options.defaultRate])
|
}, [options.defaultRate])
|
||||||
@@ -73,7 +72,6 @@ export function useTextToSpeech(options: UseTTSOptions = {}): UseTTS {
|
|||||||
if (!voice && v.length) {
|
if (!voice && v.length) {
|
||||||
const byLang = v.find(x => x.lang?.toLowerCase().startsWith(defaultLang.toLowerCase()))
|
const byLang = v.find(x => x.lang?.toLowerCase().startsWith(defaultLang.toLowerCase()))
|
||||||
setVoice(byLang || v[0] || null)
|
setVoice(byLang || v[0] || null)
|
||||||
console.debug('[tts] voices loaded', { total: v.length, picked: (byLang || v[0] || null)?.lang })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
load()
|
load()
|
||||||
@@ -107,44 +105,37 @@ export function useTextToSpeech(options: UseTTSOptions = {}): UseTTS {
|
|||||||
|
|
||||||
u.onstart = () => {
|
u.onstart = () => {
|
||||||
if (utteranceRef.current !== self) return
|
if (utteranceRef.current !== self) return
|
||||||
console.debug('[tts] onstart')
|
|
||||||
setSpeaking(true)
|
setSpeaking(true)
|
||||||
setPaused(false)
|
setPaused(false)
|
||||||
}
|
}
|
||||||
u.onpause = () => {
|
u.onpause = () => {
|
||||||
if (utteranceRef.current !== self) return
|
if (utteranceRef.current !== self) return
|
||||||
console.debug('[tts] onpause')
|
|
||||||
setPaused(true)
|
setPaused(true)
|
||||||
}
|
}
|
||||||
u.onresume = () => {
|
u.onresume = () => {
|
||||||
if (utteranceRef.current !== self) return
|
if (utteranceRef.current !== self) return
|
||||||
console.debug('[tts] onresume')
|
|
||||||
setPaused(false)
|
setPaused(false)
|
||||||
}
|
}
|
||||||
u.onend = () => {
|
u.onend = () => {
|
||||||
if (utteranceRef.current !== self) return
|
if (utteranceRef.current !== self) return
|
||||||
console.debug('[tts] onend')
|
|
||||||
// Continue with next chunk if available
|
// Continue with next chunk if available
|
||||||
const hasMore = chunkIndexRef.current < (chunksRef.current.length - 1)
|
const hasMore = chunkIndexRef.current < (chunksRef.current.length - 1)
|
||||||
if (hasMore) {
|
if (hasMore) {
|
||||||
chunkIndexRef.current += 1
|
chunkIndexRef.current++
|
||||||
globalOffsetRef.current += self.text.length
|
charIndexRef.current += self.text.length
|
||||||
const next = chunksRef.current[chunkIndexRef.current] || ''
|
const nextChunk = chunksRef.current[chunkIndexRef.current]
|
||||||
const nextUtterance = createUtterance(next, langRef.current)
|
const nextUtterance = createUtterance(nextChunk, langRef.current)
|
||||||
utteranceRef.current = nextUtterance
|
utteranceRef.current = nextUtterance
|
||||||
synth!.speak(nextUtterance)
|
synth!.speak(nextUtterance)
|
||||||
return
|
} else {
|
||||||
|
setSpeaking(false)
|
||||||
|
setPaused(false)
|
||||||
}
|
}
|
||||||
setSpeaking(false)
|
|
||||||
setPaused(false)
|
|
||||||
utteranceRef.current = null
|
|
||||||
}
|
}
|
||||||
u.onerror = () => {
|
u.onerror = () => {
|
||||||
if (utteranceRef.current !== self) return
|
if (utteranceRef.current !== self) return
|
||||||
console.debug('[tts] onerror')
|
|
||||||
setSpeaking(false)
|
setSpeaking(false)
|
||||||
setPaused(false)
|
setPaused(false)
|
||||||
utteranceRef.current = null
|
|
||||||
}
|
}
|
||||||
u.onboundary = (ev: SpeechSynthesisEvent) => {
|
u.onboundary = (ev: SpeechSynthesisEvent) => {
|
||||||
if (utteranceRef.current !== self) return
|
if (utteranceRef.current !== self) return
|
||||||
@@ -197,7 +188,6 @@ export function useTextToSpeech(options: UseTTSOptions = {}): UseTTS {
|
|||||||
|
|
||||||
const stop = useCallback(() => {
|
const stop = useCallback(() => {
|
||||||
if (!supported) return
|
if (!supported) return
|
||||||
console.debug('[tts] stop')
|
|
||||||
synth!.cancel()
|
synth!.cancel()
|
||||||
setSpeaking(false)
|
setSpeaking(false)
|
||||||
setPaused(false)
|
setPaused(false)
|
||||||
@@ -211,18 +201,16 @@ export function useTextToSpeech(options: UseTTSOptions = {}): UseTTS {
|
|||||||
|
|
||||||
const speak = useCallback((text: string, langOverride?: string) => {
|
const speak = useCallback((text: string, langOverride?: string) => {
|
||||||
if (!supported || !text?.trim()) return
|
if (!supported || !text?.trim()) return
|
||||||
console.debug('[tts] speak', { len: text.length, rate })
|
|
||||||
synth!.cancel()
|
synth!.cancel()
|
||||||
spokenTextRef.current = text
|
spokenTextRef.current = text
|
||||||
charIndexRef.current = 0
|
charIndexRef.current = 0
|
||||||
langRef.current = langOverride
|
langRef.current = langOverride
|
||||||
startSpeakingChunks(text)
|
startSpeakingChunks(text)
|
||||||
}, [supported, synth, startSpeakingChunks, rate])
|
}, [supported, synth, startSpeakingChunks])
|
||||||
|
|
||||||
const pause = useCallback(() => {
|
const pause = useCallback(() => {
|
||||||
if (!supported) return
|
if (!supported) return
|
||||||
if (synth!.speaking && !synth!.paused) {
|
if (synth!.speaking && !synth!.paused) {
|
||||||
console.debug('[tts] pause')
|
|
||||||
synth!.pause()
|
synth!.pause()
|
||||||
setPaused(true)
|
setPaused(true)
|
||||||
}
|
}
|
||||||
@@ -231,7 +219,6 @@ export function useTextToSpeech(options: UseTTSOptions = {}): UseTTS {
|
|||||||
const resume = useCallback(() => {
|
const resume = useCallback(() => {
|
||||||
if (!supported) return
|
if (!supported) return
|
||||||
if (synth!.speaking && synth!.paused) {
|
if (synth!.speaking && synth!.paused) {
|
||||||
console.debug('[tts] resume')
|
|
||||||
synth!.resume()
|
synth!.resume()
|
||||||
setPaused(false)
|
setPaused(false)
|
||||||
}
|
}
|
||||||
@@ -242,14 +229,11 @@ export function useTextToSpeech(options: UseTTSOptions = {}): UseTTS {
|
|||||||
if (!supported) return
|
if (!supported) return
|
||||||
if (!utteranceRef.current) return
|
if (!utteranceRef.current) return
|
||||||
|
|
||||||
console.debug('[tts] rate change', { rate, speaking: synth!.speaking, paused: synth!.paused, charIndex: charIndexRef.current })
|
|
||||||
|
|
||||||
if (synth!.speaking && !synth!.paused) {
|
if (synth!.speaking && !synth!.paused) {
|
||||||
const fullText = spokenTextRef.current
|
const fullText = spokenTextRef.current
|
||||||
const startIndex = Math.max(0, Math.min(charIndexRef.current, fullText.length))
|
const startIndex = Math.max(0, Math.min(charIndexRef.current, fullText.length))
|
||||||
const remainingText = fullText.slice(startIndex)
|
const remainingText = fullText.slice(startIndex)
|
||||||
|
|
||||||
console.debug('[tts] restart at new rate', { startIndex, remainingLen: remainingText.length })
|
|
||||||
synth!.cancel()
|
synth!.cancel()
|
||||||
// restart chunked from current global index
|
// restart chunked from current global index
|
||||||
spokenTextRef.current = remainingText
|
spokenTextRef.current = remainingText
|
||||||
@@ -273,7 +257,6 @@ export function useTextToSpeech(options: UseTTSOptions = {}): UseTTS {
|
|||||||
const fullText = spokenTextRef.current
|
const fullText = spokenTextRef.current
|
||||||
const startIndex = Math.max(0, Math.min(charIndexRef.current, fullText.length - 1))
|
const startIndex = Math.max(0, Math.min(charIndexRef.current, fullText.length - 1))
|
||||||
const remainingText = fullText.slice(startIndex)
|
const remainingText = fullText.slice(startIndex)
|
||||||
console.debug('[tts] updateRate -> restart', { newRate, startIndex, remainingLen: remainingText.length })
|
|
||||||
synth!.cancel()
|
synth!.cancel()
|
||||||
const u = createUtterance(remainingText)
|
const u = createUtterance(remainingText)
|
||||||
// ensure the new rate is applied immediately on the new utterance
|
// ensure the new rate is applied immediately on the new utterance
|
||||||
@@ -281,7 +264,6 @@ export function useTextToSpeech(options: UseTTSOptions = {}): UseTTS {
|
|||||||
utteranceRef.current = u
|
utteranceRef.current = u
|
||||||
synth!.speak(u)
|
synth!.speak(u)
|
||||||
} else if (utteranceRef.current) {
|
} else if (utteranceRef.current) {
|
||||||
console.debug('[tts] updateRate -> set on utterance', { newRate })
|
|
||||||
utteranceRef.current.rate = newRate
|
utteranceRef.current.rate = newRate
|
||||||
}
|
}
|
||||||
}, [supported, synth, createUtterance])
|
}, [supported, synth, createUtterance])
|
||||||
|
|||||||
72
src/main.tsx
72
src/main.tsx
@@ -6,16 +6,59 @@ import './index.css'
|
|||||||
import 'react-loading-skeleton/dist/skeleton.css'
|
import 'react-loading-skeleton/dist/skeleton.css'
|
||||||
|
|
||||||
// Register Service Worker for PWA functionality
|
// Register Service Worker for PWA functionality
|
||||||
|
// With injectRegister: null, we need to register manually
|
||||||
|
// With devOptions.enabled: true, vite-plugin-pwa serves SW in dev mode too
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
navigator.serviceWorker
|
const swPath = '/sw.js'
|
||||||
.register('/sw.js', { type: 'module' })
|
|
||||||
|
// Check if already registered/active first
|
||||||
|
navigator.serviceWorker.getRegistrations().then(async (registrations) => {
|
||||||
|
if (registrations.length > 0) {
|
||||||
|
return registrations[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not registered yet, try to register
|
||||||
|
// In dev mode, use the dev Service Worker for testing
|
||||||
|
if (import.meta.env.DEV) {
|
||||||
|
const devSwPath = '/sw-dev.js'
|
||||||
|
try {
|
||||||
|
// Check if dev SW exists
|
||||||
|
const response = await fetch(devSwPath)
|
||||||
|
const contentType = response.headers.get('content-type') || ''
|
||||||
|
const isJavaScript = contentType.includes('javascript') || contentType.includes('application/javascript')
|
||||||
|
|
||||||
|
if (response.ok && isJavaScript) {
|
||||||
|
return await navigator.serviceWorker.register(devSwPath, { scope: '/' })
|
||||||
|
} else {
|
||||||
|
console.warn('[sw-registration] Development Service Worker not available')
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('[sw-registration] Could not load development Service Worker:', err)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// In production, just register directly
|
||||||
|
return await navigator.serviceWorker.register(swPath)
|
||||||
|
}
|
||||||
|
})
|
||||||
.then(registration => {
|
.then(registration => {
|
||||||
|
if (!registration) return
|
||||||
|
|
||||||
// Check for updates periodically
|
// Wait for Service Worker to activate
|
||||||
setInterval(() => {
|
if (registration.installing) {
|
||||||
registration.update()
|
registration.installing.addEventListener('statechange', () => {
|
||||||
}, 60 * 60 * 1000) // Check every hour
|
// Service Worker state changed
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for updates periodically (production only)
|
||||||
|
if (import.meta.env.PROD) {
|
||||||
|
setInterval(() => {
|
||||||
|
registration.update()
|
||||||
|
}, 60 * 60 * 1000) // Check every hour
|
||||||
|
}
|
||||||
|
|
||||||
// Handle service worker updates
|
// Handle service worker updates
|
||||||
registration.addEventListener('updatefound', () => {
|
registration.addEventListener('updatefound', () => {
|
||||||
@@ -24,8 +67,6 @@ if ('serviceWorker' in navigator) {
|
|||||||
newWorker.addEventListener('statechange', () => {
|
newWorker.addEventListener('statechange', () => {
|
||||||
if (newWorker.state === 'installed' && navigator.serviceWorker.controller) {
|
if (newWorker.state === 'installed' && navigator.serviceWorker.controller) {
|
||||||
// New service worker available
|
// New service worker available
|
||||||
|
|
||||||
// Optionally show a toast notification
|
|
||||||
const updateAvailable = new CustomEvent('sw-update-available')
|
const updateAvailable = new CustomEvent('sw-update-available')
|
||||||
window.dispatchEvent(updateAvailable)
|
window.dispatchEvent(updateAvailable)
|
||||||
}
|
}
|
||||||
@@ -34,9 +75,22 @@ if ('serviceWorker' in navigator) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('❌ Service Worker registration failed:', error)
|
console.error('[sw-registration] ❌ Service Worker registration failed:', error)
|
||||||
|
console.error('[sw-registration] Error details:', {
|
||||||
|
message: error.message,
|
||||||
|
name: error.name,
|
||||||
|
stack: error.stack
|
||||||
|
})
|
||||||
|
|
||||||
|
// In dev mode, this is expected if vite-plugin-pwa isn't serving the SW
|
||||||
|
if (import.meta.env.DEV) {
|
||||||
|
console.warn('[sw-registration] ⚠️ This is expected in dev mode if vite-plugin-pwa is not serving the SW file')
|
||||||
|
console.warn('[sw-registration] Image caching will not work in dev mode - test in production build')
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
console.warn('[sw-registration] ⚠️ Service Workers not supported in this browser')
|
||||||
}
|
}
|
||||||
|
|
||||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||||
|
|||||||
@@ -34,11 +34,13 @@ function getCacheKey(naddr: string): string {
|
|||||||
return `${CACHE_PREFIX}${naddr}`
|
return `${CACHE_PREFIX}${naddr}`
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFromCache(naddr: string): ArticleContent | null {
|
export function getFromCache(naddr: string): ArticleContent | null {
|
||||||
try {
|
try {
|
||||||
const cacheKey = getCacheKey(naddr)
|
const cacheKey = getCacheKey(naddr)
|
||||||
const cached = localStorage.getItem(cacheKey)
|
const cached = localStorage.getItem(cacheKey)
|
||||||
if (!cached) return null
|
if (!cached) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
const { content, timestamp }: CachedArticle = JSON.parse(cached)
|
const { content, timestamp }: CachedArticle = JSON.parse(cached)
|
||||||
const age = Date.now() - timestamp
|
const age = Date.now() - timestamp
|
||||||
@@ -49,12 +51,51 @@ function getFromCache(naddr: string): ArticleContent | null {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return content
|
return content
|
||||||
} catch {
|
} catch (err) {
|
||||||
|
// Silently handle cache read errors
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveToCache(naddr: string, content: ArticleContent): void {
|
/**
|
||||||
|
* Caches an article event to localStorage for offline access
|
||||||
|
* @param event - The Nostr event to cache
|
||||||
|
* @param settings - Optional user settings
|
||||||
|
*/
|
||||||
|
export function cacheArticleEvent(event: NostrEvent, settings?: UserSettings): void {
|
||||||
|
try {
|
||||||
|
const dTag = event.tags.find(t => t[0] === 'd')?.[1] || ''
|
||||||
|
if (!dTag || event.kind !== 30023) return
|
||||||
|
|
||||||
|
const naddr = nip19.naddrEncode({
|
||||||
|
kind: 30023,
|
||||||
|
pubkey: event.pubkey,
|
||||||
|
identifier: dTag
|
||||||
|
})
|
||||||
|
|
||||||
|
const articleContent: ArticleContent = {
|
||||||
|
title: getArticleTitle(event) || 'Untitled Article',
|
||||||
|
markdown: event.content,
|
||||||
|
image: getArticleImage(event),
|
||||||
|
published: getArticlePublished(event),
|
||||||
|
summary: getArticleSummary(event),
|
||||||
|
author: event.pubkey,
|
||||||
|
event
|
||||||
|
}
|
||||||
|
|
||||||
|
saveToCache(naddr, articleContent, settings)
|
||||||
|
} catch (err) {
|
||||||
|
// Silently fail cache saves - quota exceeded, invalid data, etc.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function saveToCache(naddr: string, content: ArticleContent, settings?: UserSettings): void {
|
||||||
|
// Respect user settings: if image caching is disabled, we could skip article caching too
|
||||||
|
// However, for offline-first design, we default to caching unless explicitly disabled
|
||||||
|
// Future: could add explicit enableArticleCache setting
|
||||||
|
// For now, we cache aggressively but handle errors gracefully
|
||||||
|
// Note: settings parameter reserved for future use
|
||||||
|
void settings // Mark as intentionally unused for now
|
||||||
try {
|
try {
|
||||||
const cacheKey = getCacheKey(naddr)
|
const cacheKey = getCacheKey(naddr)
|
||||||
const cached: CachedArticle = {
|
const cached: CachedArticle = {
|
||||||
@@ -63,8 +104,8 @@ function saveToCache(naddr: string, content: ArticleContent): void {
|
|||||||
}
|
}
|
||||||
localStorage.setItem(cacheKey, JSON.stringify(cached))
|
localStorage.setItem(cacheKey, JSON.stringify(cached))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn('Failed to cache article:', err)
|
// Silently fail - don't block the UI if caching fails
|
||||||
// Silently fail if storage is full or unavailable
|
// Handles quota exceeded, invalid data, and other errors gracefully
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,10 +138,10 @@ export async function fetchArticleByNaddr(
|
|||||||
|
|
||||||
const pointer = decoded.data as AddressPointer
|
const pointer = decoded.data as AddressPointer
|
||||||
|
|
||||||
// Define relays to query - prefer relays from naddr, fallback to configured relays (including local)
|
// Define relays to query - use union of relay hints from naddr and configured relays
|
||||||
const baseRelays = pointer.relays && pointer.relays.length > 0
|
// This avoids failures when naddr contains stale/unreachable relay hints
|
||||||
? pointer.relays
|
const hintedRelays = (pointer.relays && pointer.relays.length > 0) ? pointer.relays : []
|
||||||
: RELAYS
|
const baseRelays = Array.from(new Set<string>([...hintedRelays, ...RELAYS]))
|
||||||
const orderedRelays = prioritizeLocalRelays(baseRelays)
|
const orderedRelays = prioritizeLocalRelays(baseRelays)
|
||||||
const { local: localRelays, remote: remoteRelays } = partitionRelays(orderedRelays)
|
const { local: localRelays, remote: remoteRelays } = partitionRelays(orderedRelays)
|
||||||
|
|
||||||
@@ -114,7 +155,28 @@ export async function fetchArticleByNaddr(
|
|||||||
// Parallel local+remote, stream immediate, collect up to first from each
|
// Parallel local+remote, stream immediate, collect up to first from each
|
||||||
const { local$, remote$ } = createParallelReqStreams(relayPool, localRelays, remoteRelays, filter, 1200, 6000)
|
const { local$, remote$ } = createParallelReqStreams(relayPool, localRelays, remoteRelays, filter, 1200, 6000)
|
||||||
const collected = await lastValueFrom(merge(local$.pipe(take(1)), remote$.pipe(take(1))).pipe(rxToArray()))
|
const collected = await lastValueFrom(merge(local$.pipe(take(1)), remote$.pipe(take(1))).pipe(rxToArray()))
|
||||||
const events = collected as NostrEvent[]
|
let events = collected as NostrEvent[]
|
||||||
|
|
||||||
|
// Fallback: if nothing found, try a second round against a set of reliable public relays
|
||||||
|
if (events.length === 0) {
|
||||||
|
const reliableRelays = Array.from(new Set<string>([
|
||||||
|
'wss://relay.nostr.band',
|
||||||
|
'wss://relay.primal.net',
|
||||||
|
'wss://relay.damus.io',
|
||||||
|
'wss://nos.lol',
|
||||||
|
...remoteRelays // keep any configured remote relays
|
||||||
|
]))
|
||||||
|
const { remote$: fallback$ } = createParallelReqStreams(
|
||||||
|
relayPool,
|
||||||
|
[], // no local
|
||||||
|
reliableRelays,
|
||||||
|
filter,
|
||||||
|
1500,
|
||||||
|
12000
|
||||||
|
)
|
||||||
|
const fallbackCollected = await lastValueFrom(fallback$.pipe(take(1), rxToArray()))
|
||||||
|
events = fallbackCollected as NostrEvent[]
|
||||||
|
}
|
||||||
|
|
||||||
if (events.length === 0) {
|
if (events.length === 0) {
|
||||||
throw new Error('Article not found')
|
throw new Error('Article not found')
|
||||||
@@ -143,7 +205,7 @@ export async function fetchArticleByNaddr(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save to cache before returning
|
// Save to cache before returning
|
||||||
saveToCache(naddr, content)
|
saveToCache(naddr, content, settings)
|
||||||
|
|
||||||
// Image caching is handled automatically by Service Worker
|
// Image caching is handled automatically by Service Worker
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,8 @@
|
|||||||
import { RelayPool } from 'applesauce-relay'
|
import { RelayPool } from 'applesauce-relay'
|
||||||
import { Helpers, EventStore } from 'applesauce-core'
|
import { Helpers, EventStore } from 'applesauce-core'
|
||||||
import { createEventLoader, createAddressLoader } from 'applesauce-loaders/loaders'
|
|
||||||
import { NostrEvent } from 'nostr-tools'
|
import { NostrEvent } from 'nostr-tools'
|
||||||
import { EventPointer } from 'nostr-tools/nip19'
|
|
||||||
import { from } from 'rxjs'
|
|
||||||
import { mergeMap } from 'rxjs/operators'
|
|
||||||
import { queryEvents } from './dataFetch'
|
import { queryEvents } from './dataFetch'
|
||||||
import { KINDS } from '../config/kinds'
|
import { KINDS } from '../config/kinds'
|
||||||
import { RELAYS } from '../config/relays'
|
|
||||||
import { collectBookmarksFromEvents } from './bookmarkProcessing'
|
import { collectBookmarksFromEvents } from './bookmarkProcessing'
|
||||||
import { Bookmark, IndividualBookmark } from '../types/bookmarks'
|
import { Bookmark, IndividualBookmark } from '../types/bookmarks'
|
||||||
import {
|
import {
|
||||||
@@ -65,12 +60,8 @@ class BookmarkController {
|
|||||||
}> = new Map()
|
}> = new Map()
|
||||||
private isLoading = false
|
private isLoading = false
|
||||||
private hydrationGeneration = 0
|
private hydrationGeneration = 0
|
||||||
|
|
||||||
// Event loaders for efficient batching
|
|
||||||
private eventStore = new EventStore()
|
|
||||||
private eventLoader: ReturnType<typeof createEventLoader> | null = null
|
|
||||||
private addressLoader: ReturnType<typeof createAddressLoader> | null = null
|
|
||||||
private externalEventStore: EventStore | null = null
|
private externalEventStore: EventStore | null = null
|
||||||
|
private relayPool: RelayPool | null = null
|
||||||
|
|
||||||
onRawEvent(cb: RawEventCallback): () => void {
|
onRawEvent(cb: RawEventCallback): () => void {
|
||||||
this.rawEventListeners.push(cb)
|
this.rawEventListeners.push(cb)
|
||||||
@@ -119,15 +110,15 @@ class BookmarkController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hydrate events by IDs using EventLoader (auto-batching, streaming)
|
* Hydrate events by IDs using queryEvents (local-first, streaming)
|
||||||
*/
|
*/
|
||||||
private hydrateByIds(
|
private async hydrateByIds(
|
||||||
ids: string[],
|
ids: string[],
|
||||||
idToEvent: Map<string, NostrEvent>,
|
idToEvent: Map<string, NostrEvent>,
|
||||||
onProgress: () => void,
|
onProgress: () => void,
|
||||||
generation: number
|
generation: number
|
||||||
): void {
|
): Promise<void> {
|
||||||
if (!this.eventLoader) {
|
if (!this.relayPool) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,86 +128,146 @@ class BookmarkController {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert IDs to EventPointers
|
// Fetch events using local-first queryEvents
|
||||||
const pointers: EventPointer[] = unique.map(id => ({ id }))
|
await queryEvents(
|
||||||
|
this.relayPool,
|
||||||
// Use mergeMap with concurrency limit instead of merge to properly batch requests
|
{ ids: unique },
|
||||||
// This prevents overwhelming relays with 96+ simultaneous requests
|
{
|
||||||
from(pointers).pipe(
|
onEvent: (event) => {
|
||||||
mergeMap(pointer => this.eventLoader!(pointer), 5)
|
// Check if hydration was cancelled
|
||||||
).subscribe({
|
if (this.hydrationGeneration !== generation) return
|
||||||
next: (event) => {
|
|
||||||
// Check if hydration was cancelled
|
idToEvent.set(event.id, event)
|
||||||
if (this.hydrationGeneration !== generation) return
|
|
||||||
|
// Also index by coordinate for addressable events
|
||||||
idToEvent.set(event.id, event)
|
if (event.kind && event.kind >= 30000 && event.kind < 40000) {
|
||||||
|
const dTag = event.tags?.find((t: string[]) => t[0] === 'd')?.[1] || ''
|
||||||
// Also index by coordinate for addressable events
|
const coordinate = `${event.kind}:${event.pubkey}:${dTag}`
|
||||||
if (event.kind && event.kind >= 30000 && event.kind < 40000) {
|
idToEvent.set(coordinate, event)
|
||||||
const dTag = event.tags?.find((t: string[]) => t[0] === 'd')?.[1] || ''
|
}
|
||||||
const coordinate = `${event.kind}:${event.pubkey}:${dTag}`
|
|
||||||
idToEvent.set(coordinate, event)
|
// Add to external event store if available
|
||||||
|
if (this.externalEventStore) {
|
||||||
|
this.externalEventStore.add(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
onProgress()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to external event store if available
|
|
||||||
if (this.externalEventStore) {
|
|
||||||
this.externalEventStore.add(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
onProgress()
|
|
||||||
},
|
|
||||||
error: () => {
|
|
||||||
// Silent error - EventLoader handles retries
|
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hydrate addressable events by coordinates using AddressLoader (auto-batching, streaming)
|
* Hydrate addressable events by coordinates using queryEvents (local-first, streaming)
|
||||||
*/
|
*/
|
||||||
private hydrateByCoordinates(
|
private async hydrateByCoordinates(
|
||||||
coords: Array<{ kind: number; pubkey: string; identifier: string }>,
|
coords: Array<{ kind: number; pubkey: string; identifier: string }>,
|
||||||
idToEvent: Map<string, NostrEvent>,
|
idToEvent: Map<string, NostrEvent>,
|
||||||
onProgress: () => void,
|
onProgress: () => void,
|
||||||
generation: number
|
generation: number
|
||||||
): void {
|
): Promise<void> {
|
||||||
if (!this.addressLoader) {
|
if (!this.relayPool) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (coords.length === 0) return
|
if (coords.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Convert coordinates to AddressPointers
|
// Group by kind and pubkey for efficient batching
|
||||||
const pointers = coords.map(c => ({
|
const filtersByKind = new Map<number, Map<string, string[]>>()
|
||||||
kind: c.kind,
|
|
||||||
pubkey: c.pubkey,
|
for (const coord of coords) {
|
||||||
identifier: c.identifier
|
if (!filtersByKind.has(coord.kind)) {
|
||||||
}))
|
filtersByKind.set(coord.kind, new Map())
|
||||||
|
}
|
||||||
|
const byPubkey = filtersByKind.get(coord.kind)!
|
||||||
|
if (!byPubkey.has(coord.pubkey)) {
|
||||||
|
byPubkey.set(coord.pubkey, [])
|
||||||
|
}
|
||||||
|
byPubkey.get(coord.pubkey)!.push(coord.identifier || '')
|
||||||
|
}
|
||||||
|
|
||||||
// Use mergeMap with concurrency limit instead of merge to properly batch requests
|
// Kick off all queries in parallel (fire-and-forget)
|
||||||
from(pointers).pipe(
|
const promises: Promise<void>[] = []
|
||||||
mergeMap(pointer => this.addressLoader!(pointer), 5)
|
|
||||||
).subscribe({
|
for (const [kind, byPubkey] of filtersByKind) {
|
||||||
next: (event) => {
|
for (const [pubkey, identifiers] of byPubkey) {
|
||||||
// Check if hydration was cancelled
|
// Separate empty and non-empty identifiers
|
||||||
if (this.hydrationGeneration !== generation) return
|
const nonEmptyIdentifiers = identifiers.filter(id => id && id.length > 0)
|
||||||
|
const hasEmptyIdentifier = identifiers.some(id => !id || id.length === 0)
|
||||||
const dTag = event.tags?.find((t: string[]) => t[0] === 'd')?.[1] || ''
|
|
||||||
const coordinate = `${event.kind}:${event.pubkey}:${dTag}`
|
|
||||||
idToEvent.set(coordinate, event)
|
|
||||||
idToEvent.set(event.id, event)
|
|
||||||
|
|
||||||
// Add to external event store if available
|
// Fetch events with non-empty d-tags
|
||||||
if (this.externalEventStore) {
|
if (nonEmptyIdentifiers.length > 0) {
|
||||||
this.externalEventStore.add(event)
|
promises.push(
|
||||||
|
queryEvents(
|
||||||
|
this.relayPool,
|
||||||
|
{ kinds: [kind], authors: [pubkey], '#d': nonEmptyIdentifiers },
|
||||||
|
{
|
||||||
|
onEvent: (event) => {
|
||||||
|
// Check if hydration was cancelled
|
||||||
|
if (this.hydrationGeneration !== generation) return
|
||||||
|
|
||||||
|
const dTag = event.tags?.find((t: string[]) => t[0] === 'd')?.[1] || ''
|
||||||
|
const coordinate = `${event.kind}:${event.pubkey}:${dTag}`
|
||||||
|
idToEvent.set(coordinate, event)
|
||||||
|
idToEvent.set(event.id, event)
|
||||||
|
|
||||||
|
// Add to external event store if available
|
||||||
|
if (this.externalEventStore) {
|
||||||
|
this.externalEventStore.add(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
onProgress()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
).then(() => {
|
||||||
|
// Query completed successfully
|
||||||
|
}).catch(() => {
|
||||||
|
// Silent error - individual query failed
|
||||||
|
})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
onProgress()
|
// Fetch events with empty d-tag separately (without '#d' filter)
|
||||||
},
|
if (hasEmptyIdentifier) {
|
||||||
error: () => {
|
promises.push(
|
||||||
// Silent error - AddressLoader handles retries
|
queryEvents(
|
||||||
|
this.relayPool,
|
||||||
|
{ kinds: [kind], authors: [pubkey] },
|
||||||
|
{
|
||||||
|
onEvent: (event) => {
|
||||||
|
// Check if hydration was cancelled
|
||||||
|
if (this.hydrationGeneration !== generation) return
|
||||||
|
|
||||||
|
// Only process events with empty d-tag
|
||||||
|
const dTag = event.tags?.find((t: string[]) => t[0] === 'd')?.[1] || ''
|
||||||
|
if (dTag !== '') return
|
||||||
|
|
||||||
|
const coordinate = `${event.kind}:${event.pubkey}:`
|
||||||
|
idToEvent.set(coordinate, event)
|
||||||
|
idToEvent.set(event.id, event)
|
||||||
|
|
||||||
|
// Add to external event store if available
|
||||||
|
if (this.externalEventStore) {
|
||||||
|
this.externalEventStore.add(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
onProgress()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
).then(() => {
|
||||||
|
// Query completed successfully
|
||||||
|
}).catch(() => {
|
||||||
|
// Silent error - individual query failed
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
// Wait for all queries to complete
|
||||||
|
await Promise.all(promises)
|
||||||
}
|
}
|
||||||
|
|
||||||
private async buildAndEmitBookmarks(
|
private async buildAndEmitBookmarks(
|
||||||
@@ -279,8 +330,6 @@ class BookmarkController {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(`📋 Requesting hydration for: ${noteIds.length} note IDs, ${coordinates.length} coordinates`)
|
|
||||||
|
|
||||||
// Helper to build and emit bookmarks
|
// Helper to build and emit bookmarks
|
||||||
const emitBookmarks = (idToEvent: Map<string, NostrEvent>) => {
|
const emitBookmarks = (idToEvent: Map<string, NostrEvent>) => {
|
||||||
// Now hydrate the ORIGINAL items (which may have duplicates), using the deduplicated results
|
// Now hydrate the ORIGINAL items (which may have duplicates), using the deduplicated results
|
||||||
@@ -293,22 +342,28 @@ class BookmarkController {
|
|||||||
const enriched = allBookmarks.map(b => ({
|
const enriched = allBookmarks.map(b => ({
|
||||||
...b,
|
...b,
|
||||||
tags: b.tags || [],
|
tags: b.tags || [],
|
||||||
// Prefer hydrated content; fallback to any cached event content in external store
|
content: b.content || this.externalEventStore?.getEvent(b.id)?.content || '', // Fallback to eventStore content
|
||||||
content: b.content && b.content.length > 0
|
created_at: (b.created_at ?? this.externalEventStore?.getEvent(b.id)?.created_at ?? null)
|
||||||
? b.content
|
|
||||||
: (this.externalEventStore?.getEvent(b.id)?.content || '')
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const sortedBookmarks = enriched
|
const sortedBookmarks = enriched
|
||||||
.map(b => ({ ...b, urlReferences: extractUrlsFromContent(b.content) }))
|
.map(b => ({
|
||||||
.sort((a, b) => ((b.added_at || 0) - (a.added_at || 0)) || ((b.created_at || 0) - (a.created_at || 0)))
|
...b,
|
||||||
|
urlReferences: extractUrlsFromContent(b.content)
|
||||||
|
}))
|
||||||
|
.sort((a, b) => {
|
||||||
|
// Sort by display time: created_at, else listUpdatedAt. Newest first. Nulls last.
|
||||||
|
const aTs = (a.created_at ?? a.listUpdatedAt ?? -Infinity)
|
||||||
|
const bTs = (b.created_at ?? b.listUpdatedAt ?? -Infinity)
|
||||||
|
return bTs - aTs
|
||||||
|
})
|
||||||
|
|
||||||
const bookmark: Bookmark = {
|
const bookmark: Bookmark = {
|
||||||
id: `${activeAccount.pubkey}-bookmarks`,
|
id: `${activeAccount.pubkey}-bookmarks`,
|
||||||
title: `Bookmarks (${sortedBookmarks.length})`,
|
title: `Bookmarks (${sortedBookmarks.length})`,
|
||||||
url: '',
|
url: '',
|
||||||
content: latestContent,
|
content: latestContent,
|
||||||
created_at: newestCreatedAt || Math.floor(Date.now() / 1000),
|
created_at: newestCreatedAt || 0,
|
||||||
tags: allTags,
|
tags: allTags,
|
||||||
bookmarkCount: sortedBookmarks.length,
|
bookmarkCount: sortedBookmarks.length,
|
||||||
eventReferences: allTags.filter((tag: string[]) => tag[0] === 'e').map((tag: string[]) => tag[1]),
|
eventReferences: allTags.filter((tag: string[]) => tag[0] === 'e').map((tag: string[]) => tag[1]),
|
||||||
@@ -324,7 +379,7 @@ class BookmarkController {
|
|||||||
const idToEvent: Map<string, NostrEvent> = new Map()
|
const idToEvent: Map<string, NostrEvent> = new Map()
|
||||||
emitBookmarks(idToEvent)
|
emitBookmarks(idToEvent)
|
||||||
|
|
||||||
// Now fetch events progressively in background using batched hydrators
|
// Now fetch events progressively in background using local-first queries
|
||||||
|
|
||||||
const generation = this.hydrationGeneration
|
const generation = this.hydrationGeneration
|
||||||
const onProgress = () => emitBookmarks(idToEvent)
|
const onProgress = () => emitBookmarks(idToEvent)
|
||||||
@@ -339,10 +394,14 @@ class BookmarkController {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Kick off batched hydration (streaming, non-blocking)
|
// Kick off hydration (streaming, non-blocking, local-first)
|
||||||
// EventLoader and AddressLoader handle batching and streaming automatically
|
// Fire-and-forget - don't await, let it run in background
|
||||||
this.hydrateByIds(noteIds, idToEvent, onProgress, generation)
|
this.hydrateByIds(noteIds, idToEvent, onProgress, generation).catch(() => {
|
||||||
this.hydrateByCoordinates(coordObjs, idToEvent, onProgress, generation)
|
// Silent error - hydration will retry or show partial results
|
||||||
|
})
|
||||||
|
this.hydrateByCoordinates(coordObjs, idToEvent, onProgress, generation).catch(() => {
|
||||||
|
// Silent error - hydration will retry or show partial results
|
||||||
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to build bookmarks:', error)
|
console.error('Failed to build bookmarks:', error)
|
||||||
this.bookmarksListeners.forEach(cb => cb([]))
|
this.bookmarksListeners.forEach(cb => cb([]))
|
||||||
@@ -357,7 +416,8 @@ class BookmarkController {
|
|||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
const { relayPool, activeAccount, accountManager, eventStore } = options
|
const { relayPool, activeAccount, accountManager, eventStore } = options
|
||||||
|
|
||||||
// Store the external event store reference for adding hydrated events
|
// Store references for hydration
|
||||||
|
this.relayPool = relayPool
|
||||||
this.externalEventStore = eventStore || null
|
this.externalEventStore = eventStore || null
|
||||||
|
|
||||||
if (!activeAccount || typeof (activeAccount as { pubkey?: string }).pubkey !== 'string') {
|
if (!activeAccount || typeof (activeAccount as { pubkey?: string }).pubkey !== 'string') {
|
||||||
@@ -369,16 +429,6 @@ class BookmarkController {
|
|||||||
// Increment generation to cancel any in-flight hydration
|
// Increment generation to cancel any in-flight hydration
|
||||||
this.hydrationGeneration++
|
this.hydrationGeneration++
|
||||||
|
|
||||||
// Initialize loaders for this session
|
|
||||||
this.eventLoader = createEventLoader(relayPool, {
|
|
||||||
eventStore: this.eventStore,
|
|
||||||
extraRelays: RELAYS
|
|
||||||
})
|
|
||||||
this.addressLoader = createAddressLoader(relayPool, {
|
|
||||||
eventStore: this.eventStore,
|
|
||||||
extraRelays: RELAYS
|
|
||||||
})
|
|
||||||
|
|
||||||
this.setLoading(true)
|
this.setLoading(true)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -15,28 +15,30 @@ export function dedupeNip51Events(events: NostrEvent[]): NostrEvent[] {
|
|||||||
}
|
}
|
||||||
const unique = Array.from(byId.values())
|
const unique = Array.from(byId.values())
|
||||||
|
|
||||||
// Separate web bookmarks (kind:39701) from list-based bookmarks
|
|
||||||
const webBookmarks = unique.filter(e => e.kind === 39701)
|
|
||||||
|
|
||||||
const bookmarkLists = unique
|
const bookmarkLists = unique
|
||||||
.filter(e => e.kind === 10003 || e.kind === 30003 || e.kind === 30001)
|
.filter(e => e.kind === 10003 || e.kind === 30003 || e.kind === 30001)
|
||||||
.sort((a, b) => (b.created_at || 0) - (a.created_at || 0))
|
.sort((a, b) => (b.created_at || 0) - (a.created_at || 0))
|
||||||
const latestBookmarkList = bookmarkLists.find(list => !list.tags?.some((t: string[]) => t[0] === 'd'))
|
const latestBookmarkList = bookmarkLists.find(list => !list.tags?.some((t: string[]) => t[0] === 'd'))
|
||||||
|
|
||||||
|
// Deduplicate replaceable events (kind:30003, 30001, 39701) by d-tag
|
||||||
const byD = new Map<string, NostrEvent>()
|
const byD = new Map<string, NostrEvent>()
|
||||||
for (const e of unique) {
|
for (const e of unique) {
|
||||||
if (e.kind === 10003 || e.kind === 30003 || e.kind === 30001) {
|
if (e.kind === 10003 || e.kind === 30003 || e.kind === 30001 || e.kind === 39701) {
|
||||||
const d = (e.tags || []).find((t: string[]) => t[0] === 'd')?.[1] || ''
|
const d = (e.tags || []).find((t: string[]) => t[0] === 'd')?.[1] || ''
|
||||||
const prev = byD.get(d)
|
const prev = byD.get(d)
|
||||||
if (!prev || (e.created_at || 0) > (prev.created_at || 0)) byD.set(d, e)
|
if (!prev || (e.created_at || 0) > (prev.created_at || 0)) byD.set(d, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const setsAndNamedLists = Array.from(byD.values())
|
// Separate web bookmarks from bookmark sets/lists
|
||||||
|
const allReplaceable = Array.from(byD.values())
|
||||||
|
const webBookmarks = allReplaceable.filter(e => e.kind === 39701)
|
||||||
|
const setsAndNamedLists = allReplaceable.filter(e => e.kind !== 39701)
|
||||||
|
|
||||||
const out: NostrEvent[] = []
|
const out: NostrEvent[] = []
|
||||||
if (latestBookmarkList) out.push(latestBookmarkList)
|
if (latestBookmarkList) out.push(latestBookmarkList)
|
||||||
out.push(...setsAndNamedLists)
|
out.push(...setsAndNamedLists)
|
||||||
// Add web bookmarks as individual events
|
// Add deduplicated web bookmarks as individual events
|
||||||
out.push(...webBookmarks)
|
out.push(...webBookmarks)
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,12 +21,16 @@ export interface AddressPointer {
|
|||||||
pubkey: string
|
pubkey: string
|
||||||
identifier: string
|
identifier: string
|
||||||
relays?: string[]
|
relays?: string[]
|
||||||
|
added_at?: number
|
||||||
|
created_at?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EventPointer {
|
export interface EventPointer {
|
||||||
id: string
|
id: string
|
||||||
relays?: string[]
|
relays?: string[]
|
||||||
author?: string
|
author?: string
|
||||||
|
added_at?: number
|
||||||
|
created_at?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApplesauceBookmarks {
|
export interface ApplesauceBookmarks {
|
||||||
@@ -77,14 +81,14 @@ export const processApplesauceBookmarks = (
|
|||||||
allItems.push({
|
allItems.push({
|
||||||
id: note.id,
|
id: note.id,
|
||||||
content: '',
|
content: '',
|
||||||
created_at: parentCreatedAt || 0,
|
created_at: note.created_at ?? null,
|
||||||
pubkey: note.author || activeAccount.pubkey,
|
pubkey: note.author || activeAccount.pubkey,
|
||||||
kind: 1, // Short note kind
|
kind: 1, // Short note kind
|
||||||
tags: [],
|
tags: [],
|
||||||
parsedContent: undefined,
|
parsedContent: undefined,
|
||||||
type: 'event' as const,
|
type: 'event' as const,
|
||||||
isPrivate,
|
isPrivate,
|
||||||
added_at: parentCreatedAt || 0
|
listUpdatedAt: parentCreatedAt || 0
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -97,14 +101,14 @@ export const processApplesauceBookmarks = (
|
|||||||
allItems.push({
|
allItems.push({
|
||||||
id: coordinate,
|
id: coordinate,
|
||||||
content: '',
|
content: '',
|
||||||
created_at: parentCreatedAt || 0,
|
created_at: article.created_at ?? null,
|
||||||
pubkey: article.pubkey,
|
pubkey: article.pubkey,
|
||||||
kind: article.kind, // Usually 30023 for long-form articles
|
kind: article.kind, // Usually 30023 for long-form articles
|
||||||
tags: [],
|
tags: [],
|
||||||
parsedContent: undefined,
|
parsedContent: undefined,
|
||||||
type: 'event' as const,
|
type: 'event' as const,
|
||||||
isPrivate,
|
isPrivate,
|
||||||
added_at: parentCreatedAt || 0
|
listUpdatedAt: parentCreatedAt ?? null
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -115,14 +119,14 @@ export const processApplesauceBookmarks = (
|
|||||||
allItems.push({
|
allItems.push({
|
||||||
id: `hashtag-${hashtag}`,
|
id: `hashtag-${hashtag}`,
|
||||||
content: `#${hashtag}`,
|
content: `#${hashtag}`,
|
||||||
created_at: parentCreatedAt || 0,
|
created_at: 0, // Hashtags don't have their own creation time
|
||||||
pubkey: activeAccount.pubkey,
|
pubkey: activeAccount.pubkey,
|
||||||
kind: 1,
|
kind: 1,
|
||||||
tags: [['t', hashtag]],
|
tags: [['t', hashtag]],
|
||||||
parsedContent: undefined,
|
parsedContent: undefined,
|
||||||
type: 'event' as const,
|
type: 'event' as const,
|
||||||
isPrivate,
|
isPrivate,
|
||||||
added_at: parentCreatedAt || 0
|
listUpdatedAt: parentCreatedAt ?? null
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -133,14 +137,14 @@ export const processApplesauceBookmarks = (
|
|||||||
allItems.push({
|
allItems.push({
|
||||||
id: `url-${url}`,
|
id: `url-${url}`,
|
||||||
content: url,
|
content: url,
|
||||||
created_at: parentCreatedAt || 0,
|
created_at: 0, // URLs don't have their own creation time
|
||||||
pubkey: activeAccount.pubkey,
|
pubkey: activeAccount.pubkey,
|
||||||
kind: 1,
|
kind: 1,
|
||||||
tags: [['r', url]],
|
tags: [['r', url]],
|
||||||
parsedContent: undefined,
|
parsedContent: undefined,
|
||||||
type: 'event' as const,
|
type: 'event' as const,
|
||||||
isPrivate,
|
isPrivate,
|
||||||
added_at: parentCreatedAt || 0
|
listUpdatedAt: parentCreatedAt || 0
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -149,20 +153,24 @@ export const processApplesauceBookmarks = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
const bookmarkArray = Array.isArray(bookmarks) ? bookmarks : [bookmarks]
|
const bookmarkArray = Array.isArray(bookmarks) ? bookmarks : [bookmarks]
|
||||||
return bookmarkArray
|
const processed = bookmarkArray
|
||||||
.filter((bookmark: BookmarkData) => bookmark.id) // Skip bookmarks without valid IDs
|
.filter((bookmark: BookmarkData) => bookmark.id) // Skip bookmarks without valid IDs
|
||||||
.map((bookmark: BookmarkData) => ({
|
.map((bookmark: BookmarkData) => {
|
||||||
id: bookmark.id!,
|
return {
|
||||||
content: bookmark.content || '',
|
id: bookmark.id!,
|
||||||
created_at: bookmark.created_at || parentCreatedAt || 0,
|
content: bookmark.content || '',
|
||||||
pubkey: activeAccount.pubkey,
|
created_at: bookmark.created_at ?? null,
|
||||||
kind: bookmark.kind || 30001,
|
pubkey: activeAccount.pubkey,
|
||||||
tags: bookmark.tags || [],
|
kind: bookmark.kind || 30001,
|
||||||
parsedContent: bookmark.content ? (getParsedContent(bookmark.content) as ParsedContent) : undefined,
|
tags: bookmark.tags || [],
|
||||||
type: 'event' as const,
|
parsedContent: bookmark.content ? (getParsedContent(bookmark.content) as ParsedContent) : undefined,
|
||||||
isPrivate,
|
type: 'event' as const,
|
||||||
added_at: bookmark.created_at || parentCreatedAt || 0
|
isPrivate,
|
||||||
}))
|
listUpdatedAt: parentCreatedAt ?? null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return processed
|
||||||
}
|
}
|
||||||
|
|
||||||
// Types and guards around signer/decryption APIs
|
// Types and guards around signer/decryption APIs
|
||||||
|
|||||||
@@ -133,29 +133,36 @@ export async function collectBookmarksFromEvents(
|
|||||||
|
|
||||||
// Handle web bookmarks (kind:39701) as individual bookmarks
|
// Handle web bookmarks (kind:39701) as individual bookmarks
|
||||||
if (evt.kind === 39701) {
|
if (evt.kind === 39701) {
|
||||||
|
// Use coordinate format for web bookmarks to enable proper deduplication
|
||||||
|
// Web bookmarks are replaceable events (kind:39701:pubkey:d-tag)
|
||||||
|
const webBookmarkId = dTag ? `${evt.kind}:${evt.pubkey}:${dTag}` : evt.id
|
||||||
|
|
||||||
publicItemsAll.push({
|
publicItemsAll.push({
|
||||||
id: evt.id,
|
id: webBookmarkId,
|
||||||
content: evt.content || '',
|
content: evt.content || '',
|
||||||
created_at: evt.created_at || Math.floor(Date.now() / 1000),
|
created_at: evt.created_at ?? null,
|
||||||
pubkey: evt.pubkey,
|
pubkey: evt.pubkey,
|
||||||
kind: evt.kind,
|
kind: evt.kind,
|
||||||
tags: evt.tags || [],
|
tags: evt.tags || [],
|
||||||
parsedContent: undefined,
|
parsedContent: undefined,
|
||||||
type: 'web' as const,
|
type: 'web' as const,
|
||||||
isPrivate: false,
|
isPrivate: false,
|
||||||
added_at: evt.created_at || Math.floor(Date.now() / 1000),
|
|
||||||
sourceKind: 39701,
|
sourceKind: 39701,
|
||||||
setName: dTag,
|
setName: dTag,
|
||||||
setTitle,
|
setTitle,
|
||||||
setDescription,
|
setDescription,
|
||||||
setImage
|
setImage,
|
||||||
|
listUpdatedAt: evt.created_at ?? null
|
||||||
})
|
})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const pub = Helpers.getPublicBookmarks(evt)
|
const pub = Helpers.getPublicBookmarks(evt)
|
||||||
|
const processedPub = processApplesauceBookmarks(pub, activeAccount, false, evt.created_at)
|
||||||
|
|
||||||
|
|
||||||
publicItemsAll.push(
|
publicItemsAll.push(
|
||||||
...processApplesauceBookmarks(pub, activeAccount, false, evt.created_at).map(i => ({
|
...processedPub.map(i => ({
|
||||||
...i,
|
...i,
|
||||||
sourceKind: evt.kind,
|
sourceKind: evt.kind,
|
||||||
setName: dTag,
|
setName: dTag,
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ class EventManager {
|
|||||||
|
|
||||||
// Safety timeout for event fetches (ms)
|
// Safety timeout for event fetches (ms)
|
||||||
private fetchTimeoutMs = 12000
|
private fetchTimeoutMs = 12000
|
||||||
|
// Retry policy
|
||||||
|
private maxAttempts = 4
|
||||||
|
private baseBackoffMs = 700
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the event manager with event store and relay pool
|
* Initialize the event manager with event store and relay pool
|
||||||
@@ -70,7 +73,7 @@ class EventManager {
|
|||||||
|
|
||||||
// Start a new fetch request
|
// Start a new fetch request
|
||||||
this.pendingRequests.set(eventId, [{ resolve, reject }])
|
this.pendingRequests.set(eventId, [{ resolve, reject }])
|
||||||
this.fetchFromRelay(eventId)
|
this.fetchFromRelayWithRetry(eventId, 1)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,17 +89,14 @@ class EventManager {
|
|||||||
requests.forEach(req => req.reject(error))
|
requests.forEach(req => req.reject(error))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private fetchFromRelayWithRetry(eventId: string, attempt: number): void {
|
||||||
* Actually fetch the event from relay
|
|
||||||
*/
|
|
||||||
private fetchFromRelay(eventId: string): void {
|
|
||||||
// If no loader yet, schedule retry
|
// If no loader yet, schedule retry
|
||||||
if (!this.relayPool || !this.eventLoader) {
|
if (!this.relayPool || !this.eventLoader) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (this.eventLoader && this.pendingRequests.has(eventId)) {
|
if (this.pendingRequests.has(eventId)) {
|
||||||
this.fetchFromRelay(eventId)
|
this.fetchFromRelayWithRetry(eventId, attempt)
|
||||||
}
|
}
|
||||||
}, 500)
|
}, this.baseBackoffMs)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,14 +111,23 @@ class EventManager {
|
|||||||
error: (err: unknown) => {
|
error: (err: unknown) => {
|
||||||
clearTimeout(timeoutId)
|
clearTimeout(timeoutId)
|
||||||
const error = err instanceof Error ? err : new Error(String(err))
|
const error = err instanceof Error ? err : new Error(String(err))
|
||||||
this.rejectPending(eventId, error)
|
// Retry on error until attempts exhausted
|
||||||
|
if (attempt < this.maxAttempts && this.pendingRequests.has(eventId)) {
|
||||||
|
setTimeout(() => this.fetchFromRelayWithRetry(eventId, attempt + 1), this.baseBackoffMs * attempt)
|
||||||
|
} else {
|
||||||
|
this.rejectPending(eventId, error)
|
||||||
|
}
|
||||||
subscription.unsubscribe()
|
subscription.unsubscribe()
|
||||||
},
|
},
|
||||||
complete: () => {
|
complete: () => {
|
||||||
// Completed without next - consider not found
|
// Completed without next - consider not found, but retry a few times
|
||||||
if (!delivered) {
|
if (!delivered) {
|
||||||
clearTimeout(timeoutId)
|
clearTimeout(timeoutId)
|
||||||
this.rejectPending(eventId, new Error('Event not found'))
|
if (attempt < this.maxAttempts && this.pendingRequests.has(eventId)) {
|
||||||
|
setTimeout(() => this.fetchFromRelayWithRetry(eventId, attempt + 1), this.baseBackoffMs * attempt)
|
||||||
|
} else {
|
||||||
|
this.rejectPending(eventId, new Error('Event not found'))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
subscription.unsubscribe()
|
subscription.unsubscribe()
|
||||||
}
|
}
|
||||||
@@ -127,8 +136,13 @@ class EventManager {
|
|||||||
// Safety timeout
|
// Safety timeout
|
||||||
const timeoutId = setTimeout(() => {
|
const timeoutId = setTimeout(() => {
|
||||||
if (!delivered) {
|
if (!delivered) {
|
||||||
this.rejectPending(eventId, new Error('Timed out fetching event'))
|
if (attempt < this.maxAttempts && this.pendingRequests.has(eventId)) {
|
||||||
subscription.unsubscribe()
|
subscription.unsubscribe()
|
||||||
|
this.fetchFromRelayWithRetry(eventId, attempt + 1)
|
||||||
|
} else {
|
||||||
|
subscription.unsubscribe()
|
||||||
|
this.rejectPending(eventId, new Error('Timed out fetching event'))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, this.fetchTimeoutMs)
|
}, this.fetchTimeoutMs)
|
||||||
}
|
}
|
||||||
@@ -139,7 +153,7 @@ class EventManager {
|
|||||||
private retryAllPending(): void {
|
private retryAllPending(): void {
|
||||||
const pendingIds = Array.from(this.pendingRequests.keys())
|
const pendingIds = Array.from(this.pendingRequests.keys())
|
||||||
pendingIds.forEach(eventId => {
|
pendingIds.forEach(eventId => {
|
||||||
this.fetchFromRelay(eventId)
|
this.fetchFromRelayWithRetry(eventId, 1)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { NostrEvent } from 'nostr-tools'
|
|||||||
import { Helpers, IEventStore } from 'applesauce-core'
|
import { Helpers, IEventStore } from 'applesauce-core'
|
||||||
import { queryEvents } from './dataFetch'
|
import { queryEvents } from './dataFetch'
|
||||||
import { KINDS } from '../config/kinds'
|
import { KINDS } from '../config/kinds'
|
||||||
|
import { cacheArticleEvent } from './articleService'
|
||||||
|
|
||||||
const { getArticleTitle, getArticleImage, getArticlePublished, getArticleSummary } = Helpers
|
const { getArticleTitle, getArticleImage, getArticlePublished, getArticleSummary } = Helpers
|
||||||
|
|
||||||
@@ -75,6 +76,9 @@ export const fetchBlogPostsFromAuthors = async (
|
|||||||
}
|
}
|
||||||
onPost(post)
|
onPost(post)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cache article content in localStorage for offline access
|
||||||
|
cacheArticleEvent(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,7 +109,6 @@ export const fetchBlogPostsFromAuthors = async (
|
|||||||
return timeB - timeA // Most recent first
|
return timeB - timeA // Most recent first
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
return blogPosts
|
return blogPosts
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch blog posts:', error)
|
console.error('Failed to fetch blog posts:', error)
|
||||||
|
|||||||
@@ -7,13 +7,22 @@ import { Helpers, IEventStore } from 'applesauce-core'
|
|||||||
import { RELAYS } from '../config/relays'
|
import { RELAYS } from '../config/relays'
|
||||||
import { Highlight } from '../types/highlights'
|
import { Highlight } from '../types/highlights'
|
||||||
import { UserSettings } from './settingsService'
|
import { UserSettings } from './settingsService'
|
||||||
import { isLocalRelay, areAllRelaysLocal } from '../utils/helpers'
|
import { isLocalRelay } from '../utils/helpers'
|
||||||
import { publishEvent } from './writeService'
|
import { setHighlightMetadata } from './highlightEventProcessor'
|
||||||
|
|
||||||
// Boris pubkey for zap splits
|
// Boris pubkey for zap splits
|
||||||
// npub19802see0gnk3vjlus0dnmfdagusqrtmsxpl5yfmkwn9uvnfnqylqduhr0x
|
// npub19802see0gnk3vjlus0dnmfdagusqrtmsxpl5yfmkwn9uvnfnqylqduhr0x
|
||||||
export const BORIS_PUBKEY = '29dea8672f44ed164bfc83db3da5bd472001af70307f42277674cbc64d33013e'
|
export const BORIS_PUBKEY = '29dea8672f44ed164bfc83db3da5bd472001af70307f42277674cbc64d33013e'
|
||||||
|
|
||||||
|
// Extended event type with highlight metadata
|
||||||
|
interface HighlightEvent extends NostrEvent {
|
||||||
|
__highlightProps?: {
|
||||||
|
publishedRelays?: string[]
|
||||||
|
isLocalOnly?: boolean
|
||||||
|
isSyncing?: boolean
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
getHighlightText,
|
getHighlightText,
|
||||||
getHighlightContext,
|
getHighlightContext,
|
||||||
@@ -118,25 +127,111 @@ export async function createHighlight(
|
|||||||
// Sign the event
|
// Sign the event
|
||||||
const signedEvent = await factory.sign(highlightEvent)
|
const signedEvent = await factory.sign(highlightEvent)
|
||||||
|
|
||||||
// Use unified write service to store and publish
|
// Initialize custom properties on the event (will be updated after publishing)
|
||||||
await publishEvent(relayPool, eventStore, signedEvent)
|
;(signedEvent as HighlightEvent).__highlightProps = {
|
||||||
|
publishedRelays: [],
|
||||||
|
isLocalOnly: false,
|
||||||
|
isSyncing: false
|
||||||
|
}
|
||||||
|
|
||||||
// Check current connection status for UI feedback
|
// Get only connected relays to avoid long timeouts
|
||||||
const connectedRelays = Array.from(relayPool.relays.values())
|
const connectedRelays = Array.from(relayPool.relays.values())
|
||||||
.filter(relay => relay.connected)
|
.filter(relay => relay.connected)
|
||||||
.map(relay => relay.url)
|
.map(relay => relay.url)
|
||||||
|
|
||||||
|
let publishResponses: { ok: boolean; message?: string; from: string }[] = []
|
||||||
|
let isLocalOnly = false
|
||||||
|
|
||||||
const hasRemoteConnection = connectedRelays.some(url => !isLocalRelay(url))
|
|
||||||
const expectedSuccessRelays = hasRemoteConnection
|
|
||||||
? RELAYS
|
|
||||||
: RELAYS.filter(isLocalRelay)
|
|
||||||
const isLocalOnly = areAllRelaysLocal(expectedSuccessRelays)
|
|
||||||
|
|
||||||
// Convert to Highlight with relay tracking info and return IMMEDIATELY
|
try {
|
||||||
|
// Publish only to connected relays to avoid long timeouts
|
||||||
|
if (connectedRelays.length === 0) {
|
||||||
|
isLocalOnly = true
|
||||||
|
} else {
|
||||||
|
publishResponses = await relayPool.publish(connectedRelays, signedEvent)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine which relays successfully accepted the event
|
||||||
|
const successfulRelays = publishResponses
|
||||||
|
.filter(response => response.ok)
|
||||||
|
.map(response => response.from)
|
||||||
|
|
||||||
|
const successfulLocalRelays = successfulRelays.filter(url => isLocalRelay(url))
|
||||||
|
const successfulRemoteRelays = successfulRelays.filter(url => !isLocalRelay(url))
|
||||||
|
|
||||||
|
// isLocalOnly is true if only local relays accepted the event
|
||||||
|
isLocalOnly = successfulLocalRelays.length > 0 && successfulRemoteRelays.length === 0
|
||||||
|
|
||||||
|
|
||||||
|
// Handle case when no relays were connected
|
||||||
|
const successfulRelaysList = publishResponses.length > 0
|
||||||
|
? publishResponses
|
||||||
|
.filter(response => response.ok)
|
||||||
|
.map(response => response.from)
|
||||||
|
: []
|
||||||
|
|
||||||
|
// Store metadata in cache (persists across EventStore serialization)
|
||||||
|
setHighlightMetadata(signedEvent.id, {
|
||||||
|
publishedRelays: successfulRelaysList,
|
||||||
|
isLocalOnly,
|
||||||
|
isSyncing: false
|
||||||
|
})
|
||||||
|
|
||||||
|
// Also update the event with the actual properties (for backwards compatibility)
|
||||||
|
;(signedEvent as HighlightEvent).__highlightProps = {
|
||||||
|
publishedRelays: successfulRelaysList,
|
||||||
|
isLocalOnly,
|
||||||
|
isSyncing: false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store the event in EventStore AFTER updating with final properties
|
||||||
|
eventStore.add(signedEvent)
|
||||||
|
|
||||||
|
// Mark for offline sync if we're in local-only mode
|
||||||
|
if (isLocalOnly) {
|
||||||
|
const { markEventAsOfflineCreated } = await import('./offlineSyncService')
|
||||||
|
markEventAsOfflineCreated(signedEvent.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ [HIGHLIGHT-PUBLISH] Failed to publish highlight to relays:', error)
|
||||||
|
// If publishing fails completely, assume local-only mode
|
||||||
|
isLocalOnly = true
|
||||||
|
|
||||||
|
// Store metadata in cache (persists across EventStore serialization)
|
||||||
|
setHighlightMetadata(signedEvent.id, {
|
||||||
|
publishedRelays: [],
|
||||||
|
isLocalOnly: true,
|
||||||
|
isSyncing: false
|
||||||
|
})
|
||||||
|
|
||||||
|
// Also update the event with the error state (for backwards compatibility)
|
||||||
|
;(signedEvent as HighlightEvent).__highlightProps = {
|
||||||
|
publishedRelays: [],
|
||||||
|
isLocalOnly: true,
|
||||||
|
isSyncing: false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store the event in EventStore AFTER updating with final properties
|
||||||
|
eventStore.add(signedEvent)
|
||||||
|
|
||||||
|
const { markEventAsOfflineCreated } = await import('./offlineSyncService')
|
||||||
|
markEventAsOfflineCreated(signedEvent.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert to Highlight with relay tracking info
|
||||||
const highlight = eventToHighlight(signedEvent)
|
const highlight = eventToHighlight(signedEvent)
|
||||||
highlight.publishedRelays = expectedSuccessRelays
|
|
||||||
|
// Manually set the properties since __highlightProps might not be working
|
||||||
|
const finalPublishedRelays = publishResponses.length > 0
|
||||||
|
? publishResponses
|
||||||
|
.filter(response => response.ok)
|
||||||
|
.map(response => response.from)
|
||||||
|
: []
|
||||||
|
|
||||||
|
highlight.publishedRelays = finalPublishedRelays
|
||||||
highlight.isLocalOnly = isLocalOnly
|
highlight.isLocalOnly = isLocalOnly
|
||||||
highlight.isOfflineCreated = isLocalOnly
|
highlight.isSyncing = false
|
||||||
|
|
||||||
return highlight
|
return highlight
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,15 @@ import { NostrEvent } from 'nostr-tools'
|
|||||||
import { Helpers } from 'applesauce-core'
|
import { Helpers } from 'applesauce-core'
|
||||||
import { Highlight } from '../types/highlights'
|
import { Highlight } from '../types/highlights'
|
||||||
|
|
||||||
|
// Extended event type with highlight metadata
|
||||||
|
interface HighlightEvent extends NostrEvent {
|
||||||
|
__highlightProps?: {
|
||||||
|
publishedRelays?: string[]
|
||||||
|
isLocalOnly?: boolean
|
||||||
|
isSyncing?: boolean
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
getHighlightText,
|
getHighlightText,
|
||||||
getHighlightContext,
|
getHighlightContext,
|
||||||
@@ -12,6 +21,66 @@ const {
|
|||||||
getHighlightAttributions
|
getHighlightAttributions
|
||||||
} = Helpers
|
} = Helpers
|
||||||
|
|
||||||
|
const METADATA_CACHE_KEY = 'highlightMetadataCache'
|
||||||
|
|
||||||
|
type HighlightMetadata = {
|
||||||
|
publishedRelays?: string[]
|
||||||
|
isLocalOnly?: boolean
|
||||||
|
isSyncing?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load highlight metadata from localStorage
|
||||||
|
*/
|
||||||
|
function loadHighlightMetadataFromStorage(): Map<string, HighlightMetadata> {
|
||||||
|
try {
|
||||||
|
const raw = localStorage.getItem(METADATA_CACHE_KEY)
|
||||||
|
if (!raw) return new Map()
|
||||||
|
|
||||||
|
const parsed = JSON.parse(raw) as Record<string, HighlightMetadata>
|
||||||
|
return new Map(Object.entries(parsed))
|
||||||
|
} catch {
|
||||||
|
// Silently fail on parse errors or if storage is unavailable
|
||||||
|
return new Map()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save highlight metadata to localStorage
|
||||||
|
*/
|
||||||
|
function saveHighlightMetadataToStorage(cache: Map<string, HighlightMetadata>): void {
|
||||||
|
try {
|
||||||
|
const record = Object.fromEntries(cache.entries())
|
||||||
|
localStorage.setItem(METADATA_CACHE_KEY, JSON.stringify(record))
|
||||||
|
} catch {
|
||||||
|
// Silently fail if storage is full or unavailable
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache for highlight metadata that persists across EventStore serialization
|
||||||
|
* Key: event ID, Value: { publishedRelays, isLocalOnly, isSyncing }
|
||||||
|
*/
|
||||||
|
const highlightMetadataCache = loadHighlightMetadataFromStorage()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store highlight metadata for an event ID
|
||||||
|
*/
|
||||||
|
export function setHighlightMetadata(
|
||||||
|
eventId: string,
|
||||||
|
metadata: HighlightMetadata
|
||||||
|
): void {
|
||||||
|
highlightMetadataCache.set(eventId, metadata)
|
||||||
|
saveHighlightMetadataToStorage(highlightMetadataCache)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get highlight metadata for an event ID
|
||||||
|
*/
|
||||||
|
export function getHighlightMetadata(eventId: string): HighlightMetadata | undefined {
|
||||||
|
return highlightMetadataCache.get(eventId)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a NostrEvent to a Highlight object
|
* Convert a NostrEvent to a Highlight object
|
||||||
*/
|
*/
|
||||||
@@ -28,6 +97,12 @@ export function eventToHighlight(event: NostrEvent): Highlight {
|
|||||||
const eventReference = sourceEventPointer?.id ||
|
const eventReference = sourceEventPointer?.id ||
|
||||||
(sourceAddressPointer ? `${sourceAddressPointer.kind}:${sourceAddressPointer.pubkey}:${sourceAddressPointer.identifier}` : undefined)
|
(sourceAddressPointer ? `${sourceAddressPointer.kind}:${sourceAddressPointer.pubkey}:${sourceAddressPointer.identifier}` : undefined)
|
||||||
|
|
||||||
|
// Check cache first (persists across EventStore serialization)
|
||||||
|
const cachedMetadata = getHighlightMetadata(event.id)
|
||||||
|
|
||||||
|
// Fall back to __highlightProps if cache doesn't have it (for backwards compatibility)
|
||||||
|
const customProps = cachedMetadata || (event as HighlightEvent).__highlightProps || {}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: event.id,
|
id: event.id,
|
||||||
pubkey: event.pubkey,
|
pubkey: event.pubkey,
|
||||||
@@ -38,7 +113,11 @@ export function eventToHighlight(event: NostrEvent): Highlight {
|
|||||||
urlReference: sourceUrl,
|
urlReference: sourceUrl,
|
||||||
author,
|
author,
|
||||||
context,
|
context,
|
||||||
comment
|
comment,
|
||||||
|
// Preserve custom properties if they exist
|
||||||
|
publishedRelays: customProps.publishedRelays,
|
||||||
|
isLocalOnly: customProps.isLocalOnly,
|
||||||
|
isSyncing: customProps.isSyncing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export const fetchHighlightsFromAuthors = async (
|
|||||||
const seenIds = new Set<string>()
|
const seenIds = new Set<string>()
|
||||||
const rawEvents = await queryEvents(
|
const rawEvents = await queryEvents(
|
||||||
relayPool,
|
relayPool,
|
||||||
{ kinds: [9802], authors: pubkeys, limit: 200 },
|
{ kinds: [9802], authors: pubkeys, limit: 1000 },
|
||||||
{
|
{
|
||||||
onEvent: (event: NostrEvent) => {
|
onEvent: (event: NostrEvent) => {
|
||||||
if (!seenIds.has(event.id)) {
|
if (!seenIds.has(event.id)) {
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ import { eventToHighlight, sortHighlights } from './highlightEventProcessor'
|
|||||||
type HighlightsCallback = (highlights: Highlight[]) => void
|
type HighlightsCallback = (highlights: Highlight[]) => void
|
||||||
type LoadingCallback = (loading: boolean) => void
|
type LoadingCallback = (loading: boolean) => void
|
||||||
|
|
||||||
const LAST_SYNCED_KEY = 'highlights_last_synced'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shared highlights controller
|
* Shared highlights controller
|
||||||
* Manages the user's highlights centrally, similar to bookmarkController
|
* Manages the user's highlights centrally, similar to bookmarkController
|
||||||
@@ -68,37 +66,10 @@ class HighlightsController {
|
|||||||
this.emitHighlights(this.currentHighlights)
|
this.emitHighlights(this.currentHighlights)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get last synced timestamp for incremental loading
|
|
||||||
*/
|
|
||||||
private getLastSyncedAt(pubkey: string): number | null {
|
|
||||||
try {
|
|
||||||
const data = localStorage.getItem(LAST_SYNCED_KEY)
|
|
||||||
if (!data) return null
|
|
||||||
const parsed = JSON.parse(data)
|
|
||||||
return parsed[pubkey] || null
|
|
||||||
} catch {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update last synced timestamp
|
|
||||||
*/
|
|
||||||
private setLastSyncedAt(pubkey: string, timestamp: number): void {
|
|
||||||
try {
|
|
||||||
const data = localStorage.getItem(LAST_SYNCED_KEY)
|
|
||||||
const parsed = data ? JSON.parse(data) : {}
|
|
||||||
parsed[pubkey] = timestamp
|
|
||||||
localStorage.setItem(LAST_SYNCED_KEY, JSON.stringify(parsed))
|
|
||||||
} catch (err) {
|
|
||||||
console.warn('[highlights] Failed to save last synced timestamp:', err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load highlights for a user
|
* Load highlights for a user
|
||||||
* Streams results and stores in event store
|
* Streams results and stores in event store
|
||||||
|
* Always fetches ALL highlights to ensure completeness
|
||||||
*/
|
*/
|
||||||
async start(options: {
|
async start(options: {
|
||||||
relayPool: RelayPool
|
relayPool: RelayPool
|
||||||
@@ -124,15 +95,12 @@ class HighlightsController {
|
|||||||
const seenIds = new Set<string>()
|
const seenIds = new Set<string>()
|
||||||
const highlightsMap = new Map<string, Highlight>()
|
const highlightsMap = new Map<string, Highlight>()
|
||||||
|
|
||||||
// Get last synced timestamp for incremental loading
|
// Fetch ALL highlights without limits (no since filter)
|
||||||
const lastSyncedAt = force ? null : this.getLastSyncedAt(pubkey)
|
// This ensures we get complete results for profile/my pages
|
||||||
const filter: { kinds: number[]; authors: string[]; since?: number } = {
|
const filter = {
|
||||||
kinds: [KINDS.Highlights],
|
kinds: [KINDS.Highlights],
|
||||||
authors: [pubkey]
|
authors: [pubkey]
|
||||||
}
|
}
|
||||||
if (lastSyncedAt) {
|
|
||||||
filter.since = lastSyncedAt
|
|
||||||
}
|
|
||||||
|
|
||||||
const events = await queryEvents(
|
const events = await queryEvents(
|
||||||
relayPool,
|
relayPool,
|
||||||
@@ -179,12 +147,6 @@ class HighlightsController {
|
|||||||
this.lastLoadedPubkey = pubkey
|
this.lastLoadedPubkey = pubkey
|
||||||
this.emitHighlights(sorted)
|
this.emitHighlights(sorted)
|
||||||
|
|
||||||
// Update last synced timestamp
|
|
||||||
if (sorted.length > 0) {
|
|
||||||
const newestTimestamp = Math.max(...sorted.map(h => h.created_at))
|
|
||||||
this.setLastSyncedAt(pubkey, newestTimestamp)
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[highlights] ❌ Failed to load highlights:', error)
|
console.error('[highlights] ❌ Failed to load highlights:', error)
|
||||||
this.currentHighlights = []
|
this.currentHighlights = []
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
* Service Worker automatically caches images on fetch
|
* Service Worker automatically caches images on fetch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const CACHE_NAME = 'boris-image-cache-v1'
|
// Must match the cache name in src/sw.ts
|
||||||
|
const CACHE_NAME = 'boris-images'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear all cached images
|
* Clear all cached images
|
||||||
|
|||||||
@@ -81,13 +81,21 @@ class NostrverseHighlightsController {
|
|||||||
const currentGeneration = this.generation
|
const currentGeneration = this.generation
|
||||||
this.setLoading(true)
|
this.setLoading(true)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const seenIds = new Set<string>()
|
const seenIds = new Set<string>()
|
||||||
const highlightsMap = new Map<string, Highlight>()
|
// Start with existing highlights when doing incremental sync
|
||||||
|
const highlightsMap = new Map<string, Highlight>(
|
||||||
|
this.currentHighlights.map(h => [h.id, h])
|
||||||
|
)
|
||||||
|
|
||||||
const lastSyncedAt = force ? null : this.getLastSyncedAt()
|
const lastSyncedAt = force ? null : this.getLastSyncedAt()
|
||||||
const filter: { kinds: number[]; since?: number } = { kinds: [KINDS.Highlights] }
|
const filter: { kinds: number[]; since?: number; limit?: number } = { kinds: [KINDS.Highlights] }
|
||||||
if (lastSyncedAt) filter.since = lastSyncedAt
|
if (lastSyncedAt) {
|
||||||
|
filter.since = lastSyncedAt
|
||||||
|
} else {
|
||||||
|
// On initial load, fetch more highlights
|
||||||
|
filter.limit = 1000
|
||||||
|
}
|
||||||
|
|
||||||
const events = await queryEvents(
|
const events = await queryEvents(
|
||||||
relayPool,
|
relayPool,
|
||||||
@@ -111,22 +119,24 @@ class NostrverseHighlightsController {
|
|||||||
|
|
||||||
if (currentGeneration !== this.generation) return
|
if (currentGeneration !== this.generation) return
|
||||||
|
|
||||||
events.forEach(evt => eventStore.add(evt))
|
events.forEach(evt => eventStore.add(evt))
|
||||||
|
|
||||||
const highlights = events.map(eventToHighlight)
|
const highlights = events.map(eventToHighlight)
|
||||||
const unique = Array.from(new Map(highlights.map(h => [h.id, h])).values())
|
// Merge new highlights with existing ones
|
||||||
const sorted = sortHighlights(unique)
|
highlights.forEach(h => highlightsMap.set(h.id, h))
|
||||||
|
const sorted = sortHighlights(Array.from(highlightsMap.values()))
|
||||||
|
|
||||||
this.currentHighlights = sorted
|
this.currentHighlights = sorted
|
||||||
this.loaded = true
|
this.loaded = true
|
||||||
this.emitHighlights(sorted)
|
this.emitHighlights(sorted)
|
||||||
|
|
||||||
if (sorted.length > 0) {
|
if (sorted.length > 0) {
|
||||||
const newest = Math.max(...sorted.map(h => h.created_at))
|
const newest = Math.max(...sorted.map(h => h.created_at))
|
||||||
this.setLastSyncedAt(newest)
|
this.setLastSyncedAt(newest)
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.currentHighlights = []
|
// On error, keep existing highlights instead of clearing them
|
||||||
|
console.error('[nostrverse-highlights] Failed to sync:', err)
|
||||||
this.emitHighlights(this.currentHighlights)
|
this.emitHighlights(this.currentHighlights)
|
||||||
} finally {
|
} finally {
|
||||||
if (currentGeneration === this.generation) this.setLoading(false)
|
if (currentGeneration === this.generation) this.setLoading(false)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { BlogPostPreview } from './exploreService'
|
|||||||
import { Highlight } from '../types/highlights'
|
import { Highlight } from '../types/highlights'
|
||||||
import { eventToHighlight, dedupeHighlights, sortHighlights } from './highlightEventProcessor'
|
import { eventToHighlight, dedupeHighlights, sortHighlights } from './highlightEventProcessor'
|
||||||
import { queryEvents } from './dataFetch'
|
import { queryEvents } from './dataFetch'
|
||||||
|
import { cacheArticleEvent } from './articleService'
|
||||||
|
|
||||||
const { getArticleTitle, getArticleImage, getArticlePublished, getArticleSummary } = Helpers
|
const { getArticleTitle, getArticleImage, getArticlePublished, getArticleSummary } = Helpers
|
||||||
|
|
||||||
@@ -57,6 +58,9 @@ export const fetchNostrverseBlogPosts = async (
|
|||||||
}
|
}
|
||||||
onPost(post)
|
onPost(post)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cache article content in localStorage for offline access
|
||||||
|
cacheArticleEvent(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,7 +83,6 @@ export const fetchNostrverseBlogPosts = async (
|
|||||||
return timeB - timeA // Most recent first
|
return timeB - timeA // Most recent first
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
return blogPosts
|
return blogPosts
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch nostrverse blog posts:', error)
|
console.error('Failed to fetch nostrverse blog posts:', error)
|
||||||
|
|||||||
@@ -3,11 +3,42 @@ import { NostrEvent } from 'nostr-tools'
|
|||||||
import { IEventStore } from 'applesauce-core'
|
import { IEventStore } from 'applesauce-core'
|
||||||
import { RELAYS } from '../config/relays'
|
import { RELAYS } from '../config/relays'
|
||||||
import { isLocalRelay } from '../utils/helpers'
|
import { isLocalRelay } from '../utils/helpers'
|
||||||
|
import { setHighlightMetadata, getHighlightMetadata } from './highlightEventProcessor'
|
||||||
|
|
||||||
|
const OFFLINE_EVENTS_KEY = 'offlineCreatedEvents'
|
||||||
|
|
||||||
let isSyncing = false
|
let isSyncing = false
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load offline events from localStorage
|
||||||
|
*/
|
||||||
|
function loadOfflineEventsFromStorage(): Set<string> {
|
||||||
|
try {
|
||||||
|
const raw = localStorage.getItem(OFFLINE_EVENTS_KEY)
|
||||||
|
if (!raw) return new Set()
|
||||||
|
|
||||||
|
const parsed = JSON.parse(raw) as string[]
|
||||||
|
return new Set(parsed)
|
||||||
|
} catch {
|
||||||
|
// Silently fail on parse errors or if storage is unavailable
|
||||||
|
return new Set()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save offline events to localStorage
|
||||||
|
*/
|
||||||
|
function saveOfflineEventsToStorage(events: Set<string>): void {
|
||||||
|
try {
|
||||||
|
const array = Array.from(events)
|
||||||
|
localStorage.setItem(OFFLINE_EVENTS_KEY, JSON.stringify(array))
|
||||||
|
} catch {
|
||||||
|
// Silently fail if storage is full or unavailable
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Track events created during offline period
|
// Track events created during offline period
|
||||||
const offlineCreatedEvents = new Set<string>()
|
const offlineCreatedEvents = loadOfflineEventsFromStorage()
|
||||||
|
|
||||||
// Track events currently being synced
|
// Track events currently being synced
|
||||||
const syncingEvents = new Set<string>()
|
const syncingEvents = new Set<string>()
|
||||||
@@ -20,6 +51,14 @@ const syncStateListeners: Array<(eventId: string, isSyncing: boolean) => void> =
|
|||||||
*/
|
*/
|
||||||
export function markEventAsOfflineCreated(eventId: string): void {
|
export function markEventAsOfflineCreated(eventId: string): void {
|
||||||
offlineCreatedEvents.add(eventId)
|
offlineCreatedEvents.add(eventId)
|
||||||
|
saveOfflineEventsToStorage(offlineCreatedEvents)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if an event was created during offline period (flight mode)
|
||||||
|
*/
|
||||||
|
export function isEventOfflineCreated(eventId: string): boolean {
|
||||||
|
return offlineCreatedEvents.has(eventId)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,6 +126,7 @@ export async function syncLocalEventsToRemote(
|
|||||||
if (eventsToSync.length === 0) {
|
if (eventsToSync.length === 0) {
|
||||||
isSyncing = false
|
isSyncing = false
|
||||||
offlineCreatedEvents.clear()
|
offlineCreatedEvents.clear()
|
||||||
|
saveOfflineEventsToStorage(offlineCreatedEvents)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,10 +135,17 @@ export async function syncLocalEventsToRemote(
|
|||||||
new Map(eventsToSync.map(e => [e.id, e])).values()
|
new Map(eventsToSync.map(e => [e.id, e])).values()
|
||||||
)
|
)
|
||||||
|
|
||||||
// Mark all events as syncing
|
// Mark all events as syncing and update metadata
|
||||||
uniqueEvents.forEach(event => {
|
uniqueEvents.forEach(event => {
|
||||||
syncingEvents.add(event.id)
|
syncingEvents.add(event.id)
|
||||||
notifySyncStateChange(event.id, true)
|
notifySyncStateChange(event.id, true)
|
||||||
|
|
||||||
|
// Update metadata cache to reflect syncing state
|
||||||
|
const existingMetadata = getHighlightMetadata(event.id)
|
||||||
|
setHighlightMetadata(event.id, {
|
||||||
|
...existingMetadata,
|
||||||
|
isSyncing: true
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// Publish to remote relays
|
// Publish to remote relays
|
||||||
@@ -118,13 +165,32 @@ export async function syncLocalEventsToRemote(
|
|||||||
syncingEvents.delete(eventId)
|
syncingEvents.delete(eventId)
|
||||||
offlineCreatedEvents.delete(eventId)
|
offlineCreatedEvents.delete(eventId)
|
||||||
notifySyncStateChange(eventId, false)
|
notifySyncStateChange(eventId, false)
|
||||||
|
|
||||||
|
// Update metadata cache: sync complete, no longer local-only
|
||||||
|
const existingMetadata = getHighlightMetadata(eventId)
|
||||||
|
setHighlightMetadata(eventId, {
|
||||||
|
...existingMetadata,
|
||||||
|
isSyncing: false,
|
||||||
|
isLocalOnly: false
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Save updated offline events set to localStorage
|
||||||
|
saveOfflineEventsToStorage(offlineCreatedEvents)
|
||||||
|
|
||||||
// Clear syncing state for failed events
|
// Clear syncing state for failed events
|
||||||
uniqueEvents.forEach(event => {
|
uniqueEvents.forEach(event => {
|
||||||
if (!successfulIds.includes(event.id)) {
|
if (!successfulIds.includes(event.id)) {
|
||||||
syncingEvents.delete(event.id)
|
syncingEvents.delete(event.id)
|
||||||
notifySyncStateChange(event.id, false)
|
notifySyncStateChange(event.id, false)
|
||||||
|
|
||||||
|
// Update metadata cache: sync failed, still local-only
|
||||||
|
const existingMetadata = getHighlightMetadata(event.id)
|
||||||
|
setHighlightMetadata(event.id, {
|
||||||
|
...existingMetadata,
|
||||||
|
isSyncing: false
|
||||||
|
// Keep isLocalOnly as true (sync failed)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
114
src/services/opengraphEnhancer.ts
Normal file
114
src/services/opengraphEnhancer.ts
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
import { fetch as fetchOpenGraph } from 'fetch-opengraph'
|
||||||
|
import { ReadItem } from './readsService'
|
||||||
|
|
||||||
|
// Cache for OpenGraph data to avoid repeated requests
|
||||||
|
const ogCache = new Map<string, Record<string, unknown>>()
|
||||||
|
|
||||||
|
function getCachedOgData(url: string): Record<string, unknown> | null {
|
||||||
|
const cached = ogCache.get(url)
|
||||||
|
if (!cached) return null
|
||||||
|
|
||||||
|
return cached
|
||||||
|
}
|
||||||
|
|
||||||
|
function setCachedOgData(url: string, data: Record<string, unknown>): void {
|
||||||
|
ogCache.set(url, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enhances a ReadItem with OpenGraph data
|
||||||
|
* Only fetches if the item doesn't already have good metadata
|
||||||
|
*/
|
||||||
|
export async function enhanceReadItemWithOpenGraph(item: ReadItem): Promise<ReadItem> {
|
||||||
|
// Skip if we already have good metadata
|
||||||
|
if (item.title && item.title !== fallbackTitleFromUrl(item.url || '') && item.image) {
|
||||||
|
return item
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!item.url) return item
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Check cache first
|
||||||
|
let ogData = getCachedOgData(item.url)
|
||||||
|
|
||||||
|
if (!ogData) {
|
||||||
|
// Fetch OpenGraph data
|
||||||
|
const fetchedOgData = await fetchOpenGraph(item.url)
|
||||||
|
if (fetchedOgData) {
|
||||||
|
ogData = fetchedOgData
|
||||||
|
setCachedOgData(item.url, fetchedOgData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ogData) return item
|
||||||
|
|
||||||
|
// Enhance the item with OpenGraph data
|
||||||
|
const enhanced: ReadItem = { ...item }
|
||||||
|
|
||||||
|
// Use OpenGraph title if we don't have a good title
|
||||||
|
if (!enhanced.title || enhanced.title === fallbackTitleFromUrl(item.url)) {
|
||||||
|
const ogTitle = ogData['og:title'] || ogData['twitter:title'] || ogData.title
|
||||||
|
if (typeof ogTitle === 'string') {
|
||||||
|
enhanced.title = ogTitle
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use OpenGraph description if we don't have a summary
|
||||||
|
if (!enhanced.summary) {
|
||||||
|
const ogDescription = ogData['og:description'] || ogData['twitter:description'] || ogData.description
|
||||||
|
if (typeof ogDescription === 'string') {
|
||||||
|
enhanced.summary = ogDescription
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use OpenGraph image if we don't have an image
|
||||||
|
if (!enhanced.image) {
|
||||||
|
const ogImage = ogData['og:image'] || ogData['twitter:image'] || ogData.image
|
||||||
|
if (typeof ogImage === 'string') {
|
||||||
|
enhanced.image = ogImage
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return enhanced
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Failed to enhance ReadItem with OpenGraph data:', error)
|
||||||
|
return item
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enhances multiple ReadItems with OpenGraph data in parallel
|
||||||
|
* Uses batching to avoid overwhelming the service
|
||||||
|
*/
|
||||||
|
export async function enhanceReadItemsWithOpenGraph(items: ReadItem[]): Promise<ReadItem[]> {
|
||||||
|
const BATCH_SIZE = 5
|
||||||
|
const BATCH_DELAY = 1000 // 1 second between batches
|
||||||
|
|
||||||
|
const enhancedItems: ReadItem[] = []
|
||||||
|
|
||||||
|
for (let i = 0; i < items.length; i += BATCH_SIZE) {
|
||||||
|
const batch = items.slice(i, i + BATCH_SIZE)
|
||||||
|
|
||||||
|
// Process batch in parallel
|
||||||
|
const batchPromises = batch.map(item => enhanceReadItemWithOpenGraph(item))
|
||||||
|
const batchResults = await Promise.all(batchPromises)
|
||||||
|
enhancedItems.push(...batchResults)
|
||||||
|
|
||||||
|
// Add delay between batches to be respectful to the service
|
||||||
|
if (i + BATCH_SIZE < items.length) {
|
||||||
|
await new Promise(resolve => setTimeout(resolve, BATCH_DELAY))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return enhancedItems
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to generate fallback title from URL
|
||||||
|
function fallbackTitleFromUrl(url: string): string {
|
||||||
|
try {
|
||||||
|
const urlObj = new URL(url)
|
||||||
|
return urlObj.hostname.replace('www.', '')
|
||||||
|
} catch {
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,78 +1,325 @@
|
|||||||
import { RelayPool, completeOnEose, onlyEvents } from 'applesauce-relay'
|
import { RelayPool, completeOnEose, onlyEvents } from 'applesauce-relay'
|
||||||
import { lastValueFrom, merge, Observable, takeUntil, timer, toArray, tap } from 'rxjs'
|
import { lastValueFrom, merge, Observable, toArray, tap } from 'rxjs'
|
||||||
import { NostrEvent } from 'nostr-tools'
|
import { NostrEvent } from 'nostr-tools'
|
||||||
import { IEventStore } from 'applesauce-core'
|
import { IEventStore } from 'applesauce-core'
|
||||||
import { prioritizeLocalRelays, partitionRelays } from '../utils/helpers'
|
import { prioritizeLocalRelays, partitionRelays } from '../utils/helpers'
|
||||||
import { rebroadcastEvents } from './rebroadcastService'
|
import { rebroadcastEvents } from './rebroadcastService'
|
||||||
import { UserSettings } from './settingsService'
|
import { UserSettings } from './settingsService'
|
||||||
|
|
||||||
|
interface CachedProfile {
|
||||||
|
event: NostrEvent
|
||||||
|
timestamp: number
|
||||||
|
lastAccessed: number // For LRU eviction
|
||||||
|
}
|
||||||
|
|
||||||
|
const PROFILE_CACHE_TTL = 30 * 24 * 60 * 60 * 1000 // 30 days in milliseconds (profiles change less frequently than articles)
|
||||||
|
const PROFILE_CACHE_PREFIX = 'profile_cache_'
|
||||||
|
const MAX_CACHED_PROFILES = 1000 // Limit number of cached profiles to prevent quota issues
|
||||||
|
let quotaExceededLogged = false // Only log quota error once per session
|
||||||
|
|
||||||
|
// Request deduplication: track in-flight fetch requests by sorted pubkey array
|
||||||
|
// Key: sorted, comma-separated pubkeys, Value: Promise for that fetch
|
||||||
|
const inFlightRequests = new Map<string, Promise<NostrEvent[]>>()
|
||||||
|
|
||||||
|
function getProfileCacheKey(pubkey: string): string {
|
||||||
|
return `${PROFILE_CACHE_PREFIX}${pubkey}`
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a cached profile from localStorage
|
||||||
|
* Returns null if not found, expired, or on error
|
||||||
|
* Updates lastAccessed timestamp for LRU eviction
|
||||||
|
*/
|
||||||
|
export function getCachedProfile(pubkey: string): NostrEvent | null {
|
||||||
|
try {
|
||||||
|
const cacheKey = getProfileCacheKey(pubkey)
|
||||||
|
const cached = localStorage.getItem(cacheKey)
|
||||||
|
if (!cached) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const data: CachedProfile = JSON.parse(cached)
|
||||||
|
const age = Date.now() - data.timestamp
|
||||||
|
|
||||||
|
if (age > PROFILE_CACHE_TTL) {
|
||||||
|
localStorage.removeItem(cacheKey)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update lastAccessed for LRU eviction (but don't fail if update fails)
|
||||||
|
try {
|
||||||
|
data.lastAccessed = Date.now()
|
||||||
|
localStorage.setItem(cacheKey, JSON.stringify(data))
|
||||||
|
} catch {
|
||||||
|
// Ignore update errors, still return the profile
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.event
|
||||||
|
} catch (err) {
|
||||||
|
// Silently handle cache read errors (quota, invalid data, etc.)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all cached profile keys for eviction
|
||||||
|
*/
|
||||||
|
function getAllCachedProfileKeys(): Array<{ key: string; lastAccessed: number }> {
|
||||||
|
const keys: Array<{ key: string; lastAccessed: number }> = []
|
||||||
|
try {
|
||||||
|
for (let i = 0; i < localStorage.length; i++) {
|
||||||
|
const key = localStorage.key(i)
|
||||||
|
if (key && key.startsWith(PROFILE_CACHE_PREFIX)) {
|
||||||
|
try {
|
||||||
|
const cached = localStorage.getItem(key)
|
||||||
|
if (cached) {
|
||||||
|
const data: CachedProfile = JSON.parse(cached)
|
||||||
|
keys.push({
|
||||||
|
key,
|
||||||
|
lastAccessed: data.lastAccessed || data.timestamp || 0
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Skip invalid entries
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Ignore errors during enumeration
|
||||||
|
}
|
||||||
|
return keys
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Evict oldest profiles (LRU) to free up space
|
||||||
|
* Removes the oldest accessed profiles until we're under the limit
|
||||||
|
*/
|
||||||
|
function evictOldProfiles(targetCount: number): void {
|
||||||
|
try {
|
||||||
|
const keys = getAllCachedProfileKeys()
|
||||||
|
if (keys.length <= targetCount) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort by lastAccessed (oldest first) and remove oldest
|
||||||
|
keys.sort((a, b) => a.lastAccessed - b.lastAccessed)
|
||||||
|
const toRemove = keys.slice(0, keys.length - targetCount)
|
||||||
|
|
||||||
|
for (const { key } of toRemove) {
|
||||||
|
localStorage.removeItem(key)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Silently fail eviction
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache a profile to localStorage
|
||||||
|
* Handles errors gracefully (quota exceeded, invalid data, etc.)
|
||||||
|
* Implements LRU eviction when cache is full
|
||||||
|
*/
|
||||||
|
export function cacheProfile(profile: NostrEvent): void {
|
||||||
|
try {
|
||||||
|
if (profile.kind !== 0) {
|
||||||
|
return // Only cache kind:0 (profile) events
|
||||||
|
}
|
||||||
|
|
||||||
|
const cacheKey = getProfileCacheKey(profile.pubkey)
|
||||||
|
|
||||||
|
// Check if we need to evict before caching
|
||||||
|
const existingKeys = getAllCachedProfileKeys()
|
||||||
|
if (existingKeys.length >= MAX_CACHED_PROFILES) {
|
||||||
|
// Check if this profile is already cached
|
||||||
|
const alreadyCached = existingKeys.some(k => k.key === cacheKey)
|
||||||
|
if (!alreadyCached) {
|
||||||
|
// Evict oldest profiles to make room (keep 90% of max)
|
||||||
|
evictOldProfiles(Math.floor(MAX_CACHED_PROFILES * 0.9))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const cached: CachedProfile = {
|
||||||
|
event: profile,
|
||||||
|
timestamp: Date.now(),
|
||||||
|
lastAccessed: Date.now()
|
||||||
|
}
|
||||||
|
localStorage.setItem(cacheKey, JSON.stringify(cached))
|
||||||
|
} catch (err) {
|
||||||
|
// Handle quota exceeded by evicting and retrying once
|
||||||
|
if (err instanceof DOMException && err.name === 'QuotaExceededError') {
|
||||||
|
if (!quotaExceededLogged) {
|
||||||
|
console.warn(`[npub-cache] localStorage quota exceeded, evicting old profiles...`)
|
||||||
|
quotaExceededLogged = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try evicting more aggressively and retry
|
||||||
|
try {
|
||||||
|
evictOldProfiles(Math.floor(MAX_CACHED_PROFILES * 0.5))
|
||||||
|
const cached: CachedProfile = {
|
||||||
|
event: profile,
|
||||||
|
timestamp: Date.now(),
|
||||||
|
lastAccessed: Date.now()
|
||||||
|
}
|
||||||
|
localStorage.setItem(getProfileCacheKey(profile.pubkey), JSON.stringify(cached))
|
||||||
|
} catch {
|
||||||
|
// Silently fail if still can't cache - don't block the UI
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Silently handle other caching errors (invalid data, etc.)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Batch load multiple profiles from localStorage cache
|
||||||
|
* Returns a Map of pubkey -> NostrEvent for all found profiles
|
||||||
|
*/
|
||||||
|
export function loadCachedProfiles(pubkeys: string[]): Map<string, NostrEvent> {
|
||||||
|
const cached = new Map<string, NostrEvent>()
|
||||||
|
|
||||||
|
for (const pubkey of pubkeys) {
|
||||||
|
const profile = getCachedProfile(pubkey)
|
||||||
|
if (profile) {
|
||||||
|
cached.set(pubkey, profile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cached
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches profile metadata (kind:0) for a list of pubkeys
|
* Fetches profile metadata (kind:0) for a list of pubkeys
|
||||||
* Stores profiles in the event store and optionally to local relays
|
* Checks localStorage cache first, then fetches from relays for missing/expired profiles
|
||||||
|
* Stores profiles in the event store and caches to localStorage
|
||||||
|
* Implements request deduplication to prevent duplicate relay requests for the same pubkey sets
|
||||||
*/
|
*/
|
||||||
export const fetchProfiles = async (
|
export const fetchProfiles = async (
|
||||||
relayPool: RelayPool,
|
relayPool: RelayPool,
|
||||||
eventStore: IEventStore,
|
eventStore: IEventStore,
|
||||||
pubkeys: string[],
|
pubkeys: string[],
|
||||||
settings?: UserSettings
|
settings?: UserSettings,
|
||||||
|
onEvent?: (event: NostrEvent) => void
|
||||||
): Promise<NostrEvent[]> => {
|
): Promise<NostrEvent[]> => {
|
||||||
try {
|
try {
|
||||||
if (pubkeys.length === 0) {
|
if (pubkeys.length === 0) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
const uniquePubkeys = Array.from(new Set(pubkeys))
|
const uniquePubkeys = Array.from(new Set(pubkeys)).sort()
|
||||||
|
|
||||||
const relayUrls = Array.from(relayPool.relays.values()).map(relay => relay.url)
|
// Check for in-flight request with same pubkey set (deduplication)
|
||||||
const prioritized = prioritizeLocalRelays(relayUrls)
|
const requestKey = uniquePubkeys.join(',')
|
||||||
const { local: localRelays, remote: remoteRelays } = partitionRelays(prioritized)
|
const existingRequest = inFlightRequests.get(requestKey)
|
||||||
|
if (existingRequest) {
|
||||||
// Keep only the most recent profile for each pubkey
|
return existingRequest
|
||||||
const profilesByPubkey = new Map<string, NostrEvent>()
|
}
|
||||||
|
|
||||||
const processEvent = (event: NostrEvent) => {
|
// Create the fetch promise and track it
|
||||||
const existing = profilesByPubkey.get(event.pubkey)
|
const fetchPromise = (async () => {
|
||||||
if (!existing || event.created_at > existing.created_at) {
|
// First, check localStorage cache for all requested profiles
|
||||||
profilesByPubkey.set(event.pubkey, event)
|
const cachedProfiles = loadCachedProfiles(uniquePubkeys)
|
||||||
// Store in event store immediately
|
const profilesByPubkey = new Map<string, NostrEvent>()
|
||||||
eventStore.add(event)
|
|
||||||
|
// Add cached profiles to the map and EventStore
|
||||||
|
for (const [pubkey, profile] of cachedProfiles.entries()) {
|
||||||
|
profilesByPubkey.set(pubkey, profile)
|
||||||
|
// Ensure cached profiles are also in EventStore for consistency
|
||||||
|
eventStore.add(profile)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine which pubkeys need to be fetched from relays
|
||||||
|
const pubkeysToFetch = uniquePubkeys.filter(pubkey => !cachedProfiles.has(pubkey))
|
||||||
|
|
||||||
|
// If all profiles are cached, return early
|
||||||
|
if (pubkeysToFetch.length === 0) {
|
||||||
|
return Array.from(profilesByPubkey.values())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const local$ = localRelays.length > 0
|
// Fetch missing profiles from relays
|
||||||
? relayPool
|
const relayUrls = Array.from(relayPool.relays.values()).map(relay => relay.url)
|
||||||
.req(localRelays, { kinds: [0], authors: uniquePubkeys })
|
const prioritized = prioritizeLocalRelays(relayUrls)
|
||||||
.pipe(
|
const { local: localRelays, remote: remoteRelays } = partitionRelays(prioritized)
|
||||||
onlyEvents(),
|
const hasPurplePages = relayUrls.some(url => url.includes('purplepag.es'))
|
||||||
tap((event: NostrEvent) => processEvent(event)),
|
if (!hasPurplePages) {
|
||||||
completeOnEose(),
|
console.warn(`[fetch-profiles] purplepag.es not in active relay pool, adding it temporarily`)
|
||||||
takeUntil(timer(1200))
|
// Add purplepag.es if it's not in the pool (it might not have connected yet)
|
||||||
)
|
const purplePagesUrl = 'wss://purplepag.es'
|
||||||
: new Observable<NostrEvent>((sub) => sub.complete())
|
if (!relayPool.relays.has(purplePagesUrl)) {
|
||||||
|
relayPool.group([purplePagesUrl])
|
||||||
|
}
|
||||||
|
// Ensure it's included in the remote relays for this fetch
|
||||||
|
if (!remoteRelays.includes(purplePagesUrl)) {
|
||||||
|
remoteRelays.push(purplePagesUrl)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const fetchedPubkeys = new Set<string>()
|
||||||
|
|
||||||
const remote$ = remoteRelays.length > 0
|
const processEvent = (event: NostrEvent) => {
|
||||||
? relayPool
|
fetchedPubkeys.add(event.pubkey)
|
||||||
.req(remoteRelays, { kinds: [0], authors: uniquePubkeys })
|
const existing = profilesByPubkey.get(event.pubkey)
|
||||||
.pipe(
|
if (!existing || event.created_at > existing.created_at) {
|
||||||
onlyEvents(),
|
profilesByPubkey.set(event.pubkey, event)
|
||||||
tap((event: NostrEvent) => processEvent(event)),
|
// Store in event store immediately
|
||||||
completeOnEose(),
|
eventStore.add(event)
|
||||||
takeUntil(timer(6000))
|
// Cache to localStorage for future use
|
||||||
)
|
cacheProfile(event)
|
||||||
: new Observable<NostrEvent>((sub) => sub.complete())
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await lastValueFrom(merge(local$, remote$).pipe(toArray()))
|
const local$ = localRelays.length > 0
|
||||||
|
? relayPool
|
||||||
|
.req(localRelays, { kinds: [0], authors: pubkeysToFetch })
|
||||||
|
.pipe(
|
||||||
|
onlyEvents(),
|
||||||
|
onEvent ? tap((event: NostrEvent) => onEvent(event)) : tap(() => {}),
|
||||||
|
tap((event: NostrEvent) => processEvent(event)),
|
||||||
|
completeOnEose()
|
||||||
|
)
|
||||||
|
: new Observable<NostrEvent>((sub) => sub.complete())
|
||||||
|
|
||||||
const profiles = Array.from(profilesByPubkey.values())
|
const remote$ = remoteRelays.length > 0
|
||||||
|
? relayPool
|
||||||
|
.req(remoteRelays, { kinds: [0], authors: pubkeysToFetch })
|
||||||
|
.pipe(
|
||||||
|
onlyEvents(),
|
||||||
|
onEvent ? tap((event: NostrEvent) => onEvent(event)) : tap(() => {}),
|
||||||
|
tap((event: NostrEvent) => processEvent(event)),
|
||||||
|
completeOnEose()
|
||||||
|
)
|
||||||
|
: new Observable<NostrEvent>((sub) => sub.complete())
|
||||||
|
|
||||||
// Rebroadcast profiles to local/all relays based on settings
|
await lastValueFrom(merge(local$, remote$).pipe(toArray()))
|
||||||
if (profiles.length > 0) {
|
|
||||||
await rebroadcastEvents(profiles, relayPool, settings)
|
|
||||||
}
|
|
||||||
|
|
||||||
return profiles
|
const profiles = Array.from(profilesByPubkey.values())
|
||||||
|
|
||||||
|
const missingPubkeys = pubkeysToFetch.filter(p => !fetchedPubkeys.has(p))
|
||||||
|
if (missingPubkeys.length > 0) {
|
||||||
|
console.warn(`[fetch-profiles] ${missingPubkeys.length} profiles not found on relays:`, missingPubkeys.map(p => p.slice(0, 16) + '...'))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: We don't preload all profile images here to avoid ERR_INSUFFICIENT_RESOURCES
|
||||||
|
// Profile images will be cached by Service Worker when they're actually displayed.
|
||||||
|
// Only the logged-in user's profile image is preloaded (in SidebarHeader).
|
||||||
|
|
||||||
|
// Rebroadcast profiles to local/all relays based on settings
|
||||||
|
// Only rebroadcast newly fetched profiles, not cached ones
|
||||||
|
const newlyFetchedProfiles = profiles.filter(p => pubkeysToFetch.includes(p.pubkey))
|
||||||
|
if (newlyFetchedProfiles.length > 0) {
|
||||||
|
await rebroadcastEvents(newlyFetchedProfiles, relayPool, settings)
|
||||||
|
}
|
||||||
|
|
||||||
|
return profiles
|
||||||
|
})()
|
||||||
|
|
||||||
|
// Track the request
|
||||||
|
inFlightRequests.set(requestKey, fetchPromise)
|
||||||
|
|
||||||
|
// Clean up when request completes (success or failure)
|
||||||
|
fetchPromise.finally(() => {
|
||||||
|
inFlightRequests.delete(requestKey)
|
||||||
|
})
|
||||||
|
|
||||||
|
return fetchPromise
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch profiles:', error)
|
console.error('[fetch-profiles] Failed to fetch profiles:', error)
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,3 +110,4 @@ export async function fetchReadableContent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -75,10 +75,17 @@ export function processReadingProgress(
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
} else if (dTag.startsWith('url:')) {
|
} else if (dTag.startsWith('url:')) {
|
||||||
// It's a URL with base64url encoding
|
// It's a URL. We support both raw URLs and base64url-encoded URLs.
|
||||||
const encoded = dTag.replace('url:', '')
|
const value = dTag.slice(4)
|
||||||
|
const looksBase64Url = /^[A-Za-z0-9_-]+$/.test(value) && (value.includes('-') || value.includes('_'))
|
||||||
try {
|
try {
|
||||||
itemUrl = atob(encoded.replace(/-/g, '+').replace(/_/g, '/'))
|
if (looksBase64Url) {
|
||||||
|
// Decode base64url to raw URL
|
||||||
|
itemUrl = atob(value.replace(/-/g, '+').replace(/_/g, '/'))
|
||||||
|
} else {
|
||||||
|
// Treat as raw URL (already decoded)
|
||||||
|
itemUrl = value
|
||||||
|
}
|
||||||
itemId = itemUrl
|
itemId = itemUrl
|
||||||
itemType = 'external'
|
itemType = 'external'
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ export interface ReadingProgressContent {
|
|||||||
progress: number // 0-1 scroll progress
|
progress: number // 0-1 scroll progress
|
||||||
ts?: number // Unix timestamp (optional, for display)
|
ts?: number // Unix timestamp (optional, for display)
|
||||||
loc?: number // Optional: pixel position
|
loc?: number // Optional: pixel position
|
||||||
ver?: string // Schema version
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper to extract and parse reading progress from event (kind 39802)
|
// Helper to extract and parse reading progress from event (kind 39802)
|
||||||
@@ -98,11 +97,8 @@ export function generateArticleIdentifier(naddrOrUrl: string): string {
|
|||||||
if (naddrOrUrl.startsWith('nostr:')) {
|
if (naddrOrUrl.startsWith('nostr:')) {
|
||||||
return naddrOrUrl.replace('nostr:', '')
|
return naddrOrUrl.replace('nostr:', '')
|
||||||
}
|
}
|
||||||
// For URLs, use base64url encoding (URL-safe)
|
// For URLs, return the raw URL. Downstream tag generation will encode as needed.
|
||||||
return btoa(naddrOrUrl)
|
return naddrOrUrl
|
||||||
.replace(/\+/g, '-')
|
|
||||||
.replace(/\//g, '_')
|
|
||||||
.replace(/=+$/, '')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -120,8 +116,7 @@ export async function saveReadingPosition(
|
|||||||
const progressContent: ReadingProgressContent = {
|
const progressContent: ReadingProgressContent = {
|
||||||
progress: position.position,
|
progress: position.position,
|
||||||
ts: position.timestamp,
|
ts: position.timestamp,
|
||||||
loc: position.scrollTop,
|
loc: position.scrollTop
|
||||||
ver: '1'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const tags = generateProgressTags(articleIdentifier)
|
const tags = generateProgressTags(articleIdentifier)
|
||||||
@@ -138,8 +133,136 @@ export async function saveReadingPosition(
|
|||||||
await publishEvent(relayPool, eventStore, signed)
|
await publishEvent(relayPool, eventStore, signed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Streaming reading position loader (non-blocking, EOSE-driven)
|
||||||
|
* Seeds from local eventStore, streams relay updates to store in background
|
||||||
|
* @returns Unsubscribe function to cancel both store watch and network stream
|
||||||
|
*/
|
||||||
|
export function startReadingPositionStream(
|
||||||
|
relayPool: RelayPool,
|
||||||
|
eventStore: IEventStore,
|
||||||
|
pubkey: string,
|
||||||
|
articleIdentifier: string,
|
||||||
|
onPosition: (pos: ReadingPosition | null) => void
|
||||||
|
): () => void {
|
||||||
|
const dTag = generateDTag(articleIdentifier)
|
||||||
|
|
||||||
|
// 1) Seed from local replaceable immediately and watch for updates
|
||||||
|
const storeSub = eventStore
|
||||||
|
.replaceable(READING_PROGRESS_KIND, pubkey, dTag)
|
||||||
|
.subscribe((event: NostrEvent | undefined) => {
|
||||||
|
if (!event) {
|
||||||
|
onPosition(null)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const parsed = getReadingProgressContent(event)
|
||||||
|
onPosition(parsed || null)
|
||||||
|
})
|
||||||
|
|
||||||
|
// 2) Stream from relays in background; pipe into store; no timeout/unsubscribe timer
|
||||||
|
const networkSub = relayPool
|
||||||
|
.subscription(RELAYS, {
|
||||||
|
kinds: [READING_PROGRESS_KIND],
|
||||||
|
authors: [pubkey],
|
||||||
|
'#d': [dTag]
|
||||||
|
})
|
||||||
|
.pipe(onlyEvents(), mapEventsToStore(eventStore))
|
||||||
|
.subscribe()
|
||||||
|
|
||||||
|
// Caller manages lifecycle
|
||||||
|
return () => {
|
||||||
|
try { storeSub.unsubscribe() } catch { /* ignore */ }
|
||||||
|
try { networkSub.unsubscribe() } catch { /* ignore */ }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stabilized reading position collector
|
||||||
|
* Collects position updates for a brief window, then emits the best one (newest, then highest progress)
|
||||||
|
* @returns Object with stop() to cancel and onStable(cb) to register callback
|
||||||
|
*/
|
||||||
|
export function collectReadingPositionsOnce(params: {
|
||||||
|
relayPool: RelayPool
|
||||||
|
eventStore: IEventStore
|
||||||
|
pubkey: string
|
||||||
|
articleIdentifier: string
|
||||||
|
windowMs?: number
|
||||||
|
}): { stop: () => void; onStable: (cb: (pos: ReadingPosition | null) => void) => void } {
|
||||||
|
const { relayPool, eventStore, pubkey, articleIdentifier, windowMs = 700 } = params
|
||||||
|
|
||||||
|
const candidates: ReadingPosition[] = []
|
||||||
|
let stableCallback: ((pos: ReadingPosition | null) => void) | null = null
|
||||||
|
let timer: ReturnType<typeof setTimeout> | null = null
|
||||||
|
let streamStop: (() => void) | null = null
|
||||||
|
let hasEmitted = false
|
||||||
|
|
||||||
|
const emitStable = () => {
|
||||||
|
if (hasEmitted || !stableCallback) return
|
||||||
|
hasEmitted = true
|
||||||
|
|
||||||
|
if (candidates.length === 0) {
|
||||||
|
stableCallback(null)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort: newest first, then highest progress
|
||||||
|
candidates.sort((a, b) => {
|
||||||
|
const timeDiff = b.timestamp - a.timestamp
|
||||||
|
if (timeDiff !== 0) return timeDiff
|
||||||
|
return b.position - a.position
|
||||||
|
})
|
||||||
|
|
||||||
|
stableCallback(candidates[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start streaming and collecting
|
||||||
|
streamStop = startReadingPositionStream(
|
||||||
|
relayPool,
|
||||||
|
eventStore,
|
||||||
|
pubkey,
|
||||||
|
articleIdentifier,
|
||||||
|
(pos) => {
|
||||||
|
if (hasEmitted) return
|
||||||
|
if (!pos) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (pos.position <= 0.05 || pos.position >= 1) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
candidates.push(pos)
|
||||||
|
|
||||||
|
// Schedule one-shot emission if not already scheduled
|
||||||
|
if (!timer) {
|
||||||
|
timer = setTimeout(() => {
|
||||||
|
emitStable()
|
||||||
|
if (streamStop) streamStop()
|
||||||
|
}, windowMs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
|
stop: () => {
|
||||||
|
if (timer) {
|
||||||
|
clearTimeout(timer)
|
||||||
|
timer = null
|
||||||
|
}
|
||||||
|
if (streamStop) {
|
||||||
|
streamStop()
|
||||||
|
streamStop = null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onStable: (cb) => {
|
||||||
|
stableCallback = cb
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load reading position from Nostr (kind 39802)
|
* Load reading position from Nostr (kind 39802)
|
||||||
|
* @deprecated Use startReadingPositionStream for non-blocking behavior
|
||||||
|
* Returns current local position immediately (or null) and starts background sync
|
||||||
*/
|
*/
|
||||||
export async function loadReadingPosition(
|
export async function loadReadingPosition(
|
||||||
relayPool: RelayPool,
|
relayPool: RelayPool,
|
||||||
@@ -149,101 +272,29 @@ export async function loadReadingPosition(
|
|||||||
): Promise<ReadingPosition | null> {
|
): Promise<ReadingPosition | null> {
|
||||||
const dTag = generateDTag(articleIdentifier)
|
const dTag = generateDTag(articleIdentifier)
|
||||||
|
|
||||||
// Check local event store first
|
let initial: ReadingPosition | null = null
|
||||||
try {
|
try {
|
||||||
const localEvent = await firstValueFrom(
|
const localEvent = await firstValueFrom(
|
||||||
eventStore.replaceable(READING_PROGRESS_KIND, pubkey, dTag)
|
eventStore.replaceable(READING_PROGRESS_KIND, pubkey, dTag)
|
||||||
)
|
)
|
||||||
if (localEvent) {
|
if (localEvent) {
|
||||||
const content = getReadingProgressContent(localEvent)
|
const content = getReadingProgressContent(localEvent)
|
||||||
if (content) {
|
if (content) initial = content
|
||||||
// Fetch from relays in background to get any updates
|
|
||||||
relayPool
|
|
||||||
.subscription(RELAYS, {
|
|
||||||
kinds: [READING_PROGRESS_KIND],
|
|
||||||
authors: [pubkey],
|
|
||||||
'#d': [dTag]
|
|
||||||
})
|
|
||||||
.pipe(onlyEvents(), mapEventsToStore(eventStore))
|
|
||||||
.subscribe()
|
|
||||||
|
|
||||||
return content
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch {
|
||||||
// Ignore errors and fetch from relays
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch from relays
|
// Start background sync (fire-and-forget; no timeout)
|
||||||
const result = await fetchFromRelays(
|
relayPool
|
||||||
relayPool,
|
.subscription(RELAYS, {
|
||||||
eventStore,
|
kinds: [READING_PROGRESS_KIND],
|
||||||
pubkey,
|
authors: [pubkey],
|
||||||
READING_PROGRESS_KIND,
|
'#d': [dTag]
|
||||||
dTag,
|
})
|
||||||
getReadingProgressContent
|
.pipe(onlyEvents(), mapEventsToStore(eventStore))
|
||||||
)
|
.subscribe()
|
||||||
|
|
||||||
return result || null
|
return initial
|
||||||
}
|
|
||||||
|
|
||||||
// Helper function to fetch from relays with timeout
|
|
||||||
async function fetchFromRelays(
|
|
||||||
relayPool: RelayPool,
|
|
||||||
eventStore: IEventStore,
|
|
||||||
pubkey: string,
|
|
||||||
kind: number,
|
|
||||||
dTag: string,
|
|
||||||
parser: (event: NostrEvent) => ReadingPosition | undefined
|
|
||||||
): Promise<ReadingPosition | null> {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
let hasResolved = false
|
|
||||||
const timeout = setTimeout(() => {
|
|
||||||
if (!hasResolved) {
|
|
||||||
hasResolved = true
|
|
||||||
resolve(null)
|
|
||||||
}
|
|
||||||
}, 3000)
|
|
||||||
|
|
||||||
const sub = relayPool
|
|
||||||
.subscription(RELAYS, {
|
|
||||||
kinds: [kind],
|
|
||||||
authors: [pubkey],
|
|
||||||
'#d': [dTag]
|
|
||||||
})
|
|
||||||
.pipe(onlyEvents(), mapEventsToStore(eventStore))
|
|
||||||
.subscribe({
|
|
||||||
complete: async () => {
|
|
||||||
clearTimeout(timeout)
|
|
||||||
if (!hasResolved) {
|
|
||||||
hasResolved = true
|
|
||||||
try {
|
|
||||||
const event = await firstValueFrom(
|
|
||||||
eventStore.replaceable(kind, pubkey, dTag)
|
|
||||||
)
|
|
||||||
if (event) {
|
|
||||||
const content = parser(event)
|
|
||||||
resolve(content || null)
|
|
||||||
} else {
|
|
||||||
resolve(null)
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
resolve(null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error: () => {
|
|
||||||
clearTimeout(timeout)
|
|
||||||
if (!hasResolved) {
|
|
||||||
hasResolved = true
|
|
||||||
resolve(null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
sub.unsubscribe()
|
|
||||||
}, 3000)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ type ProgressMapCallback = (progressMap: Map<string, number>) => void
|
|||||||
type LoadingCallback = (loading: boolean) => void
|
type LoadingCallback = (loading: boolean) => void
|
||||||
|
|
||||||
const LAST_SYNCED_KEY = 'reading_progress_last_synced'
|
const LAST_SYNCED_KEY = 'reading_progress_last_synced'
|
||||||
const PROGRESS_CACHE_KEY = 'reading_progress_cache_v1'
|
const PROGRESS_CACHE_KEY = 'reading_progress_cache'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shared reading progress controller
|
* Shared reading progress controller
|
||||||
@@ -276,10 +276,10 @@ class ReadingProgressController {
|
|||||||
// Process new events
|
// Process new events
|
||||||
processReadingProgress(events, readsMap)
|
processReadingProgress(events, readsMap)
|
||||||
|
|
||||||
// Convert back to progress map (naddr -> progress)
|
// Convert back to progress map (id -> progress). Include both articles and external URLs.
|
||||||
const newProgressMap = new Map<string, number>()
|
const newProgressMap = new Map<string, number>()
|
||||||
for (const [id, item] of readsMap.entries()) {
|
for (const [id, item] of readsMap.entries()) {
|
||||||
if (item.readingProgress !== undefined && item.type === 'article') {
|
if (item.readingProgress !== undefined) {
|
||||||
newProgressMap.set(id, item.readingProgress)
|
newProgressMap.set(id, item.readingProgress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ export async function fetchAllReads(
|
|||||||
source: 'bookmark',
|
source: 'bookmark',
|
||||||
type: 'article',
|
type: 'article',
|
||||||
readingProgress: 0,
|
readingProgress: 0,
|
||||||
readingTimestamp: bookmark.added_at || bookmark.created_at
|
readingTimestamp: bookmark.created_at ?? undefined
|
||||||
}
|
}
|
||||||
readsMap.set(coordinate, item)
|
readsMap.set(coordinate, item)
|
||||||
if (onItem) emitItem(item)
|
if (onItem) emitItem(item)
|
||||||
|
|||||||
@@ -81,7 +81,15 @@ export function applyRelaySetToPool(
|
|||||||
for (const url of toRemove) {
|
for (const url of toRemove) {
|
||||||
const relay = relayPool.relays.get(url)
|
const relay = relayPool.relays.get(url)
|
||||||
if (relay) {
|
if (relay) {
|
||||||
relay.close()
|
try {
|
||||||
|
// Only close if relay is actually connected or attempting to connect
|
||||||
|
// This helps avoid WebSocket warnings for connections that never started
|
||||||
|
relay.close()
|
||||||
|
} catch (error) {
|
||||||
|
// Suppress errors when closing relays that haven't fully connected yet
|
||||||
|
// This can happen when switching relay sets before connections establish
|
||||||
|
// Silently ignore
|
||||||
|
}
|
||||||
relayPool.relays.delete(url)
|
relayPool.relays.delete(url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ export interface UserSettings {
|
|||||||
renderVideoLinksAsEmbeds?: boolean // default: false
|
renderVideoLinksAsEmbeds?: boolean // default: false
|
||||||
// Reading position sync
|
// Reading position sync
|
||||||
syncReadingPosition?: boolean // default: false (opt-in)
|
syncReadingPosition?: boolean // default: false (opt-in)
|
||||||
|
autoScrollToReadingPosition?: boolean // default: true - automatically scroll to saved position when opening article
|
||||||
autoMarkAsReadOnCompletion?: boolean // default: false (opt-in)
|
autoMarkAsReadOnCompletion?: boolean // default: false (opt-in)
|
||||||
// Bookmark filtering
|
// Bookmark filtering
|
||||||
hideBookmarksWithoutCreationDate?: boolean // default: false
|
hideBookmarksWithoutCreationDate?: boolean // default: false
|
||||||
@@ -75,90 +76,82 @@ export interface UserSettings {
|
|||||||
ttsDefaultSpeed?: number // default: 2.1
|
ttsDefaultSpeed?: number // default: 2.1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Streaming settings loader (non-blocking, EOSE-driven)
|
||||||
|
* Seeds from local eventStore, streams relay updates to store in background
|
||||||
|
* @returns Unsubscribe function to cancel both store watch and network stream
|
||||||
|
*/
|
||||||
|
export function startSettingsStream(
|
||||||
|
relayPool: RelayPool,
|
||||||
|
eventStore: IEventStore,
|
||||||
|
pubkey: string,
|
||||||
|
relays: string[],
|
||||||
|
onSettings: (settings: UserSettings | null) => void
|
||||||
|
): () => void {
|
||||||
|
// 1) Seed from local replaceable immediately and watch for updates
|
||||||
|
const storeSub = eventStore
|
||||||
|
.replaceable(APP_DATA_KIND, pubkey, SETTINGS_IDENTIFIER)
|
||||||
|
.subscribe((event: NostrEvent | undefined) => {
|
||||||
|
if (!event) {
|
||||||
|
onSettings(null)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const content = getAppDataContent<UserSettings>(event)
|
||||||
|
onSettings(content || null)
|
||||||
|
})
|
||||||
|
|
||||||
|
// 2) Stream from relays in background; pipe into store; no timeout/unsubscribe timer
|
||||||
|
const networkSub = relayPool
|
||||||
|
.subscription(relays, {
|
||||||
|
kinds: [APP_DATA_KIND],
|
||||||
|
authors: [pubkey],
|
||||||
|
'#d': [SETTINGS_IDENTIFIER]
|
||||||
|
})
|
||||||
|
.pipe(onlyEvents(), mapEventsToStore(eventStore))
|
||||||
|
.subscribe()
|
||||||
|
|
||||||
|
// Caller manages lifecycle
|
||||||
|
return () => {
|
||||||
|
try { storeSub.unsubscribe() } catch { /* ignore */ }
|
||||||
|
try { networkSub.unsubscribe() } catch { /* ignore */ }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use startSettingsStream + watchSettings for non-blocking behavior.
|
||||||
|
* Returns current local settings immediately (or null if not present) and starts background sync.
|
||||||
|
*/
|
||||||
export async function loadSettings(
|
export async function loadSettings(
|
||||||
relayPool: RelayPool,
|
relayPool: RelayPool,
|
||||||
eventStore: IEventStore,
|
eventStore: IEventStore,
|
||||||
pubkey: string,
|
pubkey: string,
|
||||||
relays: string[]
|
relays: string[]
|
||||||
): Promise<UserSettings | null> {
|
): Promise<UserSettings | null> {
|
||||||
|
let initial: UserSettings | null = null
|
||||||
// First, check if we already have settings in the local event store
|
|
||||||
try {
|
try {
|
||||||
const localEvent = await firstValueFrom(
|
const localEvent = await firstValueFrom(
|
||||||
eventStore.replaceable(APP_DATA_KIND, pubkey, SETTINGS_IDENTIFIER)
|
eventStore.replaceable(APP_DATA_KIND, pubkey, SETTINGS_IDENTIFIER)
|
||||||
)
|
)
|
||||||
if (localEvent) {
|
if (localEvent) {
|
||||||
const content = getAppDataContent<UserSettings>(localEvent)
|
const content = getAppDataContent<UserSettings>(localEvent)
|
||||||
|
initial = content || null
|
||||||
// Still fetch from relays in the background to get any updates
|
|
||||||
relayPool
|
|
||||||
.subscription(relays, {
|
|
||||||
kinds: [APP_DATA_KIND],
|
|
||||||
authors: [pubkey],
|
|
||||||
'#d': [SETTINGS_IDENTIFIER]
|
|
||||||
})
|
|
||||||
.pipe(onlyEvents(), mapEventsToStore(eventStore))
|
|
||||||
.subscribe()
|
|
||||||
|
|
||||||
return content || null
|
|
||||||
}
|
}
|
||||||
} catch (_err) {
|
} catch {
|
||||||
// Ignore local store errors
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
// If not in local store, fetch from relays
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
let hasResolved = false
|
|
||||||
const timeout = setTimeout(() => {
|
|
||||||
if (!hasResolved) {
|
|
||||||
console.warn('⚠️ Settings load timeout - no settings event found')
|
|
||||||
hasResolved = true
|
|
||||||
resolve(null)
|
|
||||||
}
|
|
||||||
}, 5000)
|
|
||||||
|
|
||||||
const sub = relayPool
|
// Start background sync (fire-and-forget; no timeout)
|
||||||
.subscription(relays, {
|
relayPool
|
||||||
kinds: [APP_DATA_KIND],
|
.subscription(relays, {
|
||||||
authors: [pubkey],
|
kinds: [APP_DATA_KIND],
|
||||||
'#d': [SETTINGS_IDENTIFIER]
|
authors: [pubkey],
|
||||||
})
|
'#d': [SETTINGS_IDENTIFIER]
|
||||||
.pipe(onlyEvents(), mapEventsToStore(eventStore))
|
})
|
||||||
.subscribe({
|
.pipe(onlyEvents(), mapEventsToStore(eventStore))
|
||||||
complete: async () => {
|
.subscribe()
|
||||||
clearTimeout(timeout)
|
|
||||||
if (!hasResolved) {
|
|
||||||
hasResolved = true
|
|
||||||
try {
|
|
||||||
const event = await firstValueFrom(
|
|
||||||
eventStore.replaceable(APP_DATA_KIND, pubkey, SETTINGS_IDENTIFIER)
|
|
||||||
)
|
|
||||||
if (event) {
|
|
||||||
const content = getAppDataContent<UserSettings>(event)
|
|
||||||
resolve(content || null)
|
|
||||||
} else {
|
|
||||||
resolve(null)
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error('❌ Error loading settings:', err)
|
|
||||||
resolve(null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error: (err) => {
|
|
||||||
console.error('❌ Settings subscription error:', err)
|
|
||||||
clearTimeout(timeout)
|
|
||||||
if (!hasResolved) {
|
|
||||||
hasResolved = true
|
|
||||||
resolve(null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
setTimeout(() => {
|
return initial
|
||||||
sub.unsubscribe()
|
|
||||||
}, 5000)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function saveSettings(
|
export async function saveSettings(
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ const { getArticleTitle, getArticleSummary, getArticleImage, getArticlePublished
|
|||||||
type WritingsCallback = (posts: BlogPostPreview[]) => void
|
type WritingsCallback = (posts: BlogPostPreview[]) => void
|
||||||
type LoadingCallback = (loading: boolean) => void
|
type LoadingCallback = (loading: boolean) => void
|
||||||
|
|
||||||
const LAST_SYNCED_KEY = 'writings_last_synced'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shared writings controller
|
* Shared writings controller
|
||||||
* Manages the user's nostr-native long-form articles (kind:30023) centrally,
|
* Manages the user's nostr-native long-form articles (kind:30023) centrally,
|
||||||
@@ -71,34 +69,6 @@ class WritingsController {
|
|||||||
this.emitWritings(this.currentPosts)
|
this.emitWritings(this.currentPosts)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get last synced timestamp for incremental loading
|
|
||||||
*/
|
|
||||||
private getLastSyncedAt(pubkey: string): number | null {
|
|
||||||
try {
|
|
||||||
const data = localStorage.getItem(LAST_SYNCED_KEY)
|
|
||||||
if (!data) return null
|
|
||||||
const parsed = JSON.parse(data)
|
|
||||||
return parsed[pubkey] || null
|
|
||||||
} catch {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update last synced timestamp
|
|
||||||
*/
|
|
||||||
private setLastSyncedAt(pubkey: string, timestamp: number): void {
|
|
||||||
try {
|
|
||||||
const data = localStorage.getItem(LAST_SYNCED_KEY)
|
|
||||||
const parsed = data ? JSON.parse(data) : {}
|
|
||||||
parsed[pubkey] = timestamp
|
|
||||||
localStorage.setItem(LAST_SYNCED_KEY, JSON.stringify(parsed))
|
|
||||||
} catch (err) {
|
|
||||||
console.warn('[writings] Failed to save last synced timestamp:', err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert NostrEvent to BlogPostPreview using applesauce Helpers
|
* Convert NostrEvent to BlogPostPreview using applesauce Helpers
|
||||||
*/
|
*/
|
||||||
@@ -127,6 +97,7 @@ class WritingsController {
|
|||||||
/**
|
/**
|
||||||
* Load writings for a user (kind:30023)
|
* Load writings for a user (kind:30023)
|
||||||
* Streams results and stores in event store
|
* Streams results and stores in event store
|
||||||
|
* Always fetches ALL writings to ensure completeness
|
||||||
*/
|
*/
|
||||||
async start(options: {
|
async start(options: {
|
||||||
relayPool: RelayPool
|
relayPool: RelayPool
|
||||||
@@ -152,15 +123,12 @@ class WritingsController {
|
|||||||
const seenIds = new Set<string>()
|
const seenIds = new Set<string>()
|
||||||
const uniqueByReplaceable = new Map<string, BlogPostPreview>()
|
const uniqueByReplaceable = new Map<string, BlogPostPreview>()
|
||||||
|
|
||||||
// Get last synced timestamp for incremental loading
|
// Fetch ALL writings without limits (no since filter)
|
||||||
const lastSyncedAt = force ? null : this.getLastSyncedAt(pubkey)
|
// This ensures we get complete results for profile/my pages
|
||||||
const filter: { kinds: number[]; authors: string[]; since?: number } = {
|
const filter = {
|
||||||
kinds: [KINDS.BlogPost],
|
kinds: [KINDS.BlogPost],
|
||||||
authors: [pubkey]
|
authors: [pubkey]
|
||||||
}
|
}
|
||||||
if (lastSyncedAt) {
|
|
||||||
filter.since = lastSyncedAt
|
|
||||||
}
|
|
||||||
|
|
||||||
const events = await queryEvents(
|
const events = await queryEvents(
|
||||||
relayPool,
|
relayPool,
|
||||||
@@ -221,12 +189,6 @@ class WritingsController {
|
|||||||
this.lastLoadedPubkey = pubkey
|
this.lastLoadedPubkey = pubkey
|
||||||
this.emitWritings(sorted)
|
this.emitWritings(sorted)
|
||||||
|
|
||||||
// Update last synced timestamp
|
|
||||||
if (sorted.length > 0) {
|
|
||||||
const newestTimestamp = Math.max(...sorted.map(p => p.event.created_at))
|
|
||||||
this.setLastSyncedAt(pubkey, newestTimestamp)
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[writings] ❌ Failed to load writings:', error)
|
console.error('[writings] ❌ Failed to load writings:', error)
|
||||||
this.currentPosts = []
|
this.currentPosts = []
|
||||||
|
|||||||
@@ -59,7 +59,7 @@
|
|||||||
.compact-read-btn:active { transform: translateY(1px); }
|
.compact-read-btn:active { transform: translateY(1px); }
|
||||||
|
|
||||||
.bookmark-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; flex-wrap: wrap; gap: 0.5rem; }
|
.bookmark-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; flex-wrap: wrap; gap: 0.5rem; }
|
||||||
.bookmark-type { color: var(--color-primary); font-size: 0.9rem; display: flex; align-items: center; gap: 0.35rem; }
|
.bookmark-type { font-size: 0.9rem; display: flex; align-items: center; gap: 0.35rem; }
|
||||||
.bookmark-id { font-family: monospace; font-size: 0.8rem; color: var(--color-text-secondary); background: var(--color-bg); padding: 0.25rem 0.5rem; border-radius: 4px; }
|
.bookmark-id { font-family: monospace; font-size: 0.8rem; color: var(--color-text-secondary); background: var(--color-bg); padding: 0.25rem 0.5rem; border-radius: 4px; }
|
||||||
.bookmark-date { font-size: 0.8rem; color: var(--color-text-muted); }
|
.bookmark-date { font-size: 0.8rem; color: var(--color-text-muted); }
|
||||||
.bookmark-date-link { font-size: 0.8rem; color: var(--color-text-muted); text-decoration: none; transition: color 0.2s ease; }
|
.bookmark-date-link { font-size: 0.8rem; color: var(--color-text-muted); text-decoration: none; transition: color 0.2s ease; }
|
||||||
@@ -76,6 +76,179 @@
|
|||||||
.expand-toggle-urls { margin-top: 0.5rem; background: transparent; border: none; color: var(--color-primary); cursor: pointer; font-size: 0.8rem; padding: 0.25rem 0; text-decoration: underline; }
|
.expand-toggle-urls { margin-top: 0.5rem; background: transparent; border: none; color: var(--color-primary); cursor: pointer; font-size: 0.8rem; padding: 0.25rem 0; text-decoration: underline; }
|
||||||
.expand-toggle-urls:hover { color: var(--color-primary-hover); }
|
.expand-toggle-urls:hover { color: var(--color-primary-hover); }
|
||||||
|
|
||||||
|
/* Medium-sized card view */
|
||||||
|
.individual-bookmark.card-view {
|
||||||
|
padding: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
overflow: hidden;
|
||||||
|
border: 1px solid var(--color-bg-elevated);
|
||||||
|
border-radius: 12px;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
background: var(--color-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.individual-bookmark.card-view:hover {
|
||||||
|
border-color: var(--color-border);
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||||
|
transform: translateY(-2px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-layout {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding: 1.25rem;
|
||||||
|
gap: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-content-header {
|
||||||
|
display: flex;
|
||||||
|
gap: 1rem;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-text-content {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-thumbnail {
|
||||||
|
width: 80px;
|
||||||
|
height: 80px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
background: linear-gradient(135deg, var(--color-bg-elevated) 0%, var(--color-bg-subtle) 50%, var(--color-bg-elevated) 100%);
|
||||||
|
background-size: cover;
|
||||||
|
background-position: center;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
border-radius: 8px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-thumbnail:hover {
|
||||||
|
opacity: 0.9;
|
||||||
|
transform: scale(1.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-thumbnail::after {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
background: linear-gradient(to bottom, transparent 60%, rgba(0,0,0,0.1) 100%);
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-thumbnail .thumbnail-placeholder {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
color: var(--color-border-subtle);
|
||||||
|
opacity: 0.6;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-content {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.25rem;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-content .bookmark-header {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-content .bookmark-title {
|
||||||
|
font-size: 1.1rem;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--color-text);
|
||||||
|
margin: 0 0 0.25rem 0;
|
||||||
|
line-height: 1.4;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
display: -webkit-box;
|
||||||
|
-webkit-line-clamp: 2;
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-content .bookmark-content {
|
||||||
|
font-size: 0.9rem;
|
||||||
|
line-height: 1.6;
|
||||||
|
color: var(--color-text);
|
||||||
|
margin: 0;
|
||||||
|
display: -webkit-box;
|
||||||
|
-webkit-line-clamp: 3;
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-content .bookmark-content.article-summary {
|
||||||
|
-webkit-line-clamp: 2;
|
||||||
|
font-style: italic;
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-content .bookmark-footer {
|
||||||
|
margin-top: auto;
|
||||||
|
padding-top: 0.125rem;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-content .bookmark-footer-right {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-content .bookmark-footer .bookmark-type {
|
||||||
|
font-size: 0.9rem;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.35rem;
|
||||||
|
color: var(--color-text-secondary) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-content .bookmark-footer .bookmark-type .content-type-icon {
|
||||||
|
color: var(--color-text-secondary) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-content .bookmark-footer .bookmark-date,
|
||||||
|
.card-content .bookmark-footer .bookmark-date-link {
|
||||||
|
display: inline;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reading progress as separator - always shown, full width */
|
||||||
|
.reading-progress-separator {
|
||||||
|
height: 1px;
|
||||||
|
width: 100%;
|
||||||
|
background: var(--color-border);
|
||||||
|
border-radius: 0.5px;
|
||||||
|
overflow: hidden;
|
||||||
|
margin: 0.125rem 0;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reading-progress-separator .progress-fill {
|
||||||
|
height: 100%;
|
||||||
|
border-radius: 0.5px;
|
||||||
|
transition: width 0.3s ease, background 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Large preview view */
|
/* Large preview view */
|
||||||
.individual-bookmark.large { padding: 0; display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--color-bg-elevated); }
|
.individual-bookmark.large { padding: 0; display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--color-bg-elevated); }
|
||||||
.large-preview-image { width: 100%; height: 180px; background: linear-gradient(135deg, var(--color-bg-elevated) 0%, var(--color-bg-subtle) 50%, var(--color-bg-elevated) 100%); background-size: cover; background-position: center; background-repeat: no-repeat; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.2s ease; border-bottom: 1px solid var(--color-border); position: relative; }
|
.large-preview-image { width: 100%; height: 180px; background: linear-gradient(135deg, var(--color-bg-elevated) 0%, var(--color-bg-subtle) 50%, var(--color-bg-elevated) 100%); background-size: cover; background-position: center; background-repeat: no-repeat; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.2s ease; border-bottom: 1px solid var(--color-border); position: relative; }
|
||||||
@@ -115,6 +288,74 @@
|
|||||||
.blog-post-card-meta { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding-top: 0.75rem; border-top: 1px solid var(--color-border); font-size: 0.75rem; color: var(--color-text-muted); flex-wrap: wrap; }
|
.blog-post-card-meta { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding-top: 0.75rem; border-top: 1px solid var(--color-border); font-size: 0.75rem; color: var(--color-text-muted); flex-wrap: wrap; }
|
||||||
.blog-post-card-author, .blog-post-card-date { display: flex; align-items: center; gap: 0.5rem; }
|
.blog-post-card-author, .blog-post-card-date { display: flex; align-items: center; gap: 0.5rem; }
|
||||||
.blog-post-card-author svg, .blog-post-card-date svg { opacity: 0.7; }
|
.blog-post-card-author svg, .blog-post-card-date svg { opacity: 0.7; }
|
||||||
|
/* Responsive design for medium-sized cards */
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.individual-bookmark.card-view {
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-layout {
|
||||||
|
padding: 1rem;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-content-header {
|
||||||
|
gap: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-thumbnail {
|
||||||
|
width: 60px;
|
||||||
|
height: 60px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-text-content {
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-content .bookmark-title {
|
||||||
|
font-size: 1rem;
|
||||||
|
margin-bottom: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-content .bookmark-content {
|
||||||
|
font-size: 0.85rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-content .bookmark-footer {
|
||||||
|
padding-top: 0.125rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 480px) {
|
||||||
|
.card-layout {
|
||||||
|
padding: 0.75rem;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-content-header {
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-thumbnail {
|
||||||
|
width: 50px;
|
||||||
|
height: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-thumbnail .thumbnail-placeholder {
|
||||||
|
font-size: 1.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-content .bookmark-title {
|
||||||
|
font-size: 0.9rem;
|
||||||
|
margin-bottom: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-content .bookmark-content {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
.explore-container { padding: 1rem; }
|
.explore-container { padding: 1rem; }
|
||||||
.explore-header h1 { font-size: 2rem; }
|
.explore-header h1 { font-size: 2rem; }
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Me page tabs */
|
/* My page tabs */
|
||||||
.me-tabs {
|
.me-tabs {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
@@ -71,10 +71,22 @@
|
|||||||
padding-top: 0.25rem;
|
padding-top: 0.25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Align highlight list width with profile card width on /me */
|
/* Align highlight list width with profile card width on /my */
|
||||||
.me-highlights-list { padding-left: 0; padding-right: 0; }
|
.me-highlights-list { padding-left: 0; padding-right: 0; }
|
||||||
.explore-header .author-card { max-width: 600px; margin: 0 auto; width: 100%; }
|
.explore-header .author-card { max-width: 600px; margin: 0 auto; width: 100%; }
|
||||||
|
|
||||||
|
/* Hide tab labels on mobile to save space */
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.me-tab .tab-label {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.me-tab {
|
||||||
|
padding: 0.75rem;
|
||||||
|
gap: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Bookmarks list */
|
/* Bookmarks list */
|
||||||
.bookmarks-list {
|
.bookmarks-list {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -83,7 +95,7 @@
|
|||||||
text-align: left; /* Override center alignment from .app */
|
text-align: left; /* Override center alignment from .app */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Bookmark filters in Me page */
|
/* Bookmark filters in My page */
|
||||||
.me-tab-content .bookmark-filters {
|
.me-tab-content .bookmark-filters {
|
||||||
background: transparent;
|
background: transparent;
|
||||||
border: none;
|
border: none;
|
||||||
|
|||||||
@@ -35,6 +35,8 @@
|
|||||||
.reading-time svg { font-size: 0.875rem; }
|
.reading-time svg { font-size: 0.875rem; }
|
||||||
.highlight-indicator { display: flex; align-items: center; gap: 0.5rem; padding: 0.375rem 0.75rem; background: rgba(99, 102, 241, 0.1); border: 1px solid rgba(99, 102, 241, 0.3); border-radius: 6px; font-size: 0.875rem; color: var(--color-text); }
|
.highlight-indicator { display: flex; align-items: center; gap: 0.5rem; padding: 0.375rem 0.75rem; background: rgba(99, 102, 241, 0.1); border: 1px solid rgba(99, 102, 241, 0.3); border-radius: 6px; font-size: 0.875rem; color: var(--color-text); }
|
||||||
.highlight-indicator svg { font-size: 0.875rem; }
|
.highlight-indicator svg { font-size: 0.875rem; }
|
||||||
|
.highlight-indicator.clickable { cursor: pointer; transition: all 0.2s ease; }
|
||||||
|
.highlight-indicator.clickable:hover { background: rgba(99, 102, 241, 0.15); border-color: rgba(99, 102, 241, 0.5); transform: translateY(-1px); }
|
||||||
.reader-html { color: var(--color-text); line-height: 1.6; word-wrap: break-word; overflow-wrap: break-word; word-break: break-word; font-family: var(--reading-font); font-size: var(--reading-font-size); }
|
.reader-html { color: var(--color-text); line-height: 1.6; word-wrap: break-word; overflow-wrap: break-word; word-break: break-word; font-family: var(--reading-font); font-size: var(--reading-font-size); }
|
||||||
.reader-markdown { color: var(--color-text); line-height: 1.7; font-family: var(--reading-font); font-size: var(--reading-font-size); }
|
.reader-markdown { color: var(--color-text); line-height: 1.7; font-family: var(--reading-font); font-size: var(--reading-font-size); }
|
||||||
/* Ensure font inheritance */
|
/* Ensure font inheritance */
|
||||||
@@ -55,13 +57,14 @@
|
|||||||
.reader .reader-markdown h1, .reader .reader-markdown h2, .reader .reader-markdown h3, .reader .reader-markdown h4, .reader .reader-markdown h5, .reader .reader-markdown h6 { text-align: left !important; }
|
.reader .reader-markdown h1, .reader .reader-markdown h2, .reader .reader-markdown h3, .reader .reader-markdown h4, .reader .reader-markdown h5, .reader .reader-markdown h6 { text-align: left !important; }
|
||||||
/* Tame images from external content */
|
/* Tame images from external content */
|
||||||
.reader .reader-html img, .reader .reader-markdown img {
|
.reader .reader-html img, .reader .reader-markdown img {
|
||||||
max-width: var(--image-max-width, 100%);
|
width: var(--image-width, auto);
|
||||||
max-height: 70vh;
|
max-width: 100%;
|
||||||
|
max-height: var(--image-max-height, 70vh);
|
||||||
height: auto;
|
height: auto;
|
||||||
width: auto;
|
|
||||||
display: block;
|
display: block;
|
||||||
margin: 0.75rem auto;
|
margin: 0.75rem auto;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
|
object-fit: contain;
|
||||||
}
|
}
|
||||||
/* Headlines with Tailwind typography */
|
/* Headlines with Tailwind typography */
|
||||||
.reader-markdown h1, .reader-html h1 {
|
.reader-markdown h1, .reader-html h1 {
|
||||||
@@ -143,7 +146,7 @@
|
|||||||
}
|
}
|
||||||
.reader-markdown blockquote, .reader-html blockquote {
|
.reader-markdown blockquote, .reader-html blockquote {
|
||||||
margin: 1.5rem 0;
|
margin: 1.5rem 0;
|
||||||
padding: 1rem 0 1rem 2rem;
|
padding: 1rem 2rem;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
.reader-markdown blockquote p, .reader-html blockquote p { margin: 0.5rem 0; }
|
.reader-markdown blockquote p, .reader-html blockquote p { margin: 0.5rem 0; }
|
||||||
@@ -190,8 +193,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.reader-markdown img, .reader-html img {
|
.reader-markdown img, .reader-html img {
|
||||||
max-width: 100%;
|
width: var(--image-width, auto) !important;
|
||||||
|
max-width: 100% !important;
|
||||||
|
max-height: var(--image-max-height, 70vh) !important;
|
||||||
height: auto;
|
height: auto;
|
||||||
|
object-fit: contain;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,7 +236,7 @@
|
|||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0.5rem;
|
padding: 0.5rem 1rem;
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
border-left: none;
|
border-left: none;
|
||||||
border-right: none;
|
border-right: none;
|
||||||
@@ -259,7 +265,7 @@
|
|||||||
.reader-header-overlay .reader-summary.hide-on-mobile { display: none; }
|
.reader-header-overlay .reader-summary.hide-on-mobile { display: none; }
|
||||||
.reader-summary-below-image { display: block; padding: 0 0 1.5rem 0; margin-top: -1rem; }
|
.reader-summary-below-image { display: block; padding: 0 0 1.5rem 0; margin-top: -1rem; }
|
||||||
.reader-summary-below-image .reader-summary { color: var(--color-text-secondary); font-size: 1rem; line-height: 1.6; margin: 0; }
|
.reader-summary-below-image .reader-summary { color: var(--color-text-secondary); font-size: 1rem; line-height: 1.6; margin: 0; }
|
||||||
.reader-hero-image { min-height: 280px; max-height: 400px; height: 50vh; }
|
.reader-hero-image { width: calc(100% + 2rem); margin: -0.5rem -1rem 2rem -1rem; min-height: 280px; max-height: 400px; height: 50vh; }
|
||||||
.reader-hero-image img { height: 100%; width: 100%; object-fit: cover; object-position: center; }
|
.reader-hero-image img { height: 100%; width: 100%; object-fit: cover; object-position: center; }
|
||||||
.reader-header-overlay { padding: 1.5rem 1rem 1rem; }
|
.reader-header-overlay { padding: 1.5rem 1rem 1rem; }
|
||||||
.reader-header-overlay .reader-title { font-size: 2rem; line-height: 1.3; }
|
.reader-header-overlay .reader-title { font-size: 2rem; line-height: 1.3; }
|
||||||
@@ -267,3 +273,21 @@
|
|||||||
|
|
||||||
/* Reading Progress Indicator - now using Tailwind utilities in component */
|
/* Reading Progress Indicator - now using Tailwind utilities in component */
|
||||||
|
|
||||||
|
/* Profile loading state - subtle opacity pulse animation */
|
||||||
|
.profile-loading {
|
||||||
|
opacity: 0.6;
|
||||||
|
animation: profile-loading-pulse 1.5s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
.profile-loading {
|
||||||
|
animation: none;
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes profile-loading-pulse {
|
||||||
|
0%, 100% { opacity: 0.6; }
|
||||||
|
50% { opacity: 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,28 @@
|
|||||||
|
|
||||||
.highlights-actions { display: flex; align-items: center; justify-content: space-between; width: 100%; }
|
.highlights-actions { display: flex; align-items: center; justify-content: space-between; width: 100%; }
|
||||||
.highlights-actions-left { display: flex; align-items: center; gap: 0.5rem; }
|
.highlights-actions-left { display: flex; align-items: center; gap: 0.5rem; }
|
||||||
|
.highlights-actions-right { display: flex; align-items: center; gap: 0.5rem; }
|
||||||
|
|
||||||
|
/* Collapse button in highlights header */
|
||||||
|
.highlights-header .toggle-highlights-btn {
|
||||||
|
background: transparent;
|
||||||
|
color: var(--color-text);
|
||||||
|
border: 1px solid var(--color-border-subtle);
|
||||||
|
padding: 0;
|
||||||
|
border-radius: 6px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 33px;
|
||||||
|
height: 33px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.highlights-header .toggle-highlights-btn:hover { background: var(--color-bg-elevated); color: var(--color-text); }
|
||||||
|
.highlights-header .toggle-highlights-btn:active { transform: translateY(1px); }
|
||||||
|
|
||||||
.highlights-title { display: flex; align-items: center; gap: 0.5rem; }
|
.highlights-title { display: flex; align-items: center; gap: 0.5rem; }
|
||||||
.highlights-title h3 { margin: 0; font-size: 1rem; font-weight: 600; }
|
.highlights-title h3 { margin: 0; font-size: 1rem; font-weight: 600; }
|
||||||
|
|||||||
@@ -54,11 +54,20 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sidebar-header-left {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
.sidebar-header-right {
|
.sidebar-header-right {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
|
flex: 1;
|
||||||
|
justify-content: flex-end;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mobile hamburger button now uses Tailwind utilities in ThreePaneLayout */
|
/* Mobile hamburger button now uses Tailwind utilities in ThreePaneLayout */
|
||||||
@@ -92,7 +101,7 @@
|
|||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.profile-avatar {
|
.profile-avatar-button {
|
||||||
min-width: 33px;
|
min-width: 33px;
|
||||||
min-height: 33px;
|
min-height: 33px;
|
||||||
width: 33px;
|
width: 33px;
|
||||||
@@ -108,10 +117,91 @@
|
|||||||
color: var(--color-text);
|
color: var(--color-text);
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
|
/* Mobile touch target improvements */
|
||||||
.profile-avatar svg { font-size: 1rem; }
|
@media (max-width: 768px) {
|
||||||
|
.profile-avatar-button {
|
||||||
|
min-width: var(--min-touch-target);
|
||||||
|
min-height: var(--min-touch-target);
|
||||||
|
width: var(--min-touch-target);
|
||||||
|
height: var(--min-touch-target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile-avatar-button:hover {
|
||||||
|
background: var(--color-bg-hover);
|
||||||
|
border-color: var(--color-border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile-avatar-button img { width: 100%; height: 100%; object-fit: cover; }
|
||||||
|
.profile-avatar-button svg { font-size: 1rem; }
|
||||||
|
|
||||||
|
/* Profile menu wrapper */
|
||||||
|
.profile-menu-wrapper {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Dropdown menu */
|
||||||
|
.profile-dropdown-menu {
|
||||||
|
position: absolute;
|
||||||
|
top: calc(100% + 0.5rem);
|
||||||
|
left: 0;
|
||||||
|
background: var(--color-bg-elevated);
|
||||||
|
border: 1px solid var(--color-border);
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||||
|
min-width: 180px;
|
||||||
|
padding: 0.25rem;
|
||||||
|
z-index: 1000;
|
||||||
|
animation: profileMenuSlideIn 0.15s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes profileMenuSlideIn {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateY(-4px);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile-menu-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.75rem;
|
||||||
|
width: 100%;
|
||||||
|
padding: 0.625rem 0.875rem;
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
color: var(--color-text);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.15s ease;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
text-align: left;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile-menu-item:hover {
|
||||||
|
background: var(--color-bg-hover);
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile-menu-item svg {
|
||||||
|
width: 1em;
|
||||||
|
font-size: 1rem;
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile-menu-separator {
|
||||||
|
height: 1px;
|
||||||
|
background: var(--color-border);
|
||||||
|
margin: 0.25rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
.sidebar-header-bar .toggle-sidebar-btn {
|
.sidebar-header-bar .toggle-sidebar-btn {
|
||||||
background: transparent;
|
background: transparent;
|
||||||
@@ -177,6 +267,42 @@
|
|||||||
.read-inline-btn:hover { background: rgb(22 163 74); /* green-600 */ }
|
.read-inline-btn:hover { background: rgb(22 163 74); /* green-600 */ }
|
||||||
|
|
||||||
/* Bookmark filters */
|
/* Bookmark filters */
|
||||||
|
.bookmark-filters-wrapper {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
border-bottom: 1px solid var(--color-border);
|
||||||
|
background: var(--color-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.bookmark-filters-wrapper > .bookmark-filters {
|
||||||
|
padding: 0;
|
||||||
|
border-bottom: none;
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bookmark-filters-wrapper > .compact-button {
|
||||||
|
background: transparent;
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
border: none;
|
||||||
|
padding: 0.375rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.15s ease;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
min-width: 32px;
|
||||||
|
min-height: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bookmark-filters-wrapper > .compact-button:hover {
|
||||||
|
color: var(--color-text);
|
||||||
|
background: var(--color-bg-elevated);
|
||||||
|
}
|
||||||
|
|
||||||
.bookmark-filters {
|
.bookmark-filters {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
|
|||||||
13
src/sw.ts
13
src/sw.ts
@@ -23,13 +23,15 @@ sw.skipWaiting()
|
|||||||
clientsClaim()
|
clientsClaim()
|
||||||
|
|
||||||
|
|
||||||
// Runtime cache: Cross-origin images
|
// Runtime cache: All images (cross-origin and same-origin)
|
||||||
// This preserves the existing image caching behavior
|
// Cache both external images and any internal image assets
|
||||||
registerRoute(
|
registerRoute(
|
||||||
({ request, url }) => {
|
({ request, url }) => {
|
||||||
const isImage = request.destination === 'image' ||
|
const isImage = request.destination === 'image' ||
|
||||||
/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(url.pathname)
|
/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(url.pathname)
|
||||||
return isImage && url.origin !== sw.location.origin
|
// Cache all images, not just cross-origin ones
|
||||||
|
// This ensures article images from any source get cached
|
||||||
|
return isImage
|
||||||
},
|
},
|
||||||
new StaleWhileRevalidate({
|
new StaleWhileRevalidate({
|
||||||
cacheName: 'boris-images',
|
cacheName: 'boris-images',
|
||||||
@@ -41,6 +43,11 @@ registerRoute(
|
|||||||
new CacheableResponsePlugin({
|
new CacheableResponsePlugin({
|
||||||
statuses: [0, 200],
|
statuses: [0, 200],
|
||||||
}),
|
}),
|
||||||
|
{
|
||||||
|
cacheWillUpdate: async ({ response }) => {
|
||||||
|
return response.ok ? response : null
|
||||||
|
}
|
||||||
|
}
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ export interface Bookmark {
|
|||||||
export interface IndividualBookmark {
|
export interface IndividualBookmark {
|
||||||
id: string
|
id: string
|
||||||
content: string
|
content: string
|
||||||
created_at: number
|
// Timestamp when the content was created (from the content event itself)
|
||||||
|
created_at: number | null
|
||||||
pubkey: string
|
pubkey: string
|
||||||
kind: number
|
kind: number
|
||||||
tags: string[][]
|
tags: string[][]
|
||||||
@@ -40,8 +41,6 @@ export interface IndividualBookmark {
|
|||||||
type: 'event' | 'article' | 'web'
|
type: 'event' | 'article' | 'web'
|
||||||
isPrivate?: boolean
|
isPrivate?: boolean
|
||||||
encryptedContent?: string
|
encryptedContent?: string
|
||||||
// When the item was added to the bookmark list (synthetic, for sorting)
|
|
||||||
added_at?: number
|
|
||||||
// The kind of the source list/set that produced this bookmark (e.g., 10003, 30003, 30001, or 39701 for web)
|
// The kind of the source list/set that produced this bookmark (e.g., 10003, 30003, 30001, or 39701 for web)
|
||||||
sourceKind?: number
|
sourceKind?: number
|
||||||
// The 'd' tag value from kind 30003 bookmark sets
|
// The 'd' tag value from kind 30003 bookmark sets
|
||||||
@@ -50,6 +49,9 @@ export interface IndividualBookmark {
|
|||||||
setTitle?: string
|
setTitle?: string
|
||||||
setDescription?: string
|
setDescription?: string
|
||||||
setImage?: string
|
setImage?: string
|
||||||
|
// Timestamp of the bookmark list event (best proxy for "when bookmarked")
|
||||||
|
// Note: This is imperfect - it's when the list was last updated, not necessarily when this item was added
|
||||||
|
listUpdatedAt?: number | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ActiveAccount {
|
export interface ActiveAccount {
|
||||||
|
|||||||
@@ -15,11 +15,10 @@ export interface Highlight {
|
|||||||
comment?: string // optional comment about the highlight
|
comment?: string // optional comment about the highlight
|
||||||
// Level classification (computed based on user's context)
|
// Level classification (computed based on user's context)
|
||||||
level?: HighlightLevel
|
level?: HighlightLevel
|
||||||
// Relay tracking for offline/local-only highlights
|
// Relay tracking for local-only highlights
|
||||||
publishedRelays?: string[] // URLs of relays where this was published (for user-created highlights)
|
publishedRelays?: string[] // URLs of relays where this was published (for user-created highlights)
|
||||||
seenOnRelays?: string[] // URLs of relays where this event was fetched from
|
seenOnRelays?: string[] // URLs of relays where this event was fetched from
|
||||||
isLocalOnly?: boolean // true if only published to local relays
|
isLocalOnly?: boolean // true if only published to local relays
|
||||||
isOfflineCreated?: boolean // true if created while in flight mode (offline)
|
|
||||||
isSyncing?: boolean // true if currently being synced to remote relays
|
isSyncing?: boolean // true if currently being synced to remote relays
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,13 +4,15 @@ import { ParsedContent, ParsedNode, IndividualBookmark } from '../types/bookmark
|
|||||||
import ResolvedMention from '../components/ResolvedMention'
|
import ResolvedMention from '../components/ResolvedMention'
|
||||||
// Note: RichContent is imported by components directly to keep this file component-only for fast refresh
|
// Note: RichContent is imported by components directly to keep this file component-only for fast refresh
|
||||||
|
|
||||||
export const formatDate = (timestamp: number) => {
|
export const formatDate = (timestamp: number | null | undefined) => {
|
||||||
|
if (!timestamp || !isFinite(timestamp) || timestamp <= 0) return ''
|
||||||
const date = new Date(timestamp * 1000)
|
const date = new Date(timestamp * 1000)
|
||||||
return formatDistanceToNow(date, { addSuffix: true })
|
return formatDistanceToNow(date, { addSuffix: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ultra-compact date format for tight spaces (e.g., compact view)
|
// Ultra-compact date format for tight spaces (e.g., compact view)
|
||||||
export const formatDateCompact = (timestamp: number) => {
|
export const formatDateCompact = (timestamp: number | null | undefined) => {
|
||||||
|
if (!timestamp || !isFinite(timestamp) || timestamp <= 0) return ''
|
||||||
const date = new Date(timestamp * 1000)
|
const date = new Date(timestamp * 1000)
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
|
|
||||||
@@ -85,9 +87,8 @@ export const renderParsedContent = (parsedContent: ParsedContent) => {
|
|||||||
|
|
||||||
// Sorting and grouping for bookmarks
|
// Sorting and grouping for bookmarks
|
||||||
export const sortIndividualBookmarks = (items: IndividualBookmark[]) => {
|
export const sortIndividualBookmarks = (items: IndividualBookmark[]) => {
|
||||||
return items
|
const getSortTime = (b: IndividualBookmark) => b.created_at ?? b.listUpdatedAt ?? -Infinity
|
||||||
.slice()
|
return items.slice().sort((a, b) => getSortTime(b) - getSortTime(a))
|
||||||
.sort((a, b) => ((b.added_at || 0) - (a.added_at || 0)) || ((b.created_at || 0) - (a.created_at || 0)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function groupIndividualBookmarks(items: IndividualBookmark[]) {
|
export function groupIndividualBookmarks(items: IndividualBookmark[]) {
|
||||||
@@ -122,10 +123,7 @@ export function hasContent(bookmark: IndividualBookmark): boolean {
|
|||||||
export function hasCreationDate(bookmark: IndividualBookmark): boolean {
|
export function hasCreationDate(bookmark: IndividualBookmark): boolean {
|
||||||
if (!bookmark.created_at) return false
|
if (!bookmark.created_at) return false
|
||||||
// If timestamp is missing or equals current time (within 1 second), consider it invalid
|
// If timestamp is missing or equals current time (within 1 second), consider it invalid
|
||||||
const now = Math.floor(Date.now() / 1000)
|
return true
|
||||||
const createdAt = Math.floor(bookmark.created_at)
|
|
||||||
// If created_at is within 1 second of now, it's likely missing/placeholder
|
|
||||||
return Math.abs(createdAt - now) > 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bookmark sets helpers (kind 30003)
|
// Bookmark sets helpers (kind 30003)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user