mirror of
https://github.com/modrinth/code.git
synced 2026-09-04 05:48:57 +00:00
feat: add 2 second auto close on skipped notifications (#6191)
This commit is contained in:
@@ -872,6 +872,7 @@ function notifySkippedQueueProjects(count: number) {
|
|||||||
title: 'Skipped projects',
|
title: 'Skipped projects',
|
||||||
text: `Skipped ${count} project(s) already moderated or locked by others.`,
|
text: `Skipped ${count} project(s) already moderated or locked by others.`,
|
||||||
type: 'info',
|
type: 'info',
|
||||||
|
autoCloseMs: 2000,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -515,6 +515,16 @@ function goToPage(page: number) {
|
|||||||
currentPage.value = page
|
currentPage.value = page
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function notifySkippedProjects(skippedCount: number) {
|
||||||
|
if (skippedCount <= 0) return
|
||||||
|
addNotification({
|
||||||
|
title: 'Skipped projects',
|
||||||
|
text: `Skipped ${skippedCount} project(s) already moderated or locked by others.`,
|
||||||
|
type: 'info',
|
||||||
|
autoCloseMs: 2000,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
async function findFirstEligibleProject(): Promise<ModerationProject | null> {
|
async function findFirstEligibleProject(): Promise<ModerationProject | null> {
|
||||||
let skippedCount = 0
|
let skippedCount = 0
|
||||||
|
|
||||||
@@ -539,13 +549,7 @@ async function findFirstEligibleProject(): Promise<ModerationProject | null> {
|
|||||||
const lockStatus = await moderationQueue.checkLock(currentId)
|
const lockStatus = await moderationQueue.checkLock(currentId)
|
||||||
|
|
||||||
if (!lockStatus.locked || lockStatus.expired || lockStatus.is_own_lock) {
|
if (!lockStatus.locked || lockStatus.expired || lockStatus.is_own_lock) {
|
||||||
if (skippedCount > 0) {
|
notifySkippedProjects(skippedCount)
|
||||||
addNotification({
|
|
||||||
title: 'Skipped projects',
|
|
||||||
text: `Skipped ${skippedCount} project(s) already moderated or locked by others.`,
|
|
||||||
type: 'info',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return project
|
return project
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -556,13 +560,7 @@ async function findFirstEligibleProject(): Promise<ModerationProject | null> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skippedCount > 0) {
|
notifySkippedProjects(skippedCount)
|
||||||
addNotification({
|
|
||||||
title: 'Skipped projects',
|
|
||||||
text: `Skipped ${skippedCount} project(s) already moderated or locked by others.`,
|
|
||||||
type: 'info',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export interface WebNotification {
|
|||||||
type?: 'error' | 'warning' | 'success' | 'info'
|
type?: 'error' | 'warning' | 'success' | 'info'
|
||||||
errorCode?: string
|
errorCode?: string
|
||||||
count?: number
|
count?: number
|
||||||
|
autoCloseMs?: number | null // null means do not dismiss automatically
|
||||||
timer?: NodeJS.Timeout
|
timer?: NodeJS.Timeout
|
||||||
supportData?: Record<string, unknown>
|
supportData?: Record<string, unknown>
|
||||||
}
|
}
|
||||||
@@ -14,7 +15,7 @@ export interface WebNotification {
|
|||||||
export type NotificationPanelLocation = 'left' | 'right'
|
export type NotificationPanelLocation = 'left' | 'right'
|
||||||
|
|
||||||
export abstract class AbstractWebNotificationManager {
|
export abstract class AbstractWebNotificationManager {
|
||||||
protected readonly AUTO_DISMISS_DELAY_MS = 30 * 1000
|
protected readonly DEFAULT_AUTO_DISMISS_DELAY_MS = 30 * 1000
|
||||||
|
|
||||||
abstract getNotifications(): WebNotification[]
|
abstract getNotifications(): WebNotification[]
|
||||||
abstract getNotificationLocation(): NotificationPanelLocation
|
abstract getNotificationLocation(): NotificationPanelLocation
|
||||||
@@ -90,9 +91,13 @@ export abstract class AbstractWebNotificationManager {
|
|||||||
|
|
||||||
this.clearNotificationTimer(notification)
|
this.clearNotificationTimer(notification)
|
||||||
|
|
||||||
|
if (notification.autoCloseMs === null) return
|
||||||
|
|
||||||
|
const delay = notification.autoCloseMs ?? DEFAULT_AUTO_DISMISS_DELAY_MS
|
||||||
|
|
||||||
notification.timer = setTimeout(() => {
|
notification.timer = setTimeout(() => {
|
||||||
this.removeNotification(notification.id)
|
this.removeNotification(notification.id)
|
||||||
}, this.AUTO_DISMISS_DELAY_MS)
|
}, delay)
|
||||||
}
|
}
|
||||||
|
|
||||||
stopNotificationTimer = (notification: WebNotification): void => {
|
stopNotificationTimer = (notification: WebNotification): void => {
|
||||||
|
|||||||
Reference in New Issue
Block a user