pulling out the basic messaging service.

This commit is contained in:
Samuel Andert
2023-07-21 13:47:09 +02:00
parent 5e827cd939
commit 6c691c7be3
3 changed files with 56 additions and 72 deletions

View File

@ -1,38 +1,7 @@
<script>
import { writable } from 'svelte/store';
// Dummy messages
const messagesList = [
"Believe you can, and you're halfway there.",
'The only way to do great work is to love what you do.',
'Success is not final, failure is not fatal: It is the courage to continue that counts.',
'The best way to predict the future is to create it.',
"Your time is limited, don't waste it living someone else's life.",
'Every moment is a fresh beginning.',
"Don't watch the clock; do what it does. Keep going.",
'Believe in yourself and all that you are. Know that there is something inside you that is greater than any obstacle.',
'You are never too old to set another goal or to dream a new dream.',
'The future belongs to those who believe in the beauty of their dreams.'
];
// Reactive store to store chat messages
const messages = writable([]);
function addRandomMessage() {
const randomMessage = messagesList[Math.floor(Math.random() * messagesList.length)];
const currentDate = new Date().toLocaleString();
messages.update((oldMessages) => [
...oldMessages,
{ text: randomMessage, timestamp: currentDate }
]);
}
// Function to clear all messages
function clearMessages() {
messages.set([]);
}
import { messages, clearMessages, addRandomMessage } from '$lib/services/messages';
</script>
<!-- HTML content -->
<main class="p-4 flex flex-col-reverse overflow-y-auto h-[calc(100vh-70px)]">
<div class="flex flex-col space-y-4">
<!-- Your messages, displayed in chronological order -->