Skip to content

Commit

Permalink
refactor: simplify citation rendering
Browse files Browse the repository at this point in the history
defining it as a function means we can simplify the reactivity
  • Loading branch information
jamesdabbs committed Jun 9, 2024
1 parent b8baac4 commit 3e4052c
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions packages/viewer/src/components/Search/Search.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,23 @@
urlSearchParam('text', text)
urlSearchParam('q', rawFormula, () => ($suggest = false))
let title: string
$: if ($rawFormula.length > 0) {
if ($text.length > 0) {
title = `π-Base, Search for \`${$rawFormula}\` matching \`${$text}\``
function describe(formula: string, text: string) {
if (formula.length > 0) {
if (text.length > 0) {
return `Search for \`${formula}\` matching \`${text}\``
} else {
return `Search for \`${formula}\``
}
} else {
title = `π-Base, Search for \`${$rawFormula}\``
}
} else {
if ($text.length > 0) {
title = `π-Base, Search matching \`${$text}\``
} else {
title = 'π-Base, Explore'
if (text.length > 0) {
return `Search matching \`${text}\``
} else {
return 'Explore'
}
}
}
$: title = `π-Base, ${describe($rawFormula, $text)}`
</script>

<div class="row">
Expand Down Expand Up @@ -77,5 +80,5 @@
</div>
</div>
<div>
{#key [$rawFormula, $text]}<Cite {title} />{/key}
<Cite {title} />
</div>

0 comments on commit 3e4052c

Please sign in to comment.