-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
=
committed
Dec 11, 2022
1 parent
c0ac4e0
commit 80bba62
Showing
9 changed files
with
1,698 additions
and
279 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,42 @@ | ||
import { Cup, cups } from "../products/Cup"; | ||
import { collection, addDoc, getFirestore } from "firebase/firestore"; | ||
import { app } from "src/main"; | ||
import * as sha512 from 'js-sha512'; | ||
|
||
export var cartArray: Object[] = cups; | ||
export var cartArray: Cup[] = []; | ||
|
||
export function addItems(cup: Cup) { | ||
cartArray.push(cup) | ||
localStorage.setItem('cartItems', JSON.stringify(cartArray)) | ||
sessionStorage.setItem('cartItems', JSON.stringify(cartArray)) | ||
} | ||
|
||
export function getCartItems() { | ||
let data = localStorage.getItem('cartItems') | ||
let data = sessionStorage.getItem('cartItems') | ||
if (data) return JSON.parse(data) | ||
} | ||
|
||
export function deleteCartItems() { | ||
sessionStorage.removeItem('cartItems') | ||
} | ||
|
||
export function hasher(input: string) { | ||
sha512.sha512(input); | ||
} | ||
|
||
export async function buy(cup: Cup, address: string) { | ||
let rawData = sessionStorage.getItem('cartItems') | ||
const db = getFirestore(app); | ||
if (rawData) { | ||
try { | ||
const docRef = await addDoc(collection(db, Date()), { | ||
name: cup.name, | ||
price: cup.price, | ||
address: address, | ||
date: Date() | ||
}); | ||
console.log("Document written with ID: ", docRef.id); | ||
} catch (e) { | ||
console.error("Error adding document: ", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,24 @@ | ||
<div class="p-20 bg-blue-100" *ngFor="let cup of cups"> | ||
<div class="p-20 bg-blue-100" *ngFor="let cup of carts"> | ||
<div class="p-6 bg-white rounded-lg shadow-lg"> | ||
<h2 class="mb-2 text-2xl font-bold text-gray-800">{{cup.name}}</h2> | ||
<p class="text-gray-700">{{cup.desc}}</p> | ||
<h2 class="mb-2 text-2xl font-bold text-gray-800">{{ cup.name }}</h2> | ||
<p class="text-gray-700">{{ cup.desc }}</p> | ||
<p class="text-gray-700">Total price: {{ cup.quantity * cup.price }} Rs.</p> | ||
<form> | ||
<input type="text" placeholder="Detailed Address" required #address/> | ||
<br> | ||
<button | ||
class="p-3 font-mono font-bold text-white border-2 rounded-md border-sky-600 bg-red-600 hover:bg-red-800 hover:border-red-800" | ||
(click)="deleteItems(cup)" | ||
> | ||
Remove all items | ||
</button> | ||
<button | ||
type="submit" | ||
class="p-3 m-3 font-mono font-bold text-white border-2 rounded-md border-sky-600 bg-sky-600 hover:bg-sky-800 hover:border-sky-800" | ||
(click)="buy(cup, address.value)" | ||
> | ||
Buy all cups | ||
</button> | ||
</form> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,33 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Cup, cups } from '../products/Cup'; | ||
import { buy, cartArray, deleteCartItems } from './Cart'; | ||
|
||
@Component({ | ||
selector: 'app-cart', | ||
templateUrl: './cart.component.html', | ||
styleUrls: ['./cart.component.scss'] | ||
}) | ||
export class CartComponent implements OnInit { | ||
|
||
cups: Cup[] = cups | ||
carts: Cup[] = cartArray | ||
|
||
deleteItems(cup: Cup) { | ||
deleteCartItems() | ||
} | ||
buy(cup: Cup, address: string) { | ||
buy(cup, address) | ||
} | ||
|
||
constructor() { } | ||
|
||
ngOnInit(): void { | ||
let a = sessionStorage.getItem('cartItems') | ||
if (a) { | ||
if (this.carts = []) { | ||
this.carts = JSON.parse(a) | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
<div *ngFor="let cup of cups"> | ||
<div class="max-w-sm overflow-hidden rounded shadow-lg"> | ||
<img class="w-full" src={{cup.imageLink}} alt="Sunset in the mountains"> | ||
<div *ngFor="let cup of cups" class="p-5 text-center bg-lime-500"> | ||
<div class="max-w-sm m-5 bg-white shadow-2xl rounded-lg"> | ||
<img class="w-full rounded-t-lg" src={{cup.imageLink}} alt={{cup.imageLink}}> | ||
<div class="px-6 py-4"> | ||
<div class="mb-2 text-xl font-bold">{{cup.name}}</div> | ||
<p class="text-base text-gray-700"> | ||
{{cup.desc}} | ||
{{cup.price}} / Cup. | ||
</p> | ||
<select name="Quantity: "> | ||
<option *ngFor="let option of options" [value]="option.key" (click)="click(option, cup)"></option> | ||
</select> | ||
<button class="p-3 m-3 font-mono font-bold text-white border-2 rounded-md border-sky-600 bg-sky-600 hover:bg-sky-800 hover:border-sky-800">Buy</button> | ||
<input type="text" name="Quantity" id="q" #input maxlength="1" placeholder="Quantity" class="p-3 rounded-lg border-gray-600 focus:border-blue-700 w-full"> | ||
<button class="p-3 m-3 font-mono font-bold text-white border-2 rounded-md border-sky-600 bg-sky-600 hover:bg-sky-800 hover:border-sky-800" (click)="cart(cup, input)">Add to Cart</button> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters