mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-04-13 08:25:35 -04:00
Only mark actually read announcements as read
This commit is contained in:
@@ -56,22 +56,21 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<template #custom-card-action>
|
<template #custom-card-action>
|
||||||
<div v-if="newAnnouncements.length">
|
<BaseButton
|
||||||
<BaseButton
|
v-if="newAnnouncements.length"
|
||||||
color="success"
|
color="success"
|
||||||
:icon="$globals.icons.textBoxCheckOutline"
|
:icon="$globals.icons.textBoxCheckOutline"
|
||||||
:text="$t('announcements.mark-all-as-read')"
|
:text="$t('announcements.mark-all-as-read')"
|
||||||
class="mx-4"
|
@click="markAllAsRead"
|
||||||
@click="markAllAsRead"
|
/>
|
||||||
/>
|
<BaseButton
|
||||||
<BaseButton
|
:disabled="isLastAnnouncement(currentAnnouncement.key)"
|
||||||
color="info"
|
color="info"
|
||||||
:icon="$globals.icons.arrowRightBold"
|
:icon="$globals.icons.arrowRightBold"
|
||||||
icon-right
|
icon-right
|
||||||
:text="$t('general.next')"
|
:text="$t('general.next')"
|
||||||
@click="nextAnnouncement"
|
@click="nextAnnouncement"
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
</BaseDialog>
|
</BaseDialog>
|
||||||
</template>
|
</template>
|
||||||
@@ -85,9 +84,10 @@ const dialog = defineModel<boolean>({ default: false });
|
|||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
watch(() => route.fullPath, () => { dialog.value = false; });
|
watch(() => route.fullPath, () => { dialog.value = false; });
|
||||||
|
|
||||||
const { newAnnouncements, allAnnouncements, setLastRead } = useAnnouncements();
|
const { newAnnouncements, allAnnouncements, setLastRead, markAllAsRead } = useAnnouncements();
|
||||||
|
|
||||||
const currentAnnouncement = shallowRef<Announcement | undefined>();
|
const currentAnnouncement = shallowRef<Announcement | undefined>();
|
||||||
|
|
||||||
watch(dialog, () => {
|
watch(dialog, () => {
|
||||||
if (!dialog.value || currentAnnouncement.value) {
|
if (!dialog.value || currentAnnouncement.value) {
|
||||||
return;
|
return;
|
||||||
@@ -103,17 +103,20 @@ function setCurrentAnnouncement(announcement: Announcement) {
|
|||||||
setLastRead(announcement.key);
|
setLastRead(announcement.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
function markAllAsRead() {
|
|
||||||
setLastRead(allAnnouncements.at(-1)!.key);
|
|
||||||
}
|
|
||||||
|
|
||||||
function nextAnnouncement() {
|
function nextAnnouncement() {
|
||||||
const next = newAnnouncements.value.at(0);
|
// Find the first unread announcement after the current one (current is already removed from newAnnouncements)
|
||||||
if (!next) {
|
const next = newAnnouncements.value.find(a => a.key > currentAnnouncement.value!.key);
|
||||||
markAllAsRead();
|
if (next) {
|
||||||
}
|
|
||||||
else {
|
|
||||||
setCurrentAnnouncement(next);
|
setCurrentAnnouncement(next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isLastAnnouncement(key: string) {
|
||||||
|
if (!newAnnouncements.value.length) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return key >= newAnnouncements.value.at(-1)!.key;
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -65,6 +65,11 @@ export function useAnnouncements() {
|
|||||||
// The welcome announcement is a special case: it's shown to new users and
|
// The welcome announcement is a special case: it's shown to new users and
|
||||||
// all other announcements are marked as read when they view it
|
// all other announcements are marked as read when they view it
|
||||||
key = allAnnouncements.at(-1)!.key;
|
key = allAnnouncements.at(-1)!.key;
|
||||||
|
updateUnreadAnnouncements(key);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Only mark this specific announcement as read in the current session
|
||||||
|
newAnnouncements.value = newAnnouncements.value.filter(a => a.key !== key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.lastReadAnnouncement && key <= user.lastReadAnnouncement) {
|
if (user.lastReadAnnouncement && key <= user.lastReadAnnouncement) {
|
||||||
@@ -72,8 +77,6 @@ export function useAnnouncements() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateUnreadAnnouncements(key);
|
|
||||||
|
|
||||||
user.lastReadAnnouncement = key; // update immediately so we don't have to wait for the db
|
user.lastReadAnnouncement = key; // update immediately so we don't have to wait for the db
|
||||||
await api.users.updateOne(
|
await api.users.updateOne(
|
||||||
user.id,
|
user.id,
|
||||||
@@ -85,6 +88,11 @@ export function useAnnouncements() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function markAllAsRead() {
|
||||||
|
setLastRead(allAnnouncements.at(-1)!.key);
|
||||||
|
newAnnouncements.value = [];
|
||||||
|
}
|
||||||
|
|
||||||
function initUnreadAnnouncements() {
|
function initUnreadAnnouncements() {
|
||||||
const user = auth.user.value;
|
const user = auth.user.value;
|
||||||
|
|
||||||
@@ -122,5 +130,6 @@ export function useAnnouncements() {
|
|||||||
newAnnouncements,
|
newAnnouncements,
|
||||||
allAnnouncements,
|
allAnnouncements,
|
||||||
setLastRead,
|
setLastRead,
|
||||||
|
markAllAsRead,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user