+
-{/if}
+{/if}
\ No newline at end of file
From d6442f969df1b60c30cad022591b35571fba0cef Mon Sep 17 00:00:00 2001
From: GStudiosX <76548041+GStudiosX2@users.noreply.github.com>
Date: Mon, 29 Jul 2024 17:17:39 +0100
Subject: [PATCH 004/127] clear inputs when posting
---
src/routes/PostButton.svelte | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/routes/PostButton.svelte b/src/routes/PostButton.svelte
index 40bd55e5..11e74420 100644
--- a/src/routes/PostButton.svelte
+++ b/src/routes/PostButton.svelte
@@ -47,6 +47,10 @@
if (response.status === 201) {
opened = false;
+ lynt = '';
+ imagePreview = null;
+ fileinput.value = "";
+ image = null;
toast('Your lynt has been published!');
} else {
toast(`Something happened! Error: ${response.status} | ${response.statusText}`);
From f1b491a639bb7cb91844ae6d9e7a4cd5a77c3ffd Mon Sep 17 00:00:00 2001
From: GStudiosX <76548041+GStudiosX2@users.noreply.github.com>
Date: Mon, 29 Jul 2024 17:18:33 +0100
Subject: [PATCH 005/127] fix sse
---
src/routes/MainPage.svelte | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/src/routes/MainPage.svelte b/src/routes/MainPage.svelte
index e4bc119a..d4567187 100644
--- a/src/routes/MainPage.svelte
+++ b/src/routes/MainPage.svelte
@@ -81,17 +81,20 @@
let currentTab = 'For you';
const tabs = ['For you', 'Following', 'New'];
+ let eventSource: EventSource | undefined = undefined;
+
function handleTabChange(tab: string) {
currentTab = tab;
fetchFeed();
if (currentTab === tabs[2]) {
- const eventSource = new EventSource('/api/sse');
+ eventSource = new EventSource('/api/sse');
eventSource.onmessage = async (event) => {
- const newLyntId = JSON.parse(event.data);
-
+ const newLyntId = JSON.parse(event.data);;
await renderLyntAtTop(newLyntId);
- };
+ }
+ } else {
+ eventSource.close();
}
}
From 516bb07e8d6f9e08c392af63d714877e45f283eb Mon Sep 17 00:00:00 2001
From: GStudiosX <76548041+GStudiosX2@users.noreply.github.com>
Date: Mon, 29 Jul 2024 18:25:06 +0100
Subject: [PATCH 006/127] first version of notification ding
---
src/routes/Navigation.svelte | 32 ++++++++++++++++++++++++++++----
src/routes/Notifications.svelte | 4 ++--
src/routes/OutlineButton.svelte | 21 ++++++++++++++++++---
src/routes/stores.ts | 2 +-
4 files changed, 49 insertions(+), 10 deletions(-)
diff --git a/src/routes/Navigation.svelte b/src/routes/Navigation.svelte
index 009c8e3a..c6a6f287 100644
--- a/src/routes/Navigation.svelte
+++ b/src/routes/Navigation.svelte
@@ -6,7 +6,8 @@
import { goto } from '$app/navigation';
import { toggleMode } from 'mode-watcher';
import PostButton from './PostButton.svelte';
- import { onMount } from 'svelte';
+ import { onMount, onDestroy } from 'svelte';
+ import { get } from 'svelte/store';
import { unreadMessages } from "./stores";
export let id: string;
@@ -18,6 +19,8 @@
{ icon: User, label: 'Profile', page: 'profile' + handle }
];
+ let notificationDing = false;
+
function handleNavClick(page: string) {
currentPage.set(page);
if (page === 'home') {
@@ -28,13 +31,34 @@
}
}
- onMount(async () => {
+ async function updateUnread() {
+ notificationDing = false;
+ let count = get(unreadMessages);
const response = await fetch('/api/notifications/unread');
if (response.ok) {
- $unreadMessages = (await response.json()).count;
+ unreadMessages.set((await response.json()).count);
} else {
console.error('Failed to fetch unread messages');
+ return;
+ }
+
+ if ($unreadMessages > count && count !== -1) {
+ notificationDing = true;
}
+ }
+
+ let intervalUnreadUpdate: NodeJS.Timeout | undefined = undefined;
+
+ onMount(async () => {
+ await updateUnread();
+
+ intervalUnreadUpdate = setInterval(async () => {
+ await updateUnread();
+ }, 5000);
+ });
+
+ onDestroy(() => {
+ clearInterval(intervalUnreadUpdate);
});
@@ -53,7 +77,7 @@
icon={item.icon}
text={item.label}
secondary={item.label === 'Notifications' && $unreadMessages > 0 ? $unreadMessages : undefined}
- className="border-none w-full md:w-auto"
+ className="border-none w-full md:w-auto {notificationDing ? item.label === 'Notifications' ? 'new' : '' : ''}"
on:click={() => handleNavClick(item.page)}
/>
{/each}
diff --git a/src/routes/Notifications.svelte b/src/routes/Notifications.svelte
index 3b682638..1e34b845 100644
--- a/src/routes/Notifications.svelte
+++ b/src/routes/Notifications.svelte
@@ -38,12 +38,12 @@
console.error('Failed to fetch notifications');
}
- const response2 = await fetch('/api/notifications/unread');
+ /*const response2 = await fetch('/api/notifications/unread');
if (response2.ok) {
$unreadMessages = (await response2.json()).count;
} else {
console.error('Failed to fetch unread messages');
- }
+ }*/
});
function formatTimeAgo(dateString: string) {
diff --git a/src/routes/OutlineButton.svelte b/src/routes/OutlineButton.svelte
index 19906ece..4393ba35 100644
--- a/src/routes/OutlineButton.svelte
+++ b/src/routes/OutlineButton.svelte
@@ -86,7 +86,7 @@
{/if}
{#if secondary}
{secondary}
@@ -94,7 +94,7 @@