From 0b41684e57c79374aee3a564307cd4fdef603e7c Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Tue, 18 Mar 2025 11:41:04 -0400 Subject: THE UPDATE USER WORKS! -ak --- .../src/app/components/need-list/need-list.component.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 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 e1c0de1..46e09f0 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 @@ -105,15 +105,14 @@ export class NeedListComponent { return type === ("HELPER" as unknown as userType); } - add(need: number) { + add(need: Need) { const currentUser = this.usersService.getCurrentUser(); + console.log("get current user in angular:", currentUser) if (currentUser) { - this.usersService.updateUser(currentUser.username, currentUser).subscribe(() => { - const currentUser = this.usersService.getCurrentUser(); - if (currentUser && currentUser.basket) { - currentUser.basket.push(need); - console.log("added to basket"); - } + currentUser.basket.push(need.id); + console.log("pushed to basket: " + currentUser.basket) + this.usersService.updateUser(currentUser).subscribe(() => { + console.log("rah"); error: (err: any) => { console.error(err); } -- cgit v1.2.3 From 98431cd75078fd671270039ad9fa4d42759dc502 Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Tue, 18 Mar 2025 12:42:37 -0400 Subject: reworked funding basket to accept need-list component. -ak --- ufund-ui/src/app/components/need-list/need-list.component.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 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 46e09f0..2764c7e 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 @@ -107,12 +107,12 @@ export class NeedListComponent { add(need: Need) { const currentUser = this.usersService.getCurrentUser(); - console.log("get current user in angular:", currentUser) + //console.log("get current user in angular:", currentUser) if (currentUser) { currentUser.basket.push(need.id); - console.log("pushed to basket: " + currentUser.basket) + //console.log("pushed to basket: " + currentUser.basket) this.usersService.updateUser(currentUser).subscribe(() => { - console.log("rah"); + this.usersService.refreshBasket(); error: (err: any) => { console.error(err); } -- cgit v1.2.3 From 054857f51d1397d1122219e407a25c18472733f6 Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Tue, 18 Mar 2025 14:32:56 -0400 Subject: add alert on duplicate entry --- .../app/components/need-list/need-list.component.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 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 2764c7e..25f05d6 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 @@ -109,14 +109,18 @@ export class NeedListComponent { const currentUser = this.usersService.getCurrentUser(); //console.log("get current user in angular:", currentUser) if (currentUser) { - currentUser.basket.push(need.id); - //console.log("pushed to basket: " + currentUser.basket) - this.usersService.updateUser(currentUser).subscribe(() => { - this.usersService.refreshBasket(); - error: (err: any) => { - console.error(err); - } - }); + if (!currentUser.basket.includes(need.id)) { + currentUser.basket.push(need.id); + this.usersService.updateUser(currentUser).subscribe(() => { + this.usersService.refreshBasket(); + error: (err: any) => { + console.error(err); + } + }); + } else { + window.alert("This need is already in your basket!") + } + } -- cgit v1.2.3