aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbenal01 <bja4245@rit.edu>2025-03-17 23:46:03 -0400
committerbenal01 <bja4245@rit.edu>2025-03-17 23:46:03 -0400
commit5563fa8e1b4a8df9dc05cdb48405c3de634fdd81 (patch)
tree1884a659869b816a5762827d52632843cf97332e
parent361f73f967475089e995b62079316bd91232570e (diff)
parent1dd36e3643f646443555554d6de024653373fc8f (diff)
downloadJellySolutions-5563fa8e1b4a8df9dc05cdb48405c3de634fdd81.tar.gz
JellySolutions-5563fa8e1b4a8df9dc05cdb48405c3de634fdd81.tar.bz2
JellySolutions-5563fa8e1b4a8df9dc05cdb48405c3de634fdd81.zip
needs called onInit
-rw-r--r--ufund-ui/src/app/components/funding-basket/funding-basket.component.ts93
1 files changed, 55 insertions, 38 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 418158f..a6ee8fc 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,16 +1,23 @@
-import { Component, OnInit } from '@angular/core';
+import {Component, OnInit} from '@angular/core';
import {User} from '../../models/User';
+<<<<<<< HEAD
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 { CupboardService } from '../../services/cupboard.service';
+=======
+import {UsersService} from '../../services/users.service';
+import {Need} from '../../models/Need';
+import {NeedListComponent} from '../need-list/need-list.component';
+import {Router} from '@angular/router';
+>>>>>>> 1dd36e3643f646443555554d6de024653373fc8f
@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 {
@@ -44,47 +51,57 @@ export class FundingBasketComponent implements
if (this.isInBasket(need)){
this.basket.push(need);
}
- });
+ 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();
+ }
}