mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
notification cursor
This commit is contained in:
committed by
Aiden McClelland
parent
9a75474aa9
commit
2a8224abcf
@@ -13,10 +13,10 @@ import { ErrorToastService } from 'src/app/services/error-toast.service'
|
|||||||
export class NotificationsPage {
|
export class NotificationsPage {
|
||||||
loading = true
|
loading = true
|
||||||
notifications: ServerNotifications = []
|
notifications: ServerNotifications = []
|
||||||
page = 1
|
beforeCursor: number
|
||||||
needInfinite = false
|
needInfinite = false
|
||||||
fromToast = false
|
fromToast = false
|
||||||
readonly perPage = 20
|
readonly perPage = 40
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
private readonly embassyApi: ApiService,
|
private readonly embassyApi: ApiService,
|
||||||
@@ -33,7 +33,7 @@ export class NotificationsPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async refresh (e: any) {
|
async refresh (e: any) {
|
||||||
this.page = 1
|
this.beforeCursor = undefined
|
||||||
this.notifications = await this.getNotifications(),
|
this.notifications = await this.getNotifications(),
|
||||||
e.target.complete()
|
e.target.complete()
|
||||||
}
|
}
|
||||||
@@ -47,9 +47,9 @@ export class NotificationsPage {
|
|||||||
async getNotifications (): Promise<ServerNotifications> {
|
async getNotifications (): Promise<ServerNotifications> {
|
||||||
let notifications: ServerNotifications = []
|
let notifications: ServerNotifications = []
|
||||||
try {
|
try {
|
||||||
notifications = await this.embassyApi.getNotifications({ page: this.page, 'per-page': this.perPage })
|
notifications = await this.embassyApi.getNotifications({ before: this.beforeCursor, limit: this.perPage })
|
||||||
|
this.beforeCursor = notifications[notifications.length - 1]?.id
|
||||||
this.needInfinite = notifications.length >= this.perPage
|
this.needInfinite = notifications.length >= this.perPage
|
||||||
this.page++
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.errToast.present(e)
|
this.errToast.present(e)
|
||||||
} finally {
|
} finally {
|
||||||
@@ -68,6 +68,7 @@ export class NotificationsPage {
|
|||||||
try {
|
try {
|
||||||
await this.embassyApi.deleteNotification({ id })
|
await this.embassyApi.deleteNotification({ id })
|
||||||
this.notifications.splice(index, 1)
|
this.notifications.splice(index, 1)
|
||||||
|
this.beforeCursor = this.notifications[this.notifications.length - 1].id
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.errToast.present(e)
|
this.errToast.present(e)
|
||||||
} finally {
|
} finally {
|
||||||
@@ -86,6 +87,7 @@ export class NotificationsPage {
|
|||||||
try {
|
try {
|
||||||
await this.embassyApi.deleteAllNotifications({ })
|
await this.embassyApi.deleteAllNotifications({ })
|
||||||
this.notifications = []
|
this.notifications = []
|
||||||
|
this.beforeCursor = undefined
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.errToast.present(e)
|
this.errToast.present(e)
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -637,7 +637,7 @@ export module Mock {
|
|||||||
|
|
||||||
export const Notifications: ServerNotifications = [
|
export const Notifications: ServerNotifications = [
|
||||||
{
|
{
|
||||||
id: '123e4567-e89b-12d3-a456-426655440000',
|
id: 1,
|
||||||
'package-id': null,
|
'package-id': null,
|
||||||
'created-at': '2019-12-26T14:20:30.872Z',
|
'created-at': '2019-12-26T14:20:30.872Z',
|
||||||
code: 1,
|
code: 1,
|
||||||
@@ -657,7 +657,7 @@ export module Mock {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '123e4567-e89b-12d3-a456-426655440001',
|
id: 2,
|
||||||
'package-id': 'bitcoind',
|
'package-id': 'bitcoind',
|
||||||
'created-at': '2019-12-26T14:20:30.872Z',
|
'created-at': '2019-12-26T14:20:30.872Z',
|
||||||
code: 2,
|
code: 2,
|
||||||
@@ -667,7 +667,7 @@ export module Mock {
|
|||||||
data: null,
|
data: null,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '123e4567-e89b-12d3-a456-426655440002',
|
id: 3,
|
||||||
'package-id': 'bitcoind',
|
'package-id': 'bitcoind',
|
||||||
'created-at': '2019-12-26T14:20:30.872Z',
|
'created-at': '2019-12-26T14:20:30.872Z',
|
||||||
code: 3,
|
code: 3,
|
||||||
@@ -677,7 +677,7 @@ export module Mock {
|
|||||||
data: null,
|
data: null,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '123e4567-e89b-12d3-a456-426655440003',
|
id: 4,
|
||||||
'package-id': 'bitcoind',
|
'package-id': 'bitcoind',
|
||||||
'created-at': '2019-12-26T14:20:30.872Z',
|
'created-at': '2019-12-26T14:20:30.872Z',
|
||||||
code: 4,
|
code: 4,
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ export module RR {
|
|||||||
|
|
||||||
// notification
|
// notification
|
||||||
|
|
||||||
export type GetNotificationsReq = WithExpire<{ page: number, 'per-page': number }> // notification.list
|
export type GetNotificationsReq = WithExpire<{ before?: number, after?: number, limit?: number }> // notification.list
|
||||||
export type GetNotificationsRes = WithRevision<ServerNotification<number>[]>
|
export type GetNotificationsRes = WithRevision<ServerNotification<number>[]>
|
||||||
|
|
||||||
export type DeleteNotificationReq = { id: string } // notification.delete
|
export type DeleteNotificationReq = { id: string } // notification.delete
|
||||||
@@ -326,7 +326,7 @@ export interface SSHKeyEntry {
|
|||||||
export type ServerNotifications = ServerNotification<any>[]
|
export type ServerNotifications = ServerNotification<any>[]
|
||||||
|
|
||||||
export interface ServerNotification<T extends number> {
|
export interface ServerNotification<T extends number> {
|
||||||
id: string
|
id: number
|
||||||
'package-id': string | null
|
'package-id': string | null
|
||||||
'created-at': string
|
'created-at': string
|
||||||
code: T
|
code: T
|
||||||
|
|||||||
Reference in New Issue
Block a user