Suggestions.svelte 3.43 KB
Newer Older
1
<script lang="ts">
Timothy J. Baek's avatar
Timothy J. Baek committed
2
	import Bolt from '$lib/components/icons/Bolt.svelte';
Timothy J. Baek's avatar
Timothy J. Baek committed
3
	import { onMount } from 'svelte';
Timothy J. Baek's avatar
Timothy J. Baek committed
4

5
	export let submitPrompt: Function;
6
	export let suggestionPrompts = [];
7
8
9

	let prompts = [];

Timothy J. Baek's avatar
Timothy J. Baek committed
10
11
12
	$: prompts = suggestionPrompts
		.reduce((acc, current) => [...acc, ...[current]], [])
		.sort(() => Math.random() - 0.5);
13
14
15
	// suggestionPrompts.length <= 4
	// 	? suggestionPrompts
	// 	: suggestionPrompts.sort(() => Math.random() - 0.5).slice(0, 4);
Timothy J. Baek's avatar
Timothy J. Baek committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

	onMount(() => {
		const containerElement = document.getElementById('suggestions-container');

		if (containerElement) {
			containerElement.addEventListener('wheel', function (event) {
				if (event.deltaY !== 0) {
					// If scrolling vertically, prevent default behavior
					event.preventDefault();
					// Adjust horizontal scroll position based on vertical scroll
					containerElement.scrollLeft += event.deltaY;
				}
			});
		}
	});
31
32
</script>

Timothy J. Baek's avatar
Timothy J. Baek committed
33
34
35
36
37
38
39
{#if prompts.length > 0}
	<div class="mb-2 flex gap-1 text-sm font-medium items-center text-gray-400 dark:text-gray-600">
		<Bolt />
		Suggested
	</div>
{/if}

Timothy J. Baek's avatar
Timothy J. Baek committed
40
<div class="w-full">
Timothy J. Baek's avatar
Timothy J. Baek committed
41
42
43
44
	<div
		class="relative w-full flex gap-2 snap-x snap-mandatory md:snap-none overflow-x-auto tabs"
		id="suggestions-container"
	>
Timothy J. Baek's avatar
Timothy J. Baek committed
45
		{#each prompts as prompt, promptIdx}
46
			<div class="snap-center shrink-0">
Timothy J. Baek's avatar
Timothy J. Baek committed
47
				<button
Timothy J. Baek's avatar
Timothy J. Baek committed
48
					class="flex flex-col flex-1 shrink-0 w-64 justify-between h-36 p-5 px-6 bg-gray-50 hover:bg-gray-100 dark:bg-gray-850 dark:hover:bg-gray-800 rounded-3xl transition group"
Timothy J. Baek's avatar
Timothy J. Baek committed
49
50
51
					on:click={() => {
						submitPrompt(prompt.content);
					}}
52
				>
Timothy J. Baek's avatar
Timothy J. Baek committed
53
					<div class="flex flex-col text-left">
Timothy J. Baek's avatar
Timothy J. Baek committed
54
						{#if prompt.title && prompt.title[0] !== ''}
55
56
57
58
59
							<div
								class="  font-medium dark:text-gray-300 dark:group-hover:text-gray-200 transition"
							>
								{prompt.title[0]}
							</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
60
							<div class="text-sm text-gray-600 font-normal line-clamp-2">{prompt.title[1]}</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
61
						{:else}
62
63
64
							<div
								class=" self-center text-sm font-medium dark:text-gray-300 dark:group-hover:text-gray-100 transition line-clamp-2"
							>
Timothy J. Baek's avatar
Timothy J. Baek committed
65
66
67
68
69
								{prompt.content}
							</div>
						{/if}
					</div>

Timothy J. Baek's avatar
Timothy J. Baek committed
70
					<div class="w-full flex justify-between">
71
72
73
74
75
						<div
							class="text-xs text-gray-400 group-hover:text-gray-500 dark:text-gray-600 dark:group-hover:text-gray-500 transition self-center"
						>
							Prompt
						</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
76
77
78

						<div
							class="self-end p-1 rounded-lg text-gray-300 group-hover:text-gray-800 dark:text-gray-700 dark:group-hover:text-gray-100 transition"
Timothy J. Baek's avatar
Timothy J. Baek committed
79
						>
Timothy J. Baek's avatar
Timothy J. Baek committed
80
81
82
83
84
85
86
87
88
89
90
91
92
							<svg
								xmlns="http://www.w3.org/2000/svg"
								viewBox="0 0 16 16"
								fill="currentColor"
								class="size-4"
							>
								<path
									fill-rule="evenodd"
									d="M8 14a.75.75 0 0 1-.75-.75V4.56L4.03 7.78a.75.75 0 0 1-1.06-1.06l4.5-4.5a.75.75 0 0 1 1.06 0l4.5 4.5a.75.75 0 0 1-1.06 1.06L8.75 4.56v8.69A.75.75 0 0 1 8 14Z"
									clip-rule="evenodd"
								/>
							</svg>
						</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
93
94
95
96
					</div>
				</button>
			</div>
		{/each}
97

Timothy J. Baek's avatar
Timothy J. Baek committed
98
99
100
101
102
103
		<!-- <div class="snap-center shrink-0">
		<img
			class="shrink-0 w-80 h-40 rounded-lg shadow-xl bg-white"
			src="https://images.unsplash.com/photo-1604999565976-8913ad2ddb7c?ixlib=rb-1.2.1&amp;ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&amp;auto=format&amp;fit=crop&amp;w=320&amp;h=160&amp;q=80"
		/>
	</div> -->
Timothy J. Baek's avatar
Timothy J. Baek committed
104
	</div>
105
</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
106
107
108
109
110
111
112
113
114
115
116

<style>
	.tabs::-webkit-scrollbar {
		display: none; /* for Chrome, Safari and Opera */
	}

	.tabs {
		-ms-overflow-style: none; /* IE and Edge */
		scrollbar-width: none; /* Firefox */
	}
</style>