diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 00f274b..3a894f4 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -112,7 +112,8 @@ export class AppComponent { 'forgot', 'feedback', 'wishlist', - 'preference' + 'preference', + 'changedetails' ]; const currentUrl = this.router.url.split('/'); const index = restrictedUrl.findIndex(x => x === currentUrl[1]); diff --git a/src/app/cart/cart.page.ts b/src/app/cart/cart.page.ts index 31659ea..66ae9d3 100644 --- a/src/app/cart/cart.page.ts +++ b/src/app/cart/cart.page.ts @@ -1,29 +1,29 @@ -import { Component, OnInit, ViewChild } from "@angular/core"; -import { IonSlides } from "@ionic/angular"; -import { Location } from "@angular/common"; -import { Router, ActivatedRoute } from "@angular/router"; -import { CartsService } from "./../../config/cart.service"; -import { OrdersService } from "./../../config/order.service"; -import { ModalController } from "@ionic/angular"; -import { DeliverypopPage } from "../deliverypop/deliverypop.page"; -import { ServiceService } from "./../../config/service.service"; -import { AddressService } from "./../../config/address.service"; -import { AddressList } from "./../../config/services/address"; -import { trigger, transition, animate, style } from "@angular/animations"; -import { zip } from "rxjs"; +import { Component, OnInit, ViewChild } from '@angular/core'; +import { IonSlides } from '@ionic/angular'; +import { Location } from '@angular/common'; +import { Router, ActivatedRoute } from '@angular/router'; +import { CartsService } from './../../config/cart.service'; +import { OrdersService } from './../../config/order.service'; +import { ModalController } from '@ionic/angular'; +import { DeliverypopPage } from '../deliverypop/deliverypop.page'; +import { ServiceService } from './../../config/service.service'; +import { AddressService } from './../../config/address.service'; +import { AddressList } from './../../config/services/address'; +import { trigger, transition, animate, style } from '@angular/animations'; +import { zip } from 'rxjs'; @Component({ - selector: "app-cart", - templateUrl: "./cart.page.html", - styleUrls: ["./cart.page.scss"], + selector: 'app-cart', + templateUrl: './cart.page.html', + styleUrls: ['./cart.page.scss'], animations: [ - trigger("slideInOut", [ - transition(":enter", [ - style({ transform: "translateY(100%)" }), - animate("200ms ease-in", style({ transform: "translateY(0%)" })) + trigger('slideInOut', [ + transition(':enter', [ + style({ transform: 'translateY(100%)' }), + animate('200ms ease-in', style({ transform: 'translateY(0%)' })) ]), - transition(":leave", [ - animate("200ms ease-out", style({ transform: "translateY(100%)" })) + transition(':leave', [ + animate('200ms ease-out', style({ transform: 'translateY(100%)' })) ]) ]) ] @@ -50,7 +50,6 @@ export class CartPage implements OnInit { totalAmt: number; bookDate: any; timeinterval: any; - deliveryTime: any; constructor( private router: Router, @@ -62,7 +61,7 @@ export class CartPage implements OnInit { public service: ServiceService, public addressService: AddressService ) { - console.log("cart loaded"); + console.log('cart loaded'); this.bookDate = this.formatDate(); this.currentIndex = 0; this.count = 1; @@ -73,7 +72,7 @@ export class CartPage implements OnInit { this.discount = 0; // this.cartService.cartList(); this.loader = true; - const users = this.service.get("user").then(data => { + const users = this.service.get('user').then(data => { if (data) { data = JSON.parse(data); this.custId = data.uid; @@ -91,7 +90,7 @@ export class CartPage implements OnInit { } ionViewWillEnter() { - const users = this.service.get("user").then(data => { + const users = this.service.get('user').then(data => { if (data) { data = JSON.parse(data); this.cartService.cartList(); @@ -183,7 +182,7 @@ export class CartPage implements OnInit { const state = this.orderService .checkOut(this.cartService.carts, otherCharges) .then(data => { - console.log("ready for slide"); + console.log('ready for slide'); const timeStamp = Math.floor(Date.now() / 1000); this.timeinterval = setInterval(() => { This.getDeliveryTime(timeStamp); @@ -191,7 +190,7 @@ export class CartPage implements OnInit { this.slides.slideNext(); }); } else { - alert("Please choose delivery location"); + alert('Please choose delivery location'); } } else { this.slides.slideNext(); @@ -204,9 +203,9 @@ export class CartPage implements OnInit { console.log(endDate); endDate.setHours(endDate.getHours() + 1); const t = this.getTimeRemaining(endDate, new Date()); - const minutes = t.minutes < 10 ? "0" + t.minutes : t.minutes; - const seconds = t.seconds < 10 ? "0" + t.seconds : t.seconds; - this.deliveryTime = minutes + " : " + seconds; + const minutes = t.minutes < 10 ? '0' + t.minutes : t.minutes; + const seconds = t.seconds < 10 ? '0' + t.seconds : t.seconds; + this.deliveryTime = minutes + ' : ' + seconds; if (t.t <= 0) { clearInterval(this.timeinterval); } @@ -286,33 +285,33 @@ export class CartPage implements OnInit { formatDate() { const date = new Date(); const months = [ - "Jan", - "Feb", - "Mar", - "Apr", - "May", - "June", - "July", - "Aug", - "Sep", - "Oct", - "Nov", - "Dec" + 'Jan', + 'Feb', + 'Mar', + 'Apr', + 'May', + 'June', + 'July', + 'Aug', + 'Sep', + 'Oct', + 'Nov', + 'Dec' ]; let hours = date.getHours(); const minutes = date.getMinutes(); - const ampm = hours >= 12 ? "PM" : "AM"; + const ampm = hours >= 12 ? 'PM' : 'AM'; hours = hours % 12; hours = hours ? hours : 12; // the hour '0' should be '12' - const newminutes = minutes < 10 ? "0" + minutes : minutes; - const strTime = hours + ":" + newminutes + " " + ampm; + const newminutes = minutes < 10 ? '0' + minutes : minutes; + const strTime = hours + ':' + newminutes + ' ' + ampm; return ( months[date.getMonth()] + - " " + + ' ' + date.getDate() + - "," + + ',' + date.getFullYear() + - " " + + ' ' + strTime ); } diff --git a/src/app/changedetails/changedetails.page.html b/src/app/changedetails/changedetails.page.html index 0b080f9..c371058 100644 --- a/src/app/changedetails/changedetails.page.html +++ b/src/app/changedetails/changedetails.page.html @@ -26,7 +26,7 @@ /> <div class="md-errors-spacer" - [hidden]="name.valid || submitted == false" + [hidden]="name.valid" class="ion-padding-start" > Name is required @@ -56,10 +56,7 @@ placeholder="Change your Phone Number" #phone="ngModel" /> - <div - class="md-errors-spacer" - [hidden]="phone.valid || submitted == false" - > + <div class="md-errors-spacer" [hidden]="phone.valid"> <div *ngIf="phone.errors && phone.errors.required"> Phone number is required </div> @@ -113,14 +110,20 @@ [required]="currentPassword ? true: false" placeholder="Confirm Password" /> - <div *ngIf="confirmPassword.errors"> - {{confPasswordErr}} + <div + *ngIf="confirmPassword.value !=='' && confirmPassword.value !== password.value" + > + Password should match </div> </div> </div> <div class="row"> - <button class="login_btn" (click)="onFormSubmit(updateForm)"> + <button + class="login_btn" + (click)="onFormSubmit(updateForm)" + [disabled]="!phone.valid || !name.valid" + > UPDATE </button> </div> diff --git a/src/app/changedetails/changedetails.page.ts b/src/app/changedetails/changedetails.page.ts index e65439a..390af0c 100644 --- a/src/app/changedetails/changedetails.page.ts +++ b/src/app/changedetails/changedetails.page.ts @@ -61,30 +61,20 @@ export class ChangedetailsPage implements OnInit { onFormSubmit(form: NgForm) { this.submitted = true; console.log(form.value); - if (form.valid) { - // Change Password - if (form.value.currentPassword && form.value.password) { - if ( - form.value.password && - form.value.password === form.value.confirmPassword - ) { - // this.register.updateData(form.value, this.userData.uid); - this.register.updatePassword( - form.value.currentPassword, - form.value.password - ); - console.log('Password Changed and profile updated'), form.value; - } else { - console.log('Password should match'); - this.confPasswordErr = 'Password should match'; - } - } else { - // this.register.updateData(form.value, this.userData); - console.log('profile updated', form.value); - } - // console.log('valid form values', form.value); + // if (form.valid) { + // Change Password + if ( + form.value.currentPassword && + form.value.password && form.value.password === form.value.confirmPassword + ) { + this.register.updateData(form.value, this.userData.uid); + this.register.updatePassword( + form.value.currentPassword, + form.value.password + ); } else { - console.log(form); + this.register.updateData(form.value, this.userData); + console.log('profile updated', form.value); } } } diff --git a/src/app/myorder/myorder.page.html b/src/app/myorder/myorder.page.html index 8b17cd7..997d2d6 100644 --- a/src/app/myorder/myorder.page.html +++ b/src/app/myorder/myorder.page.html @@ -109,6 +109,11 @@ <div class="clear"></div> </li> --> </ul> + <div class="empty-wishlist-wrapper" *ngIf="myorder.orders.length == 0"> + <img src="../../assets/wishlist.png" /> + <h1>There is no order</h1> + <button (click)="goToPage('home')">shop now</button> + </div> </div> </ion-content> <div class="loader" *ngIf="loader"> diff --git a/src/app/myorder/myorder.page.scss b/src/app/myorder/myorder.page.scss index 6ba1319..1e73595 100644 --- a/src/app/myorder/myorder.page.scss +++ b/src/app/myorder/myorder.page.scss @@ -1,112 +1,137 @@ .myorder_wrapper { - ul { - margin: 0px; - padding: 10px; - li { - list-style: none; - padding: 10px; - padding-bottom: 15px; - .order_info { - padding-top: 10px; - padding-bottom: 10px; - h5 { - margin: 0px; - padding: 0px; - } - .order_track { - background-color: rgba(53, 203, 171, 1); - color: #fff; - border-radius: 3px; - padding: 3px; - padding-left: 10px; - padding-right: 10px; - } - } - .order_image { - width: 90px; - height: 90px; - float: left; - border-radius: 8px; - background-color: #a8a8a8; - img { - width: 100%; - height: 100%; - object-fit: cover; - object-position: center; - } - } - .order_detail { - width: calc(100% - 190px); - float: left; - padding-left: 20px; - h5 { - margin: 0px; - padding: 0px; - color: rgba(176, 174, 199, 1); - font-size: 16px; - padding-top: 3px; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; - width: 100%; - span { - color: #29285b; - } - } - h6 { - margin: 0px; - padding: 0px; - color: rgba(176, 174, 199, 1); - font-size: 12px; - padding-top: 9px; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; - } - p { - margin: 0px; - padding: 0px; - color: rgba(59, 57, 77, 1); - font-weight: 900; - padding-top: 10px; - font-size: 20px; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; - } - } - .order_other { - width: 100px; - float: right; - h6 { - margin: 0px; - padding: 0px; - color: rgba(176, 174, 199, 1); - font-size: 12px; - padding-top: 9px; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; - padding-bottom: 10px; - } - h5 { - margin: 0px; - padding: 0px; - color: rgba(206, 153, 76, 1); - font-size: 16px; - font-weight: bold; - } - .track_btn { - background: #29285b; - color: #FFF; - float: right; - padding: 12px; - font-size: 18px; - border-radius: 5px; - padding-left: 15px; - padding-right: 15px; - } - } + ul { + margin: 0px; + padding: 10px; + li { + list-style: none; + padding: 10px; + padding-bottom: 15px; + .order_info { + padding-top: 10px; + padding-bottom: 10px; + h5 { + margin: 0px; + padding: 0px; } + .order_track { + background-color: rgba(53, 203, 171, 1); + color: #fff; + border-radius: 3px; + padding: 3px; + padding-left: 10px; + padding-right: 10px; + } + } + .order_image { + width: 90px; + height: 90px; + float: left; + border-radius: 8px; + background-color: #a8a8a8; + img { + width: 100%; + height: 100%; + object-fit: cover; + object-position: center; + } + } + .order_detail { + width: calc(100% - 190px); + float: left; + padding-left: 20px; + h5 { + margin: 0px; + padding: 0px; + color: rgba(176, 174, 199, 1); + font-size: 16px; + padding-top: 3px; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + width: 100%; + span { + color: #29285b; + } + } + h6 { + margin: 0px; + padding: 0px; + color: rgba(176, 174, 199, 1); + font-size: 12px; + padding-top: 9px; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } + p { + margin: 0px; + padding: 0px; + color: rgba(59, 57, 77, 1); + font-weight: 900; + padding-top: 10px; + font-size: 20px; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } + } + .order_other { + width: 100px; + float: right; + h6 { + margin: 0px; + padding: 0px; + color: rgba(176, 174, 199, 1); + font-size: 12px; + padding-top: 9px; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + padding-bottom: 10px; + } + h5 { + margin: 0px; + padding: 0px; + color: rgba(206, 153, 76, 1); + font-size: 16px; + font-weight: bold; + } + .track_btn { + background: #29285b; + color: #fff; + float: right; + padding: 12px; + font-size: 18px; + border-radius: 5px; + padding-left: 15px; + padding-right: 15px; + } + } + } + } + + .empty-wishlist-wrapper { + text-align: center; + padding-top: 25%; + img { + width: 100px; + } + h1 { + font-size: 18px; + font-weight: bolder; + text-transform: uppercase; + color: #3b394d; + } + button { + background-color: #29285b; + border-radius: 8px; + height: 50px; + width: 48%; + color: #fff; + font-size: 18px; + font-weight: lighter; + text-transform: uppercase; + margin-top: 10px; } -} \ No newline at end of file + } +} diff --git a/src/app/nearby/nearby.page.ts b/src/app/nearby/nearby.page.ts index bcf9d8f..4c9dd48 100644 --- a/src/app/nearby/nearby.page.ts +++ b/src/app/nearby/nearby.page.ts @@ -134,8 +134,7 @@ export class NearbyPage implements OnInit { this.loader = false; this.successState = false; if (this.type === 1) { - this.service.set('type', 0); - this.router.navigateByUrl('home', { queryParams: null }); + this.router.navigateByUrl('preference', { queryParams: null }); } else { this.goBack(); } diff --git a/src/app/preference/preference.page.html b/src/app/preference/preference.page.html index 687e718..d722b59 100644 --- a/src/app/preference/preference.page.html +++ b/src/app/preference/preference.page.html @@ -1,33 +1,52 @@ <div class="nav_header"> - <button class="nav_btn nav_back floatLeft" (click)="goBack()"> - <img src="../assets/Group17_2.png" /> - </button> - <div class="nav_title floatLeft"> - <h4>Preference</h4> - </div> - <div class="clear"></div> + <button class="nav_btn nav_back floatLeft" (click)="goBack()" *ngIf="type==0"> + <img src="../assets/Group17_2.png" /> + </button> + <div class="nav_title floatLeft"> + <h4>Preferences</h4> + </div> + <div class="clear"></div> </div> <ion-content> - <div class="preference-wrapper"> - <div class="pref-wrap-two"> - <ion-grid> - <ion-row *ngIf="categoriesService.activecategories && categoriesService.activecategories.length > 0"> - <ion-col size="6" *ngFor="let categories of categoriesService.activecategories"> - <div class="preference-box"> - <input type="checkbox" class="preference" /> - <img [src]="categories.catImage" onerror="this.src='../assets/handsome-man-outdoors-drinking-coffee-with-sunglasses-guy-with-beard-instagram-effect_1212-818@3x.png'"> - <h1>{{categories.catName}}</h1> - </div> - </ion-col> - </ion-row> - </ion-grid> - </div> - <div class="bottom-button"> - <button class="show-btn" (click)="goToPage('nearby')"> - Continue - </button> - <span>SKIP</span> - </div> + <div class="preference-wrapper"> + <div class="pref-wrap-two"> + <ion-grid> + <ion-row + *ngIf="categoriesService.activecategories && categoriesService.activecategories.length > 0" + > + <ion-col + size="6" + *ngFor="let categories of categoriesService.categories" + > + <div class="preference-box"> + <input + type="checkbox" + class="preference" + (click)="selectPrefernce(categories.catId)" + [checked]="selectedPref(categories.catId)" + /> + <img + [src]="categories.catImage" + onerror="this.src='../assets/handsome-man-outdoors-drinking-coffee-with-sunglasses-guy-with-beard-instagram-effect_1212-818@3x.png'" + /> + <h1>{{categories.catName}}</h1> + </div> + </ion-col> + </ion-row> + </ion-grid> + </div> + <div class="bottom-button"> + <button class="show-btn" (click)="onSubmit()"> + Continue + </button> + <!-- <span>SKIP</span> --> </div> -</ion-content> \ No newline at end of file + </div> +</ion-content> +<div class="loader" *ngIf="loader"> + <div class="lds-ripple"> + <div></div> + <div></div> + </div> +</div> diff --git a/src/app/preference/preference.page.ts b/src/app/preference/preference.page.ts index bfdc5c9..daa96c6 100644 --- a/src/app/preference/preference.page.ts +++ b/src/app/preference/preference.page.ts @@ -1,17 +1,97 @@ -import { Component, OnInit } from "@angular/core"; -import { CategoriesService } from "./../../config/category.service"; -import { ServiceService } from "./../../config/service.service"; +import { Component, OnInit } from '@angular/core'; +import { CategoriesService } from './../../config/category.service'; +import { ServiceService } from './../../config/service.service'; +import { Router, ActivatedRoute } from '@angular/router'; @Component({ - selector: "app-preference", - templateUrl: "./preference.page.html", - styleUrls: ["./preference.page.scss"] + selector: 'app-preference', + templateUrl: './preference.page.html', + styleUrls: ['./preference.page.scss'] }) export class PreferencePage implements OnInit { + type: any; + successState: boolean; + uid: any; + userPrefence: any[]; + loader: boolean; + constructor( private categoriesService: CategoriesService, - private service: ServiceService - ) {} + private service: ServiceService, + private router: Router + ) { + this.successState = false; + this.userPrefence = []; + this.type = 0; + const users = this.service.get('user').then(data => { + if (data) { + data = JSON.parse(data); + this.uid = data.uid; + this.categoriesService + .preference(this.uid) + .then(datas => { + console.log(datas); + console.log(this.categoriesService.preferenceList); + this.userPrefence = this.categoriesService.preferenceList; + console.log(this.userPrefence); + }) + .catch(err => { + this.userPrefence = []; + }); + } + }); + + this.service.get('type').then(data => { + this.type = data; + }); + } ngOnInit() {} + + selectPrefernce(preferenceId) { + console.log(this.userPrefence); + console.log(preferenceId); + if (this.userPrefence) { + const index = this.userPrefence.findIndex(x => x === preferenceId); + if (index > -1) { + this.userPrefence.splice(index, 1); + } else { + this.userPrefence.push(preferenceId); + } + } else { + this.userPrefence = []; + this.userPrefence.push(preferenceId); + } + } + + onSubmit() { + this.loader = true; + console.log(this.userPrefence); + this.categoriesService.preferenceCreate(this.userPrefence, this.uid); + this.successState = true; + setTimeout(() => { + this.loader = false; + this.successState = false; + if (this.type === 1) { + this.service.set('type', 0); + this.router.navigateByUrl('home', { queryParams: null }); + } else { + this.goBack(); + } + }, 3000); + } + + selectedPref(preferenceId) { + const index = this.userPrefence.findIndex(x => x === preferenceId); + console.log(index); + if (index > -1) { + return true; + } else { + return false; + } + } + + goBack() { + window.history.back(); + } } diff --git a/src/app/productlist/productlist.page.ts b/src/app/productlist/productlist.page.ts index 365fcce..5c222c5 100644 --- a/src/app/productlist/productlist.page.ts +++ b/src/app/productlist/productlist.page.ts @@ -66,6 +66,7 @@ export class ProductlistPage implements OnInit { ngOnInit() {} ionViewWillEnter() { + console.log('logged'); const users = this.service.get('user').then(data => { if (data) { data = JSON.parse(data); diff --git a/src/app/profile/profile.page.html b/src/app/profile/profile.page.html index b2dc381..5165fbb 100644 --- a/src/app/profile/profile.page.html +++ b/src/app/profile/profile.page.html @@ -18,7 +18,7 @@ <div class="profile_circle"> <img [src]="loggedUser.profilePhoto" - onerror="this.src='./../../assets/profile_banner.png'" + onerror="this.src='./../assets/asset_avatar.png'" /> <div class="edit"></div> <input type="file" accept="image/*" (change)="fileChange($event)" /> @@ -118,6 +118,17 @@ </ion-col> </ion-row> <hr /> + <ion-row (click)="goToPage('preference')"> + <ion-col class="textLeft p0"> + <p>Preferences</p> + </ion-col> + <ion-col class="textRight p0"> + <h6> + <ion-icon name="arrow-forward"></ion-icon> + </h6> + </ion-col> + </ion-row> + <hr /> <ion-row> <ion-col class="textLeft p0"> <p>Currency</p> @@ -150,3 +161,9 @@ </div> </div> </ion-content> +<div class="loader" *ngIf="loader"> + <div class="lds-ripple"> + <div></div> + <div></div> + </div> +</div> diff --git a/src/app/profile/profile.page.ts b/src/app/profile/profile.page.ts index 0c48b1a..8c2551a 100644 --- a/src/app/profile/profile.page.ts +++ b/src/app/profile/profile.page.ts @@ -3,6 +3,7 @@ import { User } from '../../config/services/user'; import { UserService } from '../../config/user.service'; import { ServiceService } from '../../config/service.service'; import { AuthService } from '../../config/auth.service'; +import { SubjectService } from './../../config/subject.service'; import { Router, ActivatedRoute } from '@angular/router'; import { finalize, tap } from 'rxjs/operators'; import { Location } from '@angular/common'; @@ -40,6 +41,7 @@ export class ProfilePage implements OnInit { loggedUser: any; ref: AngularFireStorageReference; downloadURL; + loader: boolean; constructor( private route: ActivatedRoute, @@ -50,8 +52,10 @@ export class ProfilePage implements OnInit { private authService: AuthService, private addressService: AddressService, private wishService: WishService, - private location: Location + private location: Location, + private subject: SubjectService ) { + this.loader = false; this.service.get('user').then(data => { if (data) { this.userData = JSON.parse(data); @@ -95,6 +99,7 @@ export class ProfilePage implements OnInit { } async fileChange(event) { + this.loader = true; const fileList: FileList = event.target.files; if (fileList.length > 0) { const reader = new FileReader(); @@ -119,7 +124,14 @@ export class ProfilePage implements OnInit { .pipe( finalize(() => { ref.getDownloadURL().subscribe(url => { + this.loader = false; this.authService.profilePic(url); + this.service.get('userData').then(userData => { + const userDatas = JSON.parse(userData); + userDatas.profilePhoto = url; + this.service.set('userData', JSON.stringify(userDatas)); + this.subject.sendUserData(JSON.stringify(userDatas)); + }); }); }) ) diff --git a/src/config/category.service.ts b/src/config/category.service.ts index 46b4ca7..4330866 100644 --- a/src/config/category.service.ts +++ b/src/config/category.service.ts @@ -14,7 +14,9 @@ import { ServiceService } from './service.service'; export class CategoriesService { categories: Category[] = []; activecategories: Category[] = []; + preferenceList: any[]; constructor(public afs: AngularFirestore, public service: ServiceService) { + this.preferenceList = []; this.categoryList(); this.activeCategory(); } @@ -74,4 +76,52 @@ export class CategoriesService { } }); } + + public async preference(custId) { + const This = this; + const state = true; + const promise = new Promise(resolve => { + const orderRef: AngularFirestoreDocument<any> = this.afs + .collection('preference') + .doc(custId); + orderRef.valueChanges().subscribe(value => { + console.log(value); + this.preferenceList = []; + if (value) { + console.log(value); + // tslint:disable-next-line: forin + for (const index in value) { + console.log(index); + this.preferenceList.push(index); + resolve(this.preferenceList); + } + resolve(); + // console.log(this.activecategories); + } else { + this.preferenceList = []; + resolve([]); + } + }); + }); + return promise; + } + + preferenceCreate(preferData, custId) { + if (preferData.length > 0) { + const preferArray = []; + preferData.forEach(element => { + preferArray[element] = true; + }); + const pref = Object.assign({}, preferArray); + this.afs + .collection('preference') + .doc(custId) + .set(pref); + } else { + this.afs + .collection('preference') + .doc(custId) + .delete(); + } + } } diff --git a/src/config/products.service.ts b/src/config/products.service.ts index 7f76dd4..d8f365f 100644 --- a/src/config/products.service.ts +++ b/src/config/products.service.ts @@ -235,6 +235,7 @@ export class ProductsService { } public async getFavlist(userId: string) { + console.log(userId); const favRef: AngularFirestoreDocument<any> = this.afs .collection(`favourite`) .doc(userId); @@ -247,9 +248,11 @@ export class ProductsService { if (value !== undefined) { if (Object.keys(value).length > 0) { this.fav = this.service.splitSep(value); - // console.log(this.fav); + console.log(this.fav); } // console.log(value); + } else { + this.fav = []; } }); } diff --git a/src/config/update.service.ts b/src/config/update.service.ts index 4bf34a0..f217f13 100644 --- a/src/config/update.service.ts +++ b/src/config/update.service.ts @@ -9,6 +9,7 @@ import { AngularFirestoreCollection } from '@angular/fire/firestore'; import { ServiceService } from './../config/service.service'; +import { SubjectService } from './../config/subject.service'; import { GooglePlus } from '@ionic-native/google-plus/ngx'; import { take } from 'rxjs/operators'; import { from } from 'rxjs'; @@ -27,7 +28,8 @@ export class UpdateService { public afs: AngularFirestore, public afAuth: AngularFireAuth, private router: Router, - private service: ServiceService + private service: ServiceService, + private subject: SubjectService ) { // this.type = 1; // this.afAuth.authState.subscribe(user => { @@ -72,10 +74,11 @@ export class UpdateService { this.service .set('userData', JSON.stringify(updateOldData)) .then(res => { + this.subject.sendUserData(JSON.stringify()); console.log('success', updateOldData, res); this.service .showToast('Profile updated!', 'top', 'my-toast', 1000) - .then(res => { + .then(() => { this.router.navigateByUrl('profile'); this.loader = false; }); @@ -91,7 +94,7 @@ export class UpdateService { updatePassword(currentPassword: string, newPasswd: string) { this.loader = true; - let currentUser = this.afAuth.auth.currentUser; // Gets current user + const currentUser = this.afAuth.auth.currentUser; // Gets current user // Credential is required for re-authentication const credential = auth.EmailAuthProvider.credential( currentUser.email, @@ -108,7 +111,7 @@ export class UpdateService { console.log('password changed'); this.loader = false; this.service - .showToast('Password Changed!', 'top', 'my-toast', 1000) //success toast + .showToast('Password Changed!', 'top', 'my-toast', 1000) // success toast .then(res => { this.router.navigateByUrl('profile'); this.loader = false; @@ -117,7 +120,7 @@ export class UpdateService { .catch(error => { console.log('something fishy'); this.service - .showToast('Something went wrong', 'top', 'my-toast', 1000) //failure toast + .showToast('Something went wrong', 'top', 'my-toast', 1000) // failure toast .then(res => { this.loader = false; }); @@ -126,7 +129,7 @@ export class UpdateService { .catch(error => { console.log(error); this.service - .showToast(error.message, 'top', 'my-error', 3000) //failure toast + .showToast(error.message, 'top', 'my-error', 3000) // failure toast .then(res => { this.loader = false; });