Spaces:
Runtime error
Runtime error
Thomas G. Lopes
commited on
Commit
·
0df1a9e
1
Parent(s):
a0911b1
stop empty messages being sent
Browse files
src/lib/builders/local-toasts.svelte.ts
CHANGED
|
@@ -72,8 +72,8 @@ export class LocalToasts {
|
|
| 72 |
}).then(({ x, y, placement: _placement }) => {
|
| 73 |
placement = _placement;
|
| 74 |
Object.assign(node.style, {
|
| 75 |
-
left: placement
|
| 76 |
-
top: placement
|
| 77 |
});
|
| 78 |
|
| 79 |
// Animate
|
|
@@ -82,19 +82,16 @@ export class LocalToasts {
|
|
| 82 |
|
| 83 |
// Determine animation direction based on placement
|
| 84 |
let keyframes: Keyframe[] = [];
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
{ opacity: 1, transform: "translateX(0)", scale: "1" },
|
| 96 |
-
];
|
| 97 |
-
break;
|
| 98 |
}
|
| 99 |
|
| 100 |
node.animate(keyframes, {
|
|
@@ -123,21 +120,17 @@ export class LocalToasts {
|
|
| 123 |
|
| 124 |
// Determine animation direction based on placement
|
| 125 |
let keyframes: Keyframe[] = [];
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
{ opacity: 0, transform: "translateX(-8px)" },
|
| 137 |
-
];
|
| 138 |
-
break;
|
| 139 |
}
|
| 140 |
-
|
| 141 |
await cloned.animate(keyframes, {
|
| 142 |
duration: 400,
|
| 143 |
easing: "cubic-bezier(0.22, 1, 0.36, 1)",
|
|
|
|
| 72 |
}).then(({ x, y, placement: _placement }) => {
|
| 73 |
placement = _placement;
|
| 74 |
Object.assign(node.style, {
|
| 75 |
+
left: placement.startsWith("top") ? `${x}px` : `${x - 4}px`,
|
| 76 |
+
top: placement.startsWith("top") ? `${y - 6}px` : `${y}px`,
|
| 77 |
});
|
| 78 |
|
| 79 |
// Animate
|
|
|
|
| 82 |
|
| 83 |
// Determine animation direction based on placement
|
| 84 |
let keyframes: Keyframe[] = [];
|
| 85 |
+
if (placement.startsWith("top")) {
|
| 86 |
+
keyframes = [
|
| 87 |
+
{ opacity: 0, transform: "translateX(var(--tx, 0)) translateY(8px)", scale: "0.8" },
|
| 88 |
+
{ opacity: 1, transform: "translateX(var(--tx, 0)) translateY(0)", scale: "1" },
|
| 89 |
+
];
|
| 90 |
+
} else if (placement.startsWith("left")) {
|
| 91 |
+
keyframes = [
|
| 92 |
+
{ opacity: 0, transform: "translateX(8px)", scale: "0.8" },
|
| 93 |
+
{ opacity: 1, transform: "translateX(0)", scale: "1" },
|
| 94 |
+
];
|
|
|
|
|
|
|
|
|
|
| 95 |
}
|
| 96 |
|
| 97 |
node.animate(keyframes, {
|
|
|
|
| 120 |
|
| 121 |
// Determine animation direction based on placement
|
| 122 |
let keyframes: Keyframe[] = [];
|
| 123 |
+
if (placement.startsWith("top")) {
|
| 124 |
+
keyframes = [
|
| 125 |
+
{ opacity: 1, transform: "translateX(var(--tx, 0)) translateY(0)" },
|
| 126 |
+
{ opacity: 0, transform: "translateX(var(--tx, 0)) translateY(-8px)" },
|
| 127 |
+
];
|
| 128 |
+
} else if (placement.startsWith("left")) {
|
| 129 |
+
keyframes = [
|
| 130 |
+
{ opacity: 1, transform: "translateX(0)" },
|
| 131 |
+
{ opacity: 0, transform: "translateX(-8px)" },
|
| 132 |
+
];
|
|
|
|
|
|
|
|
|
|
| 133 |
}
|
|
|
|
| 134 |
await cloned.animate(keyframes, {
|
| 135 |
duration: 400,
|
| 136 |
easing: "cubic-bezier(0.22, 1, 0.36, 1)",
|
src/lib/components/inference-playground/message-textarea.svelte
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
import { autofocus } from "$lib/attachments/autofocus.js";
|
|
|
|
| 3 |
import { TextareaAutosize } from "$lib/spells/textarea-autosize.svelte.js";
|
| 4 |
import { conversations } from "$lib/state/conversations.svelte";
|
| 5 |
import { images } from "$lib/state/images.svelte";
|
|
@@ -19,6 +20,8 @@
|
|
| 19 |
|
| 20 |
let input = $state("");
|
| 21 |
|
|
|
|
|
|
|
| 22 |
async function onKeydown(event: KeyboardEvent) {
|
| 23 |
if (loading) return;
|
| 24 |
const ctrlOrMeta = event.ctrlKey || event.metaKey;
|
|
@@ -41,6 +44,16 @@
|
|
| 41 |
}
|
| 42 |
|
| 43 |
async function sendMessage() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
const c = conversations.active;
|
| 45 |
|
| 46 |
let images: string[] | undefined;
|
|
@@ -128,6 +141,7 @@
|
|
| 128 |
loading && "bg-red-900 hover:bg-red-800 dark:bg-red-600 dark:hover:bg-red-700",
|
| 129 |
!loading && "bg-black hover:bg-gray-900 dark:bg-blue-600 dark:hover:bg-blue-700",
|
| 130 |
]}
|
|
|
|
| 131 |
>
|
| 132 |
{#if loading}
|
| 133 |
<div class="flex flex-none items-center gap-[3px]">
|
|
@@ -182,4 +196,10 @@
|
|
| 182 |
{/each}
|
| 183 |
</div>
|
| 184 |
</label>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
</div>
|
|
|
|
| 1 |
<script lang="ts">
|
| 2 |
import { autofocus } from "$lib/attachments/autofocus.js";
|
| 3 |
+
import { LocalToasts } from "$lib/builders/local-toasts.svelte.js";
|
| 4 |
import { TextareaAutosize } from "$lib/spells/textarea-autosize.svelte.js";
|
| 5 |
import { conversations } from "$lib/state/conversations.svelte";
|
| 6 |
import { images } from "$lib/state/images.svelte";
|
|
|
|
| 20 |
|
| 21 |
let input = $state("");
|
| 22 |
|
| 23 |
+
const localToasts = new LocalToasts({ placement: "top" });
|
| 24 |
+
|
| 25 |
async function onKeydown(event: KeyboardEvent) {
|
| 26 |
if (loading) return;
|
| 27 |
const ctrlOrMeta = event.ctrlKey || event.metaKey;
|
|
|
|
| 44 |
}
|
| 45 |
|
| 46 |
async function sendMessage() {
|
| 47 |
+
if (input.trim() === "" && fileUpload.selected.size === 0) {
|
| 48 |
+
localToasts.addToast({
|
| 49 |
+
data: {
|
| 50 |
+
content: "Please enter a message",
|
| 51 |
+
variant: "danger",
|
| 52 |
+
},
|
| 53 |
+
});
|
| 54 |
+
return;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
const c = conversations.active;
|
| 58 |
|
| 59 |
let images: string[] | undefined;
|
|
|
|
| 141 |
loading && "bg-red-900 hover:bg-red-800 dark:bg-red-600 dark:hover:bg-red-700",
|
| 142 |
!loading && "bg-black hover:bg-gray-900 dark:bg-blue-600 dark:hover:bg-blue-700",
|
| 143 |
]}
|
| 144 |
+
{...localToasts.trigger}
|
| 145 |
>
|
| 146 |
{#if loading}
|
| 147 |
<div class="flex flex-none items-center gap-[3px]">
|
|
|
|
| 196 |
{/each}
|
| 197 |
</div>
|
| 198 |
</label>
|
| 199 |
+
|
| 200 |
+
{#each localToasts.toasts as toast (toast.id)}
|
| 201 |
+
<div class={toast.class} {...toast.attrs} style="--tx: -10px; {toast.attrs.style}">
|
| 202 |
+
{toast.data.content}
|
| 203 |
+
</div>
|
| 204 |
+
{/each}
|
| 205 |
</div>
|