Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 2,586 Bytes
662d5af 6216bfd 23637ad 662d5af a1a6daf 6216bfd a1a6daf 6216bfd 662d5af a1a6daf 6216bfd 662d5af 6216bfd 662d5af a1a6daf 6216bfd 662d5af 23637ad 662d5af 23637ad 0d0a611 662d5af 23637ad 662d5af 23637ad 662d5af |
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
<script lang="ts">
import type { Message } from "$lib/types/Message";
import CarbonTrashCan from "~icons/carbon/trash-can";
import CarbonChevronLeft from "~icons/carbon/chevron-left";
import CarbonChevronRight from "~icons/carbon/chevron-right";
import { createEventDispatcher } from "svelte";
import { base } from "$app/paths";
import { page } from "$app/state";
import { error } from "$lib/stores/errors";
import { invalidate } from "$app/navigation";
import { UrlDependency } from "$lib/types/UrlDependency";
interface Props {
message: Message;
alternatives?: Message["id"][];
loading?: boolean;
}
let { message, alternatives = [], loading = false }: Props = $props();
let currentIdx = $derived(alternatives.findIndex((id) => id === message.id));
const dispatch = createEventDispatcher<{
showAlternateMsg: { id: Message["id"] };
}>();
</script>
<div
class="font-white group/navbranch z-0 -mt-1 ml-3.5 mr-auto flex h-6 w-fit select-none flex-row items-center justify-center gap-1 text-sm"
>
<button
class="inline text-lg font-thin text-gray-400 hover:text-gray-800 disabled:pointer-events-none disabled:opacity-25 dark:text-gray-500 dark:hover:text-gray-200"
onclick={() => dispatch("showAlternateMsg", { id: alternatives[Math.max(0, currentIdx - 1)] })}
disabled={currentIdx === 0 || loading}
>
<CarbonChevronLeft class="text-sm" />
</button>
<span class=" text-gray-400 dark:text-gray-500">
{currentIdx + 1} / {alternatives.length}
</span>
<button
class="inline text-lg font-thin text-gray-400 hover:text-gray-800 disabled:pointer-events-none disabled:opacity-25 dark:text-gray-500 dark:hover:text-gray-200"
onclick={() =>
dispatch("showAlternateMsg", {
id: alternatives[Math.min(alternatives.length - 1, currentIdx + 1)],
})}
disabled={currentIdx === alternatives.length - 1 || loading}
>
<CarbonChevronRight class="text-sm" />
</button>
{#if !loading && message.children}
<button
class="hidden group-hover/navbranch:block"
onclick={() => {
if (confirm("Are you sure you want to delete this branch?")) {
fetch(`${base}/api/conversation/${page.params.id}/message/${message.id}`, {
method: "DELETE",
}).then(async (r) => {
if (r.ok) {
await invalidate(UrlDependency.Conversation);
} else {
$error = (await r.json()).message;
}
});
}
}}
>
<div
class="flex items-center justify-center text-xs text-gray-400 hover:text-gray-800 dark:text-gray-500 dark:hover:text-gray-200"
>
<CarbonTrashCan />
</div>
</button>
{/if}
</div>
|