From 5186df87c75d83eb24a2cb5d868d8d0bb6aa5b88 Mon Sep 17 00:00:00 2001 From: benal01 Date: Fri, 4 Apr 2025 10:37:45 -0400 Subject: localstorage for page (keeps current page on refresh/back arrow) --- ufund-ui/src/app/components/need-list/need-list.component.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'ufund-ui/src/app/components/need-list/need-list.component.ts') diff --git a/ufund-ui/src/app/components/need-list/need-list.component.ts b/ufund-ui/src/app/components/need-list/need-list.component.ts index ae6bc99..39ff538 100644 --- a/ufund-ui/src/app/components/need-list/need-list.component.ts +++ b/ufund-ui/src/app/components/need-list/need-list.component.ts @@ -68,7 +68,7 @@ export class NeedListComponent { searchResults: Need[] = []; visibleNeeds: Need[] = []; sortMode: 'Ascending' | 'Descending' = 'Ascending' - currentPage: number = 0; + currentPage: number = localStorage.getItem('currentPage') ? parseInt(localStorage.getItem('currentPage')!) : 0; itemsPerPage: number = 5; totalPages: number = Math.ceil(this.needs.length / this.itemsPerPage); @@ -76,26 +76,33 @@ export class NeedListComponent { return (need.type === GoalType.MONETARY) ? "$" : ""; } + //increment/decrement decrementPage() { this.currentPage--; + localStorage.setItem('currentPage', this.currentPage.toString()); this.updateVisibleNeeds(); } incrementPage() { this.currentPage++; + localStorage.setItem('currentPage', this.currentPage.toString()); this.updateVisibleNeeds(); } + //skipping pages lastPage() { this.currentPage = this.totalPages - 1 + localStorage.setItem('currentPage', this.currentPage.toString()); this.updateVisibleNeeds() } firstPage() { this.currentPage = 0 + localStorage.setItem('currentPage', this.currentPage.toString()); this.updateVisibleNeeds() } + //user editing needs per page editNeedsPerPage() { if (this.itemsPerPage > this.searchResults.length) { this.itemsPerPage = this.searchResults.length; @@ -106,13 +113,16 @@ export class NeedListComponent { this.resetVisibleNeeds(); } + //refresing visible needs updateVisibleNeeds() { this.totalPages = Math.ceil(this.searchResults.length / this.itemsPerPage); this.visibleNeeds = this.searchResults.slice(this.currentPage * this.itemsPerPage, (this.currentPage + 1) * this.itemsPerPage); } + //reset back to first page and refresh needs resetVisibleNeeds() { this.currentPage = 0; + localStorage.setItem('currentPage', this.currentPage.toString()); this.updateVisibleNeeds(); } -- cgit v1.2.3 From 4e59fe19150614b8a9b8033d50cb8a3e0ea1d13b Mon Sep 17 00:00:00 2001 From: benal01 Date: Sat, 5 Apr 2025 13:18:30 -0400 Subject: need items per page persistence --- ufund-ui/src/app/components/need-list/need-list.component.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ufund-ui/src/app/components/need-list/need-list.component.ts') diff --git a/ufund-ui/src/app/components/need-list/need-list.component.ts b/ufund-ui/src/app/components/need-list/need-list.component.ts index 39ff538..ca92eeb 100644 --- a/ufund-ui/src/app/components/need-list/need-list.component.ts +++ b/ufund-ui/src/app/components/need-list/need-list.component.ts @@ -69,7 +69,7 @@ export class NeedListComponent { visibleNeeds: Need[] = []; sortMode: 'Ascending' | 'Descending' = 'Ascending' currentPage: number = localStorage.getItem('currentPage') ? parseInt(localStorage.getItem('currentPage')!) : 0; - itemsPerPage: number = 5; + itemsPerPage: number = localStorage.getItem('itemsPerPage') ? parseInt(localStorage.getItem('itemsPerPage')!) : 5; totalPages: number = Math.ceil(this.needs.length / this.itemsPerPage); getPrefix(need: Need) { @@ -110,6 +110,7 @@ export class NeedListComponent { if (this.itemsPerPage < 1) { this.itemsPerPage = 1; } + localStorage.setItem('itemsPerPage', this.itemsPerPage.toString()); this.resetVisibleNeeds(); } -- cgit v1.2.3 From 80492e8f6f88bff8035e27b814cc9eacbee40c65 Mon Sep 17 00:00:00 2001 From: sowgro Date: Sat, 5 Apr 2025 16:29:05 -0400 Subject: Fix storage after merge --- .../components/need-list/need-list.component.ts | 54 +++++++++++----------- 1 file changed, 28 insertions(+), 26 deletions(-) (limited to 'ufund-ui/src/app/components/need-list/need-list.component.ts') diff --git a/ufund-ui/src/app/components/need-list/need-list.component.ts b/ufund-ui/src/app/components/need-list/need-list.component.ts index 564f1f0..7ca0ae7 100644 --- a/ufund-ui/src/app/components/need-list/need-list.component.ts +++ b/ufund-ui/src/app/components/need-list/need-list.component.ts @@ -10,46 +10,48 @@ import {GoalType, Need} from '../../models/Need'; export class NeedListComponent implements OnChanges { @Input({required: true}) needs!: Need[] + @Input({required: true}) uid!: number @Input() itemsPerPage: number = 5; @Input() actionArea: TemplateRef | null = null visibleNeeds: Need[] = []; - currentPage: number = localStorage.getItem('currentPage') ? parseInt(localStorage.getItem('currentPage')!) : 0; + currentPage: number = parseInt(localStorage.getItem('currentPage'+this.uid) ?? '0') ?? 0; totalPages: number = 0; ngOnChanges() { this.updateVisibleNeeds() + this.currentPage = parseInt(localStorage.getItem('currentPage'+this.uid) ?? '0') ?? 0; } getPrefix(need: Need) { return (need.type === GoalType.MONETARY) ? "$" : ""; } - //increment/decrement - decrementPage() { - this.currentPage--; - localStorage.setItem('currentPage', this.currentPage.toString()); - this.updateVisibleNeeds(); - } - - incrementPage() { - this.currentPage++; - localStorage.setItem('currentPage', this.currentPage.toString()); - this.updateVisibleNeeds(); - } - - //skipping pages - lastPage() { - this.currentPage = this.totalPages - 1 - localStorage.setItem('currentPage', this.currentPage.toString()); - this.updateVisibleNeeds() - } - - firstPage() { - this.currentPage = 0 - localStorage.setItem('currentPage', this.currentPage.toString()); - this.updateVisibleNeeds() - } + //increment/decrement + decrementPage() { + this.currentPage--; + localStorage.setItem('currentPage'+this.uid, this.currentPage.toString()); + this.updateVisibleNeeds(); + } + + incrementPage() { + this.currentPage++; + localStorage.setItem('currentPage'+this.uid, this.currentPage.toString()); + this.updateVisibleNeeds(); + } + + //skipping pages + lastPage() { + this.currentPage = this.totalPages - 1 + localStorage.setItem('currentPage'+this.uid, this.currentPage.toString()); + this.updateVisibleNeeds() + } + + firstPage() { + this.currentPage = 0 + localStorage.setItem('currentPage'+this.uid, this.currentPage.toString()); + this.updateVisibleNeeds() + } updateVisibleNeeds() { this.totalPages = Math.ceil(this.needs.length / this.itemsPerPage); -- cgit v1.2.3