nandi/gleanpublic Fork 0
54e50b3
Commits
Clone
git clone https://git.rickub.com/nandi/glean.git
git clone ssh://git@rickub.com/nandi/glean.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

refactor: mark article as read via UI instead of via api callUnverified

Julien Robert committed 2026-08-03T12:40:56+02:00 Browse files
54e50b3 parent: 5bd3cd5
modified internal/server/articles_handler.go +8 -3
@@ -152,12 +152,17 @@ func (s *Server) handleArticleDetail(w http.ResponseWriter, r *http.Request) {
152152 nextID *int64
153153 )
154154
155+ var isRead bool
156+
155157 g, gCtx := errgroup.WithContext(ctx)
156158
157159 g.Go(func() error {
158- if err := s.dbs.Articles.MarkArticleRead(gCtx, user.DID, id); err != nil {
159- s.logger.Warn("failed to mark article read", "error", err, "id", id)
160+ state, err := s.dbs.Articles.GetReadState(gCtx, user.DID, id)
161+ if err != nil {
162+ s.logger.Warn("failed to get read state", "error", err, "id", id)
163+ return nil
160164 }
165+ isRead = state.IsRead
161166 return nil
162167 })
163168
@@ -215,7 +220,7 @@ func (s *Server) handleArticleDetail(w http.ResponseWriter, r *http.Request) {
215220 _ = g.Wait()
216221
217222 dto := toArticle(article)
218- dto.IsRead = true
223+ dto.IsRead = isRead
219224 dto.LikeCount = likeCount
220225 dto.HasLiked = liked
221226
@@ -152,12 +152,17 @@ func (s *Server) handleArticleDetail(w http.ResponseWriter, r *http.Request) {
152 nextID *int64152 nextID *int64
153 )153 )
154 154
155+ var isRead bool
156+
155 g, gCtx := errgroup.WithContext(ctx)157 g, gCtx := errgroup.WithContext(ctx)
156 158
157 g.Go(func() error {159 g.Go(func() error {
158- if err := s.dbs.Articles.MarkArticleRead(gCtx, user.DID, id); err != nil {160+ state, err := s.dbs.Articles.GetReadState(gCtx, user.DID, id)
159- s.logger.Warn("failed to mark article read", "error", err, "id", id)161+ if err != nil {
162+ s.logger.Warn("failed to get read state", "error", err, "id", id)
163+ return nil
160 }164 }
165+ isRead = state.IsRead
161 return nil166 return nil
162 })167 })
163 168
@@ -215,7 +220,7 @@ func (s *Server) handleArticleDetail(w http.ResponseWriter, r *http.Request) {
215 _ = g.Wait()220 _ = g.Wait()
216 221
217 dto := toArticle(article)222 dto := toArticle(article)
218- dto.IsRead = true223+ dto.IsRead = isRead
219 dto.LikeCount = likeCount224 dto.LikeCount = likeCount
220 dto.HasLiked = liked225 dto.HasLiked = liked
221 226
modified web/src/routes/articles/[id]/+page.svelte +18 -0
@@ -58,6 +58,24 @@
5858 annotations = data.annotations;
5959 });
6060
61+ // Sync local optimistic state when navigating between articles.
62+ $effect(() => {
63+ read = data.article.is_read;
64+ });
65+
66+ // Mark the article read on actual navigation. The server's detail handler
67+ // no longer marks read, so a hover/touch preload won't mark every hovered
68+ // card as read; only a real visit does.
69+ $effect(() => {
70+ const id = data.article.id;
71+ if (!read) {
72+ read = true;
73+ endpoints.markRead(id).catch(() => {
74+ if (data.article.id === id) read = false;
75+ });
76+ }
77+ });
78+
6179 function clamp(v: number, min: number, max: number) {
6280 return Math.max(min, Math.min(max, v));
6381 }
@@ -58,6 +58,24 @@
58 annotations = data.annotations;58 annotations = data.annotations;
59 });59 });
60 60
61+ // Sync local optimistic state when navigating between articles.
62+ $effect(() => {
63+ read = data.article.is_read;
64+ });
65+
66+ // Mark the article read on actual navigation. The server's detail handler
67+ // no longer marks read, so a hover/touch preload won't mark every hovered
68+ // card as read; only a real visit does.
69+ $effect(() => {
70+ const id = data.article.id;
71+ if (!read) {
72+ read = true;
73+ endpoints.markRead(id).catch(() => {
74+ if (data.article.id === id) read = false;
75+ });
76+ }
77+ });
78+
61 function clamp(v: number, min: number, max: number) {79 function clamp(v: number, min: number, max: number) {
62 return Math.max(min, Math.min(max, v));80 return Math.max(min, Math.min(max, v));
63 }81 }