From 2a8224abcf4520cbcd0caf8b2aa91b60739ce5a8 Mon Sep 17 00:00:00 2001 From: Drew Ansbacher Date: Tue, 14 Sep 2021 10:43:29 -0600 Subject: [PATCH] notification cursor --- ui/src/app/pages/notifications/notifications.page.ts | 12 +++++++----- ui/src/app/services/api/api.fixures.ts | 8 ++++---- ui/src/app/services/api/api.types.ts | 4 ++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/ui/src/app/pages/notifications/notifications.page.ts b/ui/src/app/pages/notifications/notifications.page.ts index 8939805eb..dd8d86149 100644 --- a/ui/src/app/pages/notifications/notifications.page.ts +++ b/ui/src/app/pages/notifications/notifications.page.ts @@ -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 { 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 { diff --git a/ui/src/app/services/api/api.fixures.ts b/ui/src/app/services/api/api.fixures.ts index c3041ceaf..44a00c2a1 100644 --- a/ui/src/app/services/api/api.fixures.ts +++ b/ui/src/app/services/api/api.fixures.ts @@ -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, diff --git a/ui/src/app/services/api/api.types.ts b/ui/src/app/services/api/api.types.ts index 134f2f741..81eff7141 100644 --- a/ui/src/app/services/api/api.types.ts +++ b/ui/src/app/services/api/api.types.ts @@ -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[]> export type DeleteNotificationReq = { id: string } // notification.delete @@ -326,7 +326,7 @@ export interface SSHKeyEntry { export type ServerNotifications = ServerNotification[] export interface ServerNotification { - id: string + id: number 'package-id': string | null 'created-at': string code: T