-
Notifications
You must be signed in to change notification settings - Fork 150
Add unread Signal-view thread count badge to email sidebar #5416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
.sqlx/query-bd5685982d6000af9914ed99171df936cad7745bff5a5b6ea54fa7d21011e7d9.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import { throwOnErr } from '@core/util/result'; | ||
| import { queryClient } from '@queries/client'; | ||
| import { emailClient } from '@service-email/client'; | ||
| import { useQuery } from '@tanstack/solid-query'; | ||
| import { type Accessor, createMemo } from 'solid-js'; | ||
| import { emailKeys } from './keys'; | ||
|
|
||
| /** | ||
| * How long a fetched count stays fresh. Short, because the badge is a | ||
| * "there is something waiting" signal — a stale one is worse than a late one. | ||
| */ | ||
| const UNREAD_COUNTS_STALE_TIME = 30 * 1000; | ||
|
|
||
| /** | ||
| * Background refresh cadence. Mail arriving from the provider doesn't | ||
| * invalidate this query (the notification-driven soup refresh doesn't know | ||
| * about it), so a poll is what turns new mail into a badge while the tab | ||
| * stays open. Reads and unreads made in-app invalidate directly and don't | ||
| * wait for it. | ||
| */ | ||
| const UNREAD_COUNTS_REFETCH_INTERVAL = 60 * 1000; | ||
|
|
||
| const queryEnabled = () => true; | ||
|
|
||
| /** | ||
| * Unread Signal-view thread counts per connected inbox, as the sidebar's Email | ||
| * badge renders them. Counts are Signal only — Noise is deliberately excluded, | ||
| * so the number always matches the tab a click lands on. | ||
| * | ||
| * The server returns one entry per accessible inbox, including inboxes with | ||
| * nothing unread, so an inbox missing from the response means "not linked" | ||
| * rather than "caught up". | ||
| */ | ||
| export function useEmailUnreadCountsQuery( | ||
| enabled: Accessor<boolean> = queryEnabled | ||
| ) { | ||
| return useQuery(() => ({ | ||
| queryKey: emailKeys.unreadCounts.queryKey, | ||
| queryFn: async () => | ||
| throwOnErr(async () => await emailClient.getUnreadCounts()), | ||
| enabled: enabled(), | ||
| staleTime: UNREAD_COUNTS_STALE_TIME, | ||
| refetchInterval: UNREAD_COUNTS_REFETCH_INTERVAL, | ||
| refetchOnWindowFocus: 'always' as const, | ||
| })); | ||
| } | ||
|
|
||
| /** | ||
| * Unread Signal counts keyed by email link id, plus the cross-inbox total the | ||
| * collapsed Email row shows. Both are `0`-safe before the query resolves, so | ||
| * the badge simply doesn't render rather than flashing a placeholder. | ||
| */ | ||
| export function useEmailUnreadCounts(enabled?: Accessor<boolean>) { | ||
| const query = useEmailUnreadCountsQuery(enabled); | ||
|
|
||
| const byLinkId = createMemo(() => { | ||
| const counts = new Map<string, number>(); | ||
| for (const entry of query.data?.counts ?? []) { | ||
| counts.set(entry.link_id, entry.unread_count); | ||
| } | ||
| return counts; | ||
| }); | ||
|
|
||
| return { | ||
| /** Unread Signal count for one inbox; `0` while the query is loading. */ | ||
| forLink: (linkId: string) => byLinkId().get(linkId) ?? 0, | ||
| /** Unread Signal count summed across every connected inbox. */ | ||
| total: () => query.data?.total ?? 0, | ||
| }; | ||
| } | ||
|
|
||
| /** Refetch the unread counts — call after anything that reads or unreads mail. */ | ||
| export function invalidateEmailUnreadCounts() { | ||
| queryClient.invalidateQueries({ | ||
| queryKey: emailKeys.unreadCounts.queryKey, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: macro-inc/macro
Length of output: 50372
🏁 Script executed:
Repository: macro-inc/macro
Length of output: 13997
🏁 Script executed:
Repository: macro-inc/macro
Length of output: 324
🏁 Script executed:
Repository: macro-inc/macro
Length of output: 7061
🏁 Script executed:
Repository: macro-inc/macro
Length of output: 5043
Wrap the sidebar unread-count query in its own
Suspenseboundary.useEmailUnreadCounts()is a new query call site, and the parentSuspenseonly wraps the authenticatedLayoutcontent so it is not a deliberate sidebar-specific fallback. WrapSidebarMailLinkwith aSuspenseboundary that handles unread-count loading.🤖 Prompt for AI Agents
Source: Path instructions