aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui/src/app/components/cupboard
diff options
context:
space:
mode:
Diffstat (limited to 'ufund-ui/src/app/components/cupboard')
-rw-r--r--ufund-ui/src/app/components/cupboard/cupboard.component.html6
-rw-r--r--ufund-ui/src/app/components/cupboard/cupboard.component.ts14
2 files changed, 16 insertions, 4 deletions
diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html
index c055c31..71c258e 100644
--- a/ufund-ui/src/app/components/cupboard/cupboard.component.html
+++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html
@@ -18,7 +18,7 @@
{{SortingAlgorithms[algorithm].display[sortMode === 'Ascending' ? 0 : 1]}}
</option>
</select>
- <button (click)="toggleSortMode(searchForm.value)">
+ <button (click)="toggleSortMode(searchForm.value)" [title]="sortMode">
<span class="icon">{{sortMode === 'Ascending' ? 'arrow_upward': 'arrow_downward'}}</span>
</button>
<label>Needs per page: </label>
@@ -30,8 +30,8 @@
<h2 *ngIf="searchResults.length == 0"> No Results Found </h2>
<ng-template let-need #NLActions>
- <button *ngIf="isHelper()" (click)="addToBasket(need)">
- <span class="icon">add</span>Add To Basket
+ <button *ngIf="isHelper()" (click)="addToBasket(need)" [disabled]="inBasket(usersService.getBasket() | async, need)">
+ <span class="icon">{{inBasket(usersService.getBasket() | async, need)? "check": "add" }}</span>Add To Basket
</button>
<button *ngIf="isManager()" (click)="select(need)">
<span class="icon">edit</span>Edit Need
diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts
index a4f8db2..bde8e27 100644
--- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts
+++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts
@@ -8,6 +8,7 @@ import {AuthService} from '../../services/auth.service';
import {ToastsService, ToastType} from '../../services/toasts.service';
import {UsersService} from '../../services/users.service';
import {SortingAlgoArrays} from './sorting';
+import {Router} from '@angular/router';
@Component({
selector: 'app-cupboard',
@@ -33,7 +34,8 @@ export class CupboardComponent implements OnInit {
private cupboardService: CupboardService,
private authService: AuthService,
private toastService: ToastsService,
- private usersService: UsersService
+ protected usersService: UsersService,
+ private router: Router
) {}
ngOnInit(): void {
@@ -42,6 +44,8 @@ export class CupboardComponent implements OnInit {
// this.refresh()
this.search(null)
});
+ this.authService.getCurrentUserSubject().subscribe(
+ () => this.usersService.refreshBasket())
}
refresh() {
@@ -121,6 +125,8 @@ export class CupboardComponent implements OnInit {
return of();
}))
.subscribe(() => {
+ let action = {label: "View Basket", onAction: () => this.router.navigate(['/basket'])}
+ this.toastService.sendToast(ToastType.INFO, `"${need.name}" Added to basket`, action)
this.usersService.refreshBasket();
});
} else {
@@ -137,6 +143,12 @@ export class CupboardComponent implements OnInit {
return this.authService.getCurrentUser()?.type === userType.HELPER
}
+ inBasket(basket: Need[] | null, need: Need) {
+ console.log(basket)
+ console.log(need)
+ return basket?.map(r => r.id).includes(need.id);
+ }
+
// --------------- FORM STUFF NOT IMPLEMENTED YET --------------- //
// async updateSearchResults() {