Skip to content

Commit

Permalink
Create a dialog for auction end
Browse files Browse the repository at this point in the history
  • Loading branch information
dhzdhd committed Nov 9, 2023
1 parent 68f7faf commit 99010c1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
3 changes: 3 additions & 0 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ module.exports = {
.service("api::product.product")
.loadProducts(params.id);

let bid = await strapi.service("api::bid.bid").loadBids(params.id);

io.emit("loadProducts", data);
io.emit("loadBids", bid);
} catch (error) {
console.log(error);
}
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
align-items: center
padding: 1rem 2rem
color: var(--secondary-color)
z-index: 10
.title
display: flex
Expand Down Expand Up @@ -121,6 +122,7 @@
align-items: center
padding: 20px
background-color: vars.$accent
z-index: 10
.social-link
margin: 0 10px
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/routes/auth/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
export let form: ActionData;
const updateUser = () => {
$: updateUser(form);
const updateUser = (form: ActionData) => {
if (browser) {
window.localStorage.setItem('user', form?.id);
}
Expand Down Expand Up @@ -44,8 +46,10 @@
use:enhance={() => {
return async ({ result, update }) => {
// await applyAction(result);
console.log(result);

update();
updateUser();
updateUser(form);
};
}}
>
Expand Down
44 changes: 32 additions & 12 deletions frontend/src/routes/home/[id=int]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@
socket = socketIOClient(CMS_URL, { query: { token: data.token } });
socket.emit('loadProducts', { id: product.id });
socket.on('loadProducts', (data: any) => {
console.log('products loaded');
console.log(data);
updateProduct(data);
});
socket.on('loadBids', (data: any) => {
console.log('bids loaded');
if (browser) {
const user = window.localStorage.getItem('user');
isWinner = Number(data.user) === Number(user);
Expand Down Expand Up @@ -91,20 +95,24 @@
<h4>Product Details</h4>
<span>{product.description}</span>
</div>
<input bind:value={currentBid} type="number" class="input" />
<Button id="bid-btn" text="Make Bid" func={makeBid} />

{#if !product.available}
<h1>Auction ended!</h1>
{#if product.available}
<input bind:value={currentBid} type="number" class="input" />
<Button id="bid-btn" text="Make Bid" func={makeBid} />
{/if}

{#if isWinner && !product.available}
<h1>You won the auction!</h1>
<Button
id="payment-btn"
text="Proceed to payment"
func={() => goto(`/home/payment?id=${product.id}`)}
/>
{#if !product.available}
<div class="dialog">
{#if isWinner}
<h1>You won the auction!</h1>
<Button
id="payment-btn"
text="Proceed to payment"
func={() => goto(`/home/payment?id=${product.id}`)}
/>
{:else}
<h1>Auction ended!</h1>
{/if}
</div>
{/if}
</section>

Expand Down Expand Up @@ -142,4 +150,16 @@ section
border: none
color: white
.dialog
position: fixed
background-color: vars.$primary
box-shadow: 0rem 0rem 100vh 100vh black
display: flex
flex-direction: column
gap: 1rem
padding: 5rem
border-radius: 2rem
top: 40vh
z-index: 0
</style>

0 comments on commit 99010c1

Please sign in to comment.