aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui
diff options
context:
space:
mode:
Diffstat (limited to 'ufund-ui')
-rw-r--r--ufund-ui/src/app/components/cupboard/cupboard.component.html4
-rw-r--r--ufund-ui/src/app/components/cupboard/cupboard.component.ts13
-rw-r--r--ufund-ui/src/app/components/funding-basket/funding-basket.component.html2
-rw-r--r--ufund-ui/src/app/components/need-list/need-list.component.ts54
-rw-r--r--ufund-ui/src/app/services/users.service.ts4
5 files changed, 46 insertions, 31 deletions
diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html
index cd8fec2..4eebc2d 100644
--- a/ufund-ui/src/app/components/cupboard/cupboard.component.html
+++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html
@@ -25,7 +25,7 @@
<span class="icon">{{sortMode === 'Ascending' ? 'arrow_upward': 'arrow_downward'}}</span>
</button>
<label>Needs per page: </label>
- <input type ="number" [(ngModel)]="itemsPerPage" min="1" max="{{searchResults.length}}">
+ <input type ="number" [(ngModel)]="itemsPerPage" (change)="editItemsPerPage()" min="1" max="{{searchResults.length}}">
</div>
</div>
<h2 *ngIf="searchResults.length < needs.length && searchResults.length != 0"> Search Results({{needs.length - searchResults.length}} needs filtered): </h2>
@@ -46,5 +46,5 @@
<span class="icon">delete</span>Delete Need
</button>
</ng-template>
- <app-need-list [actionArea]="NLActions" *ngIf="searchResults.length > 0" [needs]="searchResults" [itemsPerPage]="itemsPerPage" #needList/>
+ <app-need-list [uid]="0" [actionArea]="NLActions" *ngIf="searchResults.length > 0" [needs]="searchResults" [itemsPerPage]="itemsPerPage" #needList/>
</div>
diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts
index b03b77e..aca1397 100644
--- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts
+++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts
@@ -26,7 +26,7 @@ export class CupboardComponent implements OnInit {
needs: Need[] = [];
searchResults: Need[] = [];
sortMode: 'Ascending' | 'Descending' = 'Ascending'
- itemsPerPage = 5;
+ itemsPerPage = parseInt(localStorage.getItem('itemsPerPage') ?? '5') ?? 5;
currentSortAlgo = 'sortByPriority';
constructor(
@@ -135,6 +135,17 @@ export class CupboardComponent implements OnInit {
}
}
+ editItemsPerPage() {
+ if (this.itemsPerPage > this.searchResults.length) {
+ this.itemsPerPage = this.searchResults.length
+ }
+ if (this.itemsPerPage < 1) {
+ this.itemsPerPage = 1
+ }
+ localStorage.setItem('itemsPerPage', this.itemsPerPage.toString())
+ this.refresh();
+ }
+
protected readonly SortingAlgorithms = SortingAlgoArrays;
protected readonly Object = Object;
}
diff --git a/ufund-ui/src/app/components/funding-basket/funding-basket.component.html b/ufund-ui/src/app/components/funding-basket/funding-basket.component.html
index 3f840e1..c4b12c9 100644
--- a/ufund-ui/src/app/components/funding-basket/funding-basket.component.html
+++ b/ufund-ui/src/app/components/funding-basket/funding-basket.component.html
@@ -8,7 +8,7 @@
<span class="icon">delete</span>Remove from Basket
</button>
</ng-template>
- <app-need-list [actionArea]="NLActions" [needs]="(usersService.getBasket() | async)!"/>
+ <app-need-list [uid]="1" [actionArea]="NLActions" [needs]="(usersService.getBasket() | async)!"/>
<br>
<div id="footer">
<button class="button2" title="checkout" (click)="checkout()">Checkout</button>
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<any> | 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);
diff --git a/ufund-ui/src/app/services/users.service.ts b/ufund-ui/src/app/services/users.service.ts
index 35d080d..688d6e4 100644
--- a/ufund-ui/src/app/services/users.service.ts
+++ b/ufund-ui/src/app/services/users.service.ts
@@ -60,7 +60,9 @@ export class UsersService {
}
refreshBasket() {
- let promiseArr = this.authService.getCurrentUser()!.basket.map(async needID => {
+ let usr = this.authService.getCurrentUser();
+ if (!usr) return;
+ let promiseArr = usr.basket.map(async needID => {
return await firstValueFrom(this.cupboardService.getNeed(needID));
})
Promise.all(promiseArr).then(r => this.basket.next(r));