diff --git a/src/lib/services/messages.js b/src/lib/services/messages.js
index 8735dd4..660b55f 100644
--- a/src/lib/services/messages.js
+++ b/src/lib/services/messages.js
@@ -1,11 +1,60 @@
-// src/lib/messaging.js
-import { messagesStore } from '$lib/data//stores';
+import { writable } from 'svelte/store';
-export function addMessage(message) {
- const timestamp = new Date().toLocaleString();
- messagesStore.update((messages) => [{ text: message, timestamp }, ...messages]);
+// Helper function to determine if we're running on the client side (browser) or server side.
+function isClientSide() {
+ return typeof window !== "undefined";
+}
+
+// Safely get item from localStorage
+function getFromLocalStorage(key, defaultValue) {
+ if (isClientSide()) {
+ return localStorage.getItem(key)
+ ? JSON.parse(localStorage.getItem(key))
+ : defaultValue;
+ }
+ return defaultValue;
+}
+
+// Safely set item to localStorage
+function setToLocalStorage(key, value) {
+ if (isClientSide()) {
+ localStorage.setItem(key, JSON.stringify(value));
+ }
+}
+
+// Load messages from localStorage or set an empty array if not available
+const initialMessages = getFromLocalStorage('chat-messages', []);
+
+export const messages = writable(initialMessages);
+
+// Subscribe to messages store to watch for changes and save them to localStorage
+messages.subscribe(currentMessages => {
+ setToLocalStorage('chat-messages', currentMessages);
+});
+
+// Dummy messages
+const messagesList = [
+ "Hello there!",
+ "How are you?",
+ "What's your favorite color?",
+ "Nice weather today!",
+ "Have a great day!",
+ "I love Svelte!",
+ "Svelte is awesome!",
+ "Learning Svelte is fun!",
+ "Greetings from Svelte!",
+ "Keep coding and stay awesome!"
+];
+
+export function addRandomMessage() {
+ const randomMessage = messagesList[Math.floor(Math.random() * messagesList.length)];
+ const currentDate = new Date().toLocaleString();
+ messages.update(oldMessages => [
+ ...oldMessages,
+ { text: randomMessage, timestamp: currentDate }
+ ]);
}
export function clearMessages() {
- messagesStore.set([]);
+ messages.set([]);
}
diff --git a/src/routes/log/write/+page.svelte b/src/routes/log/write/+page.svelte
deleted file mode 100644
index 78e9c50..0000000
--- a/src/routes/log/write/+page.svelte
+++ /dev/null
@@ -1,34 +0,0 @@
-
-
-
-
-
-
-
-
-