RateComment.svelte 2.5 KB
Newer Older
Timothy J. Baek's avatar
Timothy J. Baek committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<script lang="ts">
	import { toast } from 'svelte-sonner';

	import { createEventDispatcher, onMount } from 'svelte';

	const dispatch = createEventDispatcher();

	export let show = false;
	export let message;

	const LIKE_REASONS = [
		`Accurate information`,
		`Followed instructions perfectly`,
		`Showcased creativity`,
		`Positive attitude`,
		`Attention to detail`,
		`Thorough explanation`,
		`Other`
	];

	const DISLIKE_REASONS = [
		`Don't like the style`,
		`Not factually correct`,
		`Didn't fully follow instructions`,
		`Refused when it shouldn't have`,
		`Being Lazy`,
		`Other`
	];

	let reasons = [];
	let selectedReason = null;
	let comment = '';

	$: if (message.annotation.rating === 1) {
		reasons = LIKE_REASONS;
	} else if (message.annotation.rating === -1) {
		reasons = DISLIKE_REASONS;
	}

	onMount(() => {
		selectedReason = message.annotation.reason;
		comment = message.annotation.comment;
	});

	const submitHandler = () => {
		console.log('submitHandler');

		message.annotation.reason = selectedReason;
		message.annotation.comment = comment;

		dispatch('submit');

		toast.success('Thanks for your feedback!');
		show = false;
	};
</script>

Timothy J. Baek's avatar
Timothy J. Baek committed
58
<div class=" my-2.5 rounded-xl px-4 py-3 border dark:border-gray-850">
Timothy J. Baek's avatar
Timothy J. Baek committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
	<div class="flex justify-between items-center">
		<div class=" text-sm">Tell us more:</div>

		<button
			on:click={() => {
				show = false;
			}}
		>
			<svg
				xmlns="http://www.w3.org/2000/svg"
				fill="none"
				viewBox="0 0 24 24"
				stroke-width="1.5"
				stroke="currentColor"
				class="size-4"
			>
				<path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12" />
			</svg>
		</button>
	</div>

	{#if reasons.length > 0}
		<div class="flex flex-wrap gap-2 text-sm mt-2.5">
			{#each reasons as reason}
				<button
84
					class="px-3.5 py-1 border dark:border-gray-850 hover:bg-gray-100 dark:hover:bg-gray-850 {selectedReason ===
Timothy J. Baek's avatar
Timothy J. Baek committed
85
					reason
86
						? 'bg-gray-200 dark:bg-gray-800'
Timothy J. Baek's avatar
Timothy J. Baek committed
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
						: ''} transition rounded-lg"
					on:click={() => {
						selectedReason = reason;
					}}
				>
					{reason}
				</button>
			{/each}
		</div>
	{/if}

	<div class="mt-2">
		<textarea
			bind:value={comment}
			class="w-full text-sm px-1 py-2 bg-transparent outline-none resize-none rounded-xl"
			placeholder="Feel free to add specific details"
			rows="2"
		/>
	</div>

	<div class="mt-2 flex justify-end">
		<button
Timothy J. Baek's avatar
Timothy J. Baek committed
109
			class=" bg-emerald-700 text-white text-sm font-medium rounded-lg px-3.5 py-1.5"
Timothy J. Baek's avatar
Timothy J. Baek committed
110
111
112
113
114
115
116
117
			on:click={() => {
				submitHandler();
			}}
		>
			Submit
		</button>
	</div>
</div>