simplified the actions again to fix some bugs

This commit is contained in:
Samuel Andert 2023-07-22 19:05:44 +02:00
parent 68708b65d8
commit 4d5b634e55
3 changed files with 19 additions and 12 deletions

View File

@ -1,20 +1,16 @@
<script>
import { createMessage } from '$lib/services/messages';
import { getContextStore } from '$lib/stores/contextStore.ts';
const store = getContextStore('MessageInput');
$: newMessageText = $store.newMessageText; // bind newMessageText from the store
function handleSend() {
if (newMessageText.trim() !== '') {
export function sendMessage(text) {
if (text && text.trim() !== '') {
const message = {
text: newMessageText,
text: text,
sender: 'user',
type: 'chat'
};
const appCommandPattern = /@app:(\w+)/;
const match = newMessageText.match(appCommandPattern);
const match = text.match(appCommandPattern);
if (match && match[1]) {
message.composite = {
layout: '',
@ -30,8 +26,12 @@
createMessage(message);
}
}
function handleSend() {
sendMessage(text);
}
</script>
<button class="px-4 py-2 text-white bg-blue-500 rounded hover:bg-blue-600" on:click={handleSend}>
Send Message
Send
</button>

View File

@ -1,12 +1,18 @@
<script>
import { getContextStore } from '$lib/stores/contextStore.ts';
import ClearMessages from './ClearMessages.svelte';
import SendMessage from './SendMessage.svelte';
const store = getContextStore('MessageInput');
let newMessageText = '';
let sendFunction; // To hold the sendMessage function from SendMessage component
function handleKeyDown(event) {
if (event.key === 'Enter') {
sendFunction(newMessageText);
newMessageText = '';
store.set({ newMessageText }); // Update the store directly
event.preventDefault();
}
}
@ -23,4 +29,6 @@
bind:value={newMessageText}
on:keydown={handleKeyDown}
/>
<SendMessage bind:sendMessage={sendFunction} />
<ClearMessages />
</footer>

View File

@ -25,10 +25,9 @@
},
{
id: 3,
componentName: 'MessageInput',
componentName: 'Terminal',
props: {},
slot: 'footer',
actions: ['ClearMessages', 'SendMessage']
slot: 'footer'
}
]
};