refac: citations modal

This commit is contained in:
Timothy Jaeryang Baek 2025-04-06 19:14:24 -07:00
parent 2be08f27ea
commit 06820e701c

View File

@ -14,6 +14,7 @@
let mergedDocuments = [];
function calculatePercentage(distance: number) {
if (typeof distance !== 'number') return null;
if (distance < 0) return 0;
if (distance > 1) return 100;
return Math.round(distance * 10000) / 100;
@ -122,11 +123,14 @@
<div class="text-sm my-1 dark:text-gray-400 flex items-center gap-2 w-fit">
{#if showPercentage}
{@const percentage = calculatePercentage(document.distance)}
<span
class={`px-1 rounded-sm font-medium ${getRelevanceColor(percentage)}`}
>
{percentage.toFixed(2)}%
</span>
{#if typeof percentage === 'number'}
<span
class={`px-1 rounded-sm font-medium ${getRelevanceColor(percentage)}`}
>
{percentage.toFixed(2)}%
</span>
{/if}
<span class="text-gray-500 dark:text-gray-500">
({(document?.distance ?? 0).toFixed(4)})
</span>