From 1c6def75cfd0599643de334d2938d019568a0dcc Mon Sep 17 00:00:00 2001 From: Francesco Bozzotta <39646929+silicia-apps@users.noreply.github.com> Date: Mon, 19 Feb 2024 13:01:24 +0000 Subject: [PATCH] fix realtime update list --- apps/demo/src/app/database/database.page.html | 1 + apps/demo/src/app/database/database.page.ts | 6 ++++++ libs/core/src/i18n/en.ts | 4 +++- libs/core/src/i18n/it.ts | 5 ++++- .../lib/components/list/list.component.html | 4 ++-- .../src/lib/components/list/list.component.ts | 10 +++++++++- libs/database/src/lib/store/database.state.ts | 18 ++++++++++++------ 7 files changed, 37 insertions(+), 11 deletions(-) diff --git a/apps/demo/src/app/database/database.page.html b/apps/demo/src/app/database/database.page.html index 8adbf41..9ec25f5 100644 --- a/apps/demo/src/app/database/database.page.html +++ b/apps/demo/src/app/database/database.page.html @@ -9,6 +9,7 @@ (sioCoreListItemLeftSwipe)="this.archive($event)" (sioCoreListItemRightSwipe)="this.delete($event)" (sioCoreListInfinite)="this.load($event)" + (sioRefreshList)="this.refresh($event)" > ){ + console.log(event) + this.taskState.setRemoteIndex(''); + this.taskState.load(); + } } diff --git a/libs/core/src/i18n/en.ts b/libs/core/src/i18n/en.ts index a593088..0eab116 100644 --- a/libs/core/src/i18n/en.ts +++ b/libs/core/src/i18n/en.ts @@ -3,5 +3,7 @@ export const en = { 'PAGE_TITLE' : 'Page Title', 'PAGE_COMPONENT_DEFAULT_1' : 'Empty Page', 'PAGE_COMPONENT_DEFAULT_2' : 'Create your contents', - 'PAGE_COMPONENT_LINK' : 'Componet Page of ' + 'PAGE_COMPONENT_LINK' : 'Componet Page of ', + 'LIST_PULL_WAITING': 'Waiting...', + 'LIST_PULL_TEXT': 'Pull To Refresh', } \ No newline at end of file diff --git a/libs/core/src/i18n/it.ts b/libs/core/src/i18n/it.ts index f6590b2..7920a60 100644 --- a/libs/core/src/i18n/it.ts +++ b/libs/core/src/i18n/it.ts @@ -5,5 +5,8 @@ export const it = { 'PAGE_TITLE' : 'Titolo Pagina', 'PAGE_COMPONENT_DEFAULT_1' : 'Pagina Vuota', 'PAGE_COMPONENT_DEFAULT_2' : 'Crea i Tuoi contenuti', - 'PAGE_COMPONENT_LINK' : 'questo è il componente pagina di ' + 'PAGE_COMPONENT_LINK' : 'questo è il componente pagina di ', + 'LIST_PULL_WAITING': 'Attendere...', + 'LIST_PULL_TEXT': 'Trascina per aggiornare', + } \ No newline at end of file diff --git a/libs/core/src/lib/components/list/list.component.html b/libs/core/src/lib/components/list/list.component.html index 55f7b48..1f7975f 100644 --- a/libs/core/src/lib/components/list/list.component.html +++ b/libs/core/src/lib/components/list/list.component.html @@ -1,6 +1,6 @@ - + diff --git a/libs/core/src/lib/components/list/list.component.ts b/libs/core/src/lib/components/list/list.component.ts index 87e5971..dc6f136 100644 --- a/libs/core/src/lib/components/list/list.component.ts +++ b/libs/core/src/lib/components/list/list.component.ts @@ -3,7 +3,7 @@ import { SioColorType } from '../../types'; import { SioCoreLoggerService } from '../../services/logger'; import { AttributeBoolean } from '@angular-ru/cdk/decorators'; import { InputBoolean } from '@angular-ru/cdk/typings'; -import { InfiniteScrollCustomEvent } from '@ionic/angular'; +import { InfiniteScrollCustomEvent, RefresherCustomEvent } from '@ionic/angular'; @Component({ selector: 'sio-list', @@ -43,6 +43,7 @@ export class SioCoreListComponent implements OnInit { @Output() sioCoreListItemLeftSwipe = new EventEmitter>(); @Output() sioCoreListItemRightSwipe = new EventEmitter>(); @Output() sioCoreListInfinite = new EventEmitter>(); + @Output() sioCoreRefreshList = new EventEmitter>(); // @Output() public sioCoreMenuDidChange = new EventEmitter(); @@ -82,6 +83,13 @@ export class SioCoreListComponent implements OnInit { this.sioCoreListItemRightSwipe.emit(data); } + public onRefresh(data: Event) { + this.sioCoreLoggerService.debug('[sioCoreListItemComponent][onRefresh]', data); + setTimeout(() => { + (data as RefresherCustomEvent).target.complete(); + }, 500); + } + public onListInfinite(data: Event) { this.sioCoreLoggerService.debug('[sioCoreListItemComponent][receiveListInfinite]', data); this.sioCoreListInfinite.emit({ LastId : this.data!.pop().$id }); diff --git a/libs/database/src/lib/store/database.state.ts b/libs/database/src/lib/store/database.state.ts index 44c7582..16a7edd 100644 --- a/libs/database/src/lib/store/database.state.ts +++ b/libs/database/src/lib/store/database.state.ts @@ -23,7 +23,7 @@ export abstract class SioDatabaseState< queries: string[]; } > { - public override primaryKey: string = '$id'; + public override primaryKey = '$id'; constructor( private sioCoreLoggerService: SioCoreLoggerService, @@ -35,12 +35,16 @@ export abstract class SioDatabaseState< override ngxsAfterBootstrap(): void { this.sioDatabaseService.subscribe().subscribe((event) => { this.sioCoreLoggerService.debug( - `[SioStorageState][ngxAfterBootstrap] received events`, - ); - this.sioCoreLoggerService.trace( - `[SioStorageState][ngxAfterBootstrap]`, - event, + `[SioDatabaseState][DataSocket] received events`, + event ); + const item = this.selectOne(event.payload.$id); + if (item) { + console.debug('[SioDatabaseState][DataSocket] items in list, updated'); + this.setEntityOne(event.payload); + } else { + console.debug('[SioDatabaseState][DataSocket] items not in list, do anything'); + } this.load(); }); } @@ -88,7 +92,9 @@ export abstract class SioDatabaseState< } this.setRemoteTotals(documents.total); this.setLocalTotals(this.snapshot.ids.length); + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion console.error(documents.documents.pop()!.$id!); + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion this.setRemoteIndex(documents.documents.pop()!.$id!); } return true;