Skip to content

Commit e9f7d40

Browse files
jsollycursoragent
andauthored
Hide Open chapter in definition popover on the term's own chapter (#39)
Only show the popover's Open chapter link when the reader is viewing a different chapter than the one that defines the glossary term. Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: John Solly <jsolly@users.noreply.github.com>
1 parent e17714b commit e9f7d40

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

src/components/app/ChapterView.svelte

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
{chapter.title}
114114
</h1>
115115
<p class="mt-3 text-sm leading-6 text-muted-foreground sm:text-base sm:leading-7">
116-
<TermRichText segments={linkedCopy.intro} />
116+
<TermRichText segments={linkedCopy.intro} currentChapterId={chapter.id} />
117117
</p>
118118
</header>
119119

@@ -152,7 +152,7 @@
152152

153153
<p class="mt-4 text-sm leading-6 sm:text-base sm:leading-7">
154154
{#if linked}
155-
<TermRichText segments={linked.teach} />
155+
<TermRichText segments={linked.teach} currentChapterId={chapter.id} />
156156
{:else}
157157
{piece.teach}
158158
{/if}
@@ -165,7 +165,10 @@
165165
</p>
166166
<p class="mt-1 text-sm leading-6 sm:text-base sm:leading-7">
167167
{#if linked?.watchFor}
168-
<TermRichText segments={linked.watchFor} />
168+
<TermRichText
169+
segments={linked.watchFor}
170+
currentChapterId={chapter.id}
171+
/>
169172
{:else}
170173
{piece.watchFor}
171174
{/if}
@@ -234,7 +237,10 @@
234237
<section class="mt-10 border-t pt-8 sm:mt-12">
235238
{#if chapter.closing && linkedCopy.closing}
236239
<p class="text-sm leading-6 text-muted-foreground sm:text-base sm:leading-7">
237-
<TermRichText segments={linkedCopy.closing} />
240+
<TermRichText
241+
segments={linkedCopy.closing}
242+
currentChapterId={chapter.id}
243+
/>
238244
</p>
239245
{/if}
240246
<div

src/components/app/TermDefinitionPopover.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
let {
99
term,
1010
triggerClass,
11+
currentChapterId,
1112
children,
1213
}: {
1314
term: GlossaryTerm;
1415
triggerClass: string;
16+
/** When set, hide "Open chapter" if the term is defined in this chapter. */
17+
currentChapterId?: string;
1518
children: Snippet;
1619
} = $props();
1720
@@ -21,6 +24,9 @@
2124
let titleEl: HTMLElement | null = $state(null);
2225
2326
let chapter = $derived(term.chapterId ? chapterById(term.chapterId) : undefined);
27+
let showOpenChapter = $derived(
28+
Boolean(chapter && term.chapterId && term.chapterId !== currentChapterId),
29+
);
2430
2531
function onOpenAutoFocus(event: Event) {
2632
event.preventDefault();
@@ -54,7 +60,7 @@
5460
{term.definition}
5561
</Popover.Description>
5662
</Popover.Header>
57-
{#if chapter}
63+
{#if showOpenChapter && chapter}
5864
<a
5965
class="mt-2 inline-block text-sm font-medium text-primary underline-offset-4 hover:underline"
6066
href={learnChapterPath(chapter.unitId, chapter.id)}

src/components/app/TermRichText.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
66
let {
77
segments,
8+
currentChapterId,
89
}: {
910
segments: TextSegment[];
11+
/** Chapter the reader is currently viewing, if any. */
12+
currentChapterId?: string;
1013
} = $props();
1114
</script>
1215

@@ -18,6 +21,7 @@
1821
{#if term}
1922
<TermDefinitionPopover
2023
{term}
24+
{currentChapterId}
2125
triggerClass="cursor-pointer rounded-sm text-primary underline decoration-dotted decoration-primary/70 underline-offset-2 outline-none hover:decoration-solid focus-visible:ring-2 focus-visible:ring-ring"
2226
>
2327
{segment.text}

0 commit comments

Comments
 (0)