aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2025-03-17 23:34:04 -0400
committersowgro <tpoke.ferrari@gmail.com>2025-03-17 23:34:04 -0400
commit1dd36e3643f646443555554d6de024653373fc8f (patch)
treebcff5bba5f9ba772dd4adf2ade0684bedb7f03a6
parent3c652360b44ac39fecd5b2fd9469018307a42b27 (diff)
downloadJellySolutions-1dd36e3643f646443555554d6de024653373fc8f.tar.gz
JellySolutions-1dd36e3643f646443555554d6de024653373fc8f.tar.bz2
JellySolutions-1dd36e3643f646443555554d6de024653373fc8f.zip
fix errors in funding basket
-rw-r--r--ufund-ui/src/app/components/funding-basket/funding-basket.component.ts132
1 files changed, 65 insertions, 67 deletions
diff --git a/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts b/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
index 31f2982..c65e25f 100644
--- a/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
+++ b/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
@@ -1,86 +1,84 @@
-import { Component, OnInit } from '@angular/core';
+import {Component, OnInit} from '@angular/core';
import {User} from '../../models/User';
-import { UsersService } from '../../services/users.service';
-import { Need } from '../../models/Need';
-import { NeedListComponent } from '../need-list/need-list.component';
-import { Router } from '@angular/router';
+import {UsersService} from '../../services/users.service';
+import {Need} from '../../models/Need';
+import {NeedListComponent} from '../need-list/need-list.component';
+import {Router} from '@angular/router';
@Component({
- selector: 'app-funding-basket',
- standalone: false,
- templateUrl: './funding-basket.component.html',
- styleUrl: './funding-basket.component.css'
+ selector: 'app-funding-basket',
+ standalone: false,
+ templateUrl: './funding-basket.component.html',
+ styleUrl: './funding-basket.component.css'
})
-export class FundingBasketComponent implements
- OnInit {
- user!: User;
- basket: Need[] = [];
- needCount = 0;
- need_quantity: {[key: number]: number} = {};
+export class FundingBasketComponent implements OnInit {
+ user: User | null | undefined;
+ basket: Need[] = [];
+ needCount = 0;
+ need_quantity: { [key: number]: number } = {};
- constructor(
- private router: Router,
- private usersService: UsersService
- ) {}
-
- ngOnInit(): void {
- if (!this.usersService.getCurrentUser()) {
- this.router.navigate(['/login'], {queryParams: {redir: this.router.url}});
- return;
+ constructor(
+ private router: Router,
+ private usersService: UsersService
+ ) {
}
- this.usersService.getCurrentUser()?.subscribe(user => {
- this.user = user;
- this.getBasketNeeds();
- });
- }
- getBasketNeeds(): void {
- if (this.user && this.user.cupboard) {
- this.user.cupboard.forEach(need => {
- if (this.isInBasket(need)){
- this.basket.push(need);
+ ngOnInit(): void {
+ if (!this.usersService.getCurrentUser()) {
+ this.router.navigate(['/login'], {queryParams: {redir: this.router.url}});
+ return;
}
- });
+ this.user = this.usersService.getCurrentUser()
}
- }
- isInBasket(need: Need): boolean {
- return this.basket.some(n => n.id == need.id);
- }
+ getBasketNeeds(): void {
+ if (this.user && this.user.basket) {
+ this.user.basket.forEach(need => {
+ if (this.isInBasket(need)) {
+ this.basket.push(need);
+ }
+ });
+ }
+ }
- addNeed(need: Need, quantity: number=1): void {
- if (this.user && !this.isInBasket(need)) {
- this.basket.push(need);
- this.need_quantity[need.id] = quantity;
- } if (this.isInBasket(need)) {
- this.need_quantity[need.id] += quantity;
+ isInBasket(need: Need): boolean {
+ return this.basket.some(n => n.id == need.id);
}
- this.needCount++;
+
+ addNeed(need: Need, quantity: number = 1): void {
+ if (this.user && !this.isInBasket(need)) {
+ this.basket.push(need);
+ this.need_quantity[need.id] = quantity;
+ }
+ if (this.isInBasket(need)) {
+ this.need_quantity[need.id] += quantity;
+ }
+ this.needCount++;
}
- removeNeed(need: Need, quantity:number=1): void {
- if (this.user && this.isInBasket(need)) {
- this.need_quantity[need.id] -= quantity;
- if (this.need_quantity[need.id] === 0) {
- this.basket = this.basket.filter(n => need.id !== n.id);
- }
- this.needCount--;
+ removeNeed(need: Need, quantity: number = 1): void {
+ if (this.user && this.isInBasket(need)) {
+ this.need_quantity[need.id] -= quantity;
+ if (this.need_quantity[need.id] === 0) {
+ this.basket = this.basket.filter(n => need.id !== n.id);
+ }
+ this.needCount--;
+ }
}
- }
- removeAllNeeds(): void {
- this.basket.forEach(need => {
- this.need_quantity = [];
- });
- this.basket = [];
- this.needCount = 0;
- }
+ removeAllNeeds(): void {
+ this.basket.forEach(need => {
+ this.need_quantity = [];
+ });
+ this.basket = [];
+ this.needCount = 0;
+ }
- isBasketEmpty(): boolean {
- return this.needCount === 0;
- }
+ isBasketEmpty(): boolean {
+ return this.needCount === 0;
+ }
- checkout(): void {
- this.removeAllNeeds();
- }
+ checkout(): void {
+ this.removeAllNeeds();
+ }
}