CitationsModal.svelte 2.28 KB
Newer Older
1
2
3
4
5
6
<script lang="ts">
	import { getContext, onMount, tick } from 'svelte';
	import Modal from '$lib/components/common/Modal.svelte';
	const i18n = getContext('i18n');

	export let show = false;
Timothy J. Baek's avatar
Timothy J. Baek committed
7
	export let citation;
8
9
10

	let mergedDocuments = [];

Timothy J. Baek's avatar
Timothy J. Baek committed
11
	$: if (citation) {
12
13
		mergedDocuments = citation.document?.map((c, i) => {
			return {
14
				source: citation.source,
15
16
17
18
				document: c,
				metadata: citation.metadata?.[i]
			};
		});
Timothy J. Baek's avatar
Timothy J. Baek committed
19
	}
20
21
22
23
</script>

<Modal size="lg" bind:show>
	<div>
Timothy J. Baek's avatar
Timothy J. Baek committed
24
		<div class=" flex justify-between dark:text-gray-300 px-5 pt-4 pb-2">
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
			<div class=" text-lg font-medium self-center capitalize">
				{$i18n.t('Citation')}
			</div>
			<button
				class="self-center"
				on:click={() => {
					show = false;
				}}
			>
				<svg
					xmlns="http://www.w3.org/2000/svg"
					viewBox="0 0 20 20"
					fill="currentColor"
					class="w-5 h-5"
				>
					<path
						d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
					/>
				</svg>
			</button>
		</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
46

Timothy J. Baek's avatar
Timothy J. Baek committed
47
48
		<div class="flex flex-col md:flex-row w-full px-6 pb-5 md:space-x-4">
			<div
Timothy J. Baek's avatar
Timothy J. Baek committed
49
				class="flex flex-col w-full dark:text-gray-200 overflow-y-scroll max-h-[22rem] scrollbar-hidden"
Timothy J. Baek's avatar
Timothy J. Baek committed
50
			>
Timothy J. Baek's avatar
Timothy J. Baek committed
51
52
53
54
55
				{#each mergedDocuments as document, documentIdx}
					<div class="flex flex-col w-full">
						<div class="text-sm font-medium dark:text-gray-300">
							{$i18n.t('Source')}
						</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

						{#if document.source?.name}
							<div class="text-sm dark:text-gray-400">
								<a
									href={document?.source?.url
										? `${document?.source?.url}/content`
										: document.source.name}
									target="_blank"
								>
									{document.source.name}
								</a>
							</div>
						{:else}
							<div class="text-sm dark:text-gray-400">
								{$i18n.t('No source available')}
							</div>
						{/if}
73
					</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
74
75
76
77
78
79
80
					<div class="flex flex-col w-full">
						<div class=" text-sm font-medium dark:text-gray-300">
							{$i18n.t('Content')}
						</div>
						<pre class="text-sm dark:text-gray-400 whitespace-pre-line">
							{document.document}
						</pre>
81
					</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
82

Timothy J. Baek's avatar
Timothy J. Baek committed
83
84
85
86
87
					{#if documentIdx !== mergedDocuments.length - 1}
						<hr class=" dark:border-gray-850 my-3" />
					{/if}
				{/each}
			</div>
88
89
90
		</div>
	</div>
</Modal>