Create global inbox actions (#4903)

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina
2024-03-08 14:59:20 +07:00
committed by GitHub
parent 0483e2ac0d
commit 5ce079cf3d
11 changed files with 172 additions and 43 deletions
@@ -18,7 +18,7 @@
DisplayInboxNotification,
DocNotifyContext
} from '@hcengineering/notification'
import { ActionContext, createQuery, getClient, MessageBox } from '@hcengineering/presentation'
import { ActionContext, createQuery, getClient } from '@hcengineering/presentation'
import view, { Viewlet } from '@hcengineering/view'
import {
AnyComponent,
@@ -33,9 +33,7 @@
TabList,
Location,
IconDropdown,
ButtonWithDropdown,
IconCheckAll,
showPopup
ButtonWithDropdown
} from '@hcengineering/ui'
import chunter, { ThreadMessage } from '@hcengineering/chunter'
import { Ref, WithLookup } from '@hcengineering/core'
@@ -45,7 +43,14 @@
import { inboxMessagesStore, InboxNotificationsClientImpl } from '../../inboxNotificationsClient'
import Filter from '../Filter.svelte'
import { getDisplayInboxNotifications, openInboxDoc, resolveLocation } from '../../utils'
import {
archiveAll,
getDisplayInboxNotifications,
openInboxDoc,
readAll,
resolveLocation,
unreadAll
} from '../../utils'
import { InboxNotificationsFilter } from '../../types'
export let visibleNav: boolean = true
@@ -255,35 +260,19 @@
{ size: 'auto', minSize: 30, maxSize: 'auto', float: undefined }
])
function archiveAll (): void {
showPopup(
MessageBox,
{
label: notification.string.ArchiveAllConfirmationTitle,
message: notification.string.ArchiveAllConfirmationMessage
},
'top',
(result?: boolean) => {
if (result === true) {
void inboxClient.deleteAllNotifications()
}
}
)
}
function readAll (): void {
void inboxClient.readAllNotifications()
}
async function dropdownItemSelected (id: 'archive' | 'read'): Promise<void> {
async function dropdownItemSelected (id: 'archive' | 'read' | 'unread'): Promise<void> {
if (id == null) return
if (id === 'archive') {
archiveAll()
void archiveAll()
}
if (id === 'read') {
readAll()
void readAll()
}
if (id === 'unread') {
void unreadAll()
}
}
</script>
@@ -318,14 +307,19 @@
<ButtonWithDropdown
justify="left"
kind="regular"
label={notification.string.ReadAll}
icon={IconCheckAll}
label={notification.string.MarkReadAll}
icon={notification.icon.ReadAll}
on:click={readAll}
dropdownItems={[
{
id: 'read',
icon: IconCheckAll,
label: notification.string.ReadAll
icon: notification.icon.ReadAll,
label: notification.string.MarkReadAll
},
{
id: 'unread',
icon: notification.icon.UnreadAll,
label: notification.string.MarkUnreadAll
},
{
id: 'archive',
@@ -283,4 +283,21 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
await doneOp()
}
}
async unreadAllNotifications (): Promise<void> {
const doneOp = await getClient().measure('unreadAllNotifications')
const ops = getClient().apply(generateId())
try {
const inboxNotifications = get(this.inboxNotifications) ?? []
for (const notification of inboxNotifications) {
if (notification.isViewed) {
await ops.update(notification, { isViewed: false })
}
}
} finally {
await ops.commit()
await doneOp()
}
}
}
+8 -2
View File
@@ -49,7 +49,10 @@ import {
readNotifyContext,
unReadNotifyContext,
deleteContextNotifications,
hasInboxNotifications
hasInboxNotifications,
archiveAll,
readAll,
unreadAll
} from './utils'
import { InboxNotificationsClientImpl } from './inboxNotificationsClient'
@@ -101,7 +104,10 @@ export default async (): Promise<Resources> => ({
UnHideDocNotifyContext: unHideDocNotifyContext,
ReadNotifyContext: readNotifyContext,
UnReadNotifyContext: unReadNotifyContext,
DeleteContextNotifications: deleteContextNotifications
DeleteContextNotifications: deleteContextNotifications,
ArchiveAll: archiveAll,
ReadAll: readAll,
UnreadAll: unreadAll
},
resolver: {
Location: resolveLocation
+32 -2
View File
@@ -38,8 +38,8 @@ import notification, {
type DocNotifyContext,
type InboxNotification
} from '@hcengineering/notification'
import { getClient } from '@hcengineering/presentation'
import { getLocation, navigate, type Location, type ResolvedLocation } from '@hcengineering/ui'
import { getClient, MessageBox } from '@hcengineering/presentation'
import { getLocation, navigate, type Location, type ResolvedLocation, showPopup } from '@hcengineering/ui'
import { get } from 'svelte/store'
import { InboxNotificationsClientImpl } from './inboxNotificationsClient'
@@ -412,6 +412,36 @@ export async function unpinDocNotifyContext (object: DocNotifyContext): Promise<
})
}
export async function archiveAll (): Promise<void> {
const client = InboxNotificationsClientImpl.getClient()
showPopup(
MessageBox,
{
label: notification.string.ArchiveAllConfirmationTitle,
message: notification.string.ArchiveAllConfirmationMessage
},
'top',
(result?: boolean) => {
if (result === true) {
void client.deleteAllNotifications()
}
}
)
}
export async function readAll (): Promise<void> {
const client = InboxNotificationsClientImpl.getClient()
await client.readAllNotifications()
}
export async function unreadAll (): Promise<void> {
const client = InboxNotificationsClientImpl.getClient()
await client.unreadAllNotifications()
}
export async function getDisplayInboxNotifications (
notificationsByContext: Map<Ref<DocNotifyContext>, InboxNotification[]>,
filter: InboxNotificationsFilter = 'all',