2024-04-08 10:08:30 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import { toast } from 'svelte-sonner';
|
|
|
|
|
2024-04-20 04:51:11 +00:00
|
|
|
import { createEventDispatcher, onMount, getContext } from 'svelte';
|
2024-04-20 18:35:01 +00:00
|
|
|
|
2024-04-20 04:51:11 +00:00
|
|
|
const i18n = getContext('i18n');
|
2024-04-08 10:08:30 +00:00
|
|
|
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
2024-04-21 00:10:05 +00:00
|
|
|
export let messageId = null;
|
2024-04-08 10:08:30 +00:00
|
|
|
export let show = false;
|
|
|
|
export let message;
|
|
|
|
|
2024-04-20 04:51:11 +00:00
|
|
|
let LIKE_REASONS = [];
|
|
|
|
let DISLIKE_REASONS = [];
|
|
|
|
|
|
|
|
function loadReasons() {
|
|
|
|
LIKE_REASONS = [
|
2024-04-20 18:35:01 +00:00
|
|
|
$i18n.t('Accurate information'),
|
|
|
|
$i18n.t('Followed instructions perfectly'),
|
|
|
|
$i18n.t('Showcased creativity'),
|
|
|
|
$i18n.t('Positive attitude'),
|
|
|
|
$i18n.t('Attention to detail'),
|
|
|
|
$i18n.t('Thorough explanation'),
|
|
|
|
$i18n.t('Other')
|
2024-04-20 04:51:11 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
DISLIKE_REASONS = [
|
|
|
|
$i18n.t("Don't like the style"),
|
2024-04-20 18:35:01 +00:00
|
|
|
$i18n.t('Not factually correct'),
|
2024-04-20 04:51:11 +00:00
|
|
|
$i18n.t("Didn't fully follow instructions"),
|
|
|
|
$i18n.t("Refused when it shouldn't have"),
|
2024-04-20 18:35:01 +00:00
|
|
|
$i18n.t('Being lazy'),
|
|
|
|
$i18n.t('Other')
|
2024-04-20 04:51:11 +00:00
|
|
|
];
|
|
|
|
}
|
2024-04-08 10:08:30 +00:00
|
|
|
|
|
|
|
let reasons = [];
|
|
|
|
let selectedReason = null;
|
|
|
|
let comment = '';
|
|
|
|
|
2024-05-13 21:27:58 +00:00
|
|
|
$: if (message?.annotation?.rating === 1) {
|
2024-04-08 10:08:30 +00:00
|
|
|
reasons = LIKE_REASONS;
|
2024-05-13 21:27:58 +00:00
|
|
|
} else if (message?.annotation?.rating === -1) {
|
2024-04-08 10:08:30 +00:00
|
|
|
reasons = DISLIKE_REASONS;
|
|
|
|
}
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
selectedReason = message.annotation.reason;
|
|
|
|
comment = message.annotation.comment;
|
2024-04-20 04:51:11 +00:00
|
|
|
loadReasons();
|
2024-04-08 10:08:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const submitHandler = () => {
|
|
|
|
console.log('submitHandler');
|
|
|
|
|
|
|
|
message.annotation.reason = selectedReason;
|
|
|
|
message.annotation.comment = comment;
|
|
|
|
|
|
|
|
dispatch('submit');
|
|
|
|
|
2024-04-20 04:51:11 +00:00
|
|
|
toast.success($i18n.t('Thanks for your feedback!'));
|
2024-04-08 10:08:30 +00:00
|
|
|
show = false;
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
2024-04-21 00:10:05 +00:00
|
|
|
<div
|
|
|
|
class=" my-2.5 rounded-xl px-4 py-3 border dark:border-gray-850"
|
|
|
|
id="message-feedback-{messageId}"
|
|
|
|
>
|
2024-04-08 10:08:30 +00:00
|
|
|
<div class="flex justify-between items-center">
|
2024-04-20 04:51:11 +00:00
|
|
|
<div class=" text-sm">{$i18n.t('Tell us more:')}</div>
|
2024-04-08 10:08:30 +00:00
|
|
|
|
|
|
|
<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
|
2024-04-20 04:03:47 +00:00
|
|
|
class="px-3.5 py-1 border dark:border-gray-850 hover:bg-gray-100 dark:hover:bg-gray-850 {selectedReason ===
|
2024-04-08 10:08:30 +00:00
|
|
|
reason
|
2024-04-20 04:03:47 +00:00
|
|
|
? 'bg-gray-200 dark:bg-gray-800'
|
2024-04-08 10:08:30 +00:00
|
|
|
: ''} 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"
|
2024-04-20 18:35:01 +00:00
|
|
|
placeholder={$i18n.t('Feel free to add specific details')}
|
2024-04-08 10:08:30 +00:00
|
|
|
rows="2"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="mt-2 flex justify-end">
|
|
|
|
<button
|
2024-04-08 10:10:31 +00:00
|
|
|
class=" bg-emerald-700 text-white text-sm font-medium rounded-lg px-3.5 py-1.5"
|
2024-04-08 10:08:30 +00:00
|
|
|
on:click={() => {
|
|
|
|
submitHandler();
|
|
|
|
}}
|
|
|
|
>
|
2024-05-07 18:41:17 +00:00
|
|
|
{$i18n.t('Submit')}
|
2024-04-08 10:08:30 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|