notification cursor

This commit is contained in:
Drew Ansbacher
2021-09-14 10:43:29 -06:00
committed by Aiden McClelland
parent 9a75474aa9
commit 2a8224abcf
3 changed files with 13 additions and 11 deletions

View File

@@ -13,10 +13,10 @@ import { ErrorToastService } from 'src/app/services/error-toast.service'
export class NotificationsPage {
loading = true
notifications: ServerNotifications = []
page = 1
beforeCursor: number
needInfinite = false
fromToast = false
readonly perPage = 20
readonly perPage = 40
constructor (
private readonly embassyApi: ApiService,
@@ -33,7 +33,7 @@ export class NotificationsPage {
}
async refresh (e: any) {
this.page = 1
this.beforeCursor = undefined
this.notifications = await this.getNotifications(),
e.target.complete()
}
@@ -47,9 +47,9 @@ export class NotificationsPage {
async getNotifications (): Promise<ServerNotifications> {
let notifications: ServerNotifications = []
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.page++
} catch (e) {
this.errToast.present(e)
} finally {
@@ -68,6 +68,7 @@ export class NotificationsPage {
try {
await this.embassyApi.deleteNotification({ id })
this.notifications.splice(index, 1)
this.beforeCursor = this.notifications[this.notifications.length - 1].id
} catch (e) {
this.errToast.present(e)
} finally {
@@ -86,6 +87,7 @@ export class NotificationsPage {
try {
await this.embassyApi.deleteAllNotifications({ })
this.notifications = []
this.beforeCursor = undefined
} catch (e) {
this.errToast.present(e)
} finally {

View File

@@ -637,7 +637,7 @@ export module Mock {
export const Notifications: ServerNotifications = [
{
id: '123e4567-e89b-12d3-a456-426655440000',
id: 1,
'package-id': null,
'created-at': '2019-12-26T14:20:30.872Z',
code: 1,
@@ -657,7 +657,7 @@ export module Mock {
},
},
{
id: '123e4567-e89b-12d3-a456-426655440001',
id: 2,
'package-id': 'bitcoind',
'created-at': '2019-12-26T14:20:30.872Z',
code: 2,
@@ -667,7 +667,7 @@ export module Mock {
data: null,
},
{
id: '123e4567-e89b-12d3-a456-426655440002',
id: 3,
'package-id': 'bitcoind',
'created-at': '2019-12-26T14:20:30.872Z',
code: 3,
@@ -677,7 +677,7 @@ export module Mock {
data: null,
},
{
id: '123e4567-e89b-12d3-a456-426655440003',
id: 4,
'package-id': 'bitcoind',
'created-at': '2019-12-26T14:20:30.872Z',
code: 4,

View File

@@ -68,7 +68,7 @@ export module RR {
// 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 DeleteNotificationReq = { id: string } // notification.delete
@@ -326,7 +326,7 @@ export interface SSHKeyEntry {
export type ServerNotifications = ServerNotification<any>[]
export interface ServerNotification<T extends number> {
id: string
id: number
'package-id': string | null
'created-at': string
code: T