coyotte508 HF staff commited on
Commit
ef1c12f
1 Parent(s): 67c107f

💄 Nicer-looking e-shop

Browse files

Also added stock of products

src/routes/vente/+page.svelte CHANGED
@@ -34,16 +34,48 @@
34
  <Masonry>
35
  {#each published as product}
36
  <a href="/vente/{product._id}" class="product">
37
- <div class="overflow-hidden">
 
 
 
 
 
 
 
 
38
  <Picture
39
  picture={product.photos[0]}
40
  minStorage={1}
41
- class="picture mx-auto max-w-full hover-zoom"
42
  />
43
  </div>
44
- <div class="flex">
45
- <span class="name">{product.name}</span>
46
- <span class="price ml-auto">{product.price} €</span>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  </div>
48
  </a>
49
  {/each}
 
34
  <Masonry>
35
  {#each published as product}
36
  <a href="/vente/{product._id}" class="product">
37
+ <div class="overflow-hidden rounded relative">
38
+ {#if product.stock > 1}
39
+ <div
40
+ class="absolute z-1 right-0 p-4 bg-sunray text-white font-bold rounded-bl-lg"
41
+ style="font-family: 'Riot Squad', sans-serif;"
42
+ >
43
+ x {product.stock}
44
+ </div>
45
+ {/if}
46
  <Picture
47
  picture={product.photos[0]}
48
  minStorage={1}
49
+ class="picture mx-auto max-w-full h-full hover-zoom rounded"
50
  />
51
  </div>
52
+ <div class="flex items-center">
53
+ <span class="name text-lg">{product.name}</span>
54
+ <span class="price ml-auto text-oxford font-bold">{product.price} €</span>
55
+ </div>
56
+ </a>
57
+ {/each}
58
+ <!-- In case there is only one product. We don't want a product to take full row in desktop mode -->
59
+ <div />
60
+ </Masonry>
61
+ </Container>
62
+
63
+ <Container class="mb-4">
64
+ <h2 class="text-4xl text-oxford my-4" id="produits">Produits épuisés</h2>
65
+
66
+ <Masonry>
67
+ {#each retired as product}
68
+ <a href="/vente/{product._id}" class="product">
69
+ <div class="overflow-hidden rounded relative">
70
+ <Picture
71
+ picture={product.photos[0]}
72
+ minStorage={1}
73
+ class="picture mx-auto max-w-full h-full hover-zoom rounded"
74
+ />
75
+ </div>
76
+ <div class="flex items-center">
77
+ <span class="name text-lg">{product.name}</span>
78
+ <span class="price ml-auto text-oxford font-bold line-through">{product.price} €</span>
79
  </div>
80
  </a>
81
  {/each}
src/routes/vente/[id]/+page.svelte CHANGED
@@ -8,6 +8,7 @@
8
 
9
  const product = data.product;
10
  let photoIndex = 0;
 
11
 
12
  function submit() {
13
  alert(
@@ -46,21 +47,52 @@
46
  <h1 class="text-oxford text-4xl">{product.name}</h1>
47
 
48
  <div class="mt-4 flex items-center">
49
- <span class="font-bold text-2xl mr-2">{product.price} €</span> (+ frais de livraison hors Finistère)
 
 
 
 
 
50
  </div>
51
  <div class="marked leading-6">
52
  {@html marked(product.description)}
53
  </div>
54
 
55
- <form action="post">
56
- <button
57
- type="submit"
58
- on:click|preventDefault={submit}
59
- class="mt-4 text-xl leading-6 py-3 px-6 bg-oxford border-0 shadow text-white rounded-md cursor-pointer"
60
- >
61
- Acheter
62
- </button>
63
- </form>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  </div>
65
  </article>
66
  </Container>
 
8
 
9
  const product = data.product;
10
  let photoIndex = 0;
11
+ let toBuy = 1;
12
 
13
  function submit() {
14
  alert(
 
47
  <h1 class="text-oxford text-4xl">{product.name}</h1>
48
 
49
  <div class="mt-4 flex items-center">
50
+ <span class="font-bold text-2xl mr-2" class:line-through={product.stock === 0}
51
+ >{product.price} €</span
52
+ >
53
+ {#if product.stock}(+ frais de livraison hors Finistère){:else}<span class="text-red-500"
54
+ >Produit épuisé!</span
55
+ >{/if}
56
  </div>
57
  <div class="marked leading-6">
58
  {@html marked(product.description)}
59
  </div>
60
 
61
+ {#if product.stock}
62
+ <form action="post">
63
+ {#if product.stock > 1}
64
+ <div>
65
+ <button
66
+ type="button"
67
+ class="btn bg-gray-700 rounded-md"
68
+ class:bg-gray-400!={toBuy <= 1}
69
+ disabled={toBuy <= 1}
70
+ class:cursor-default!={toBuy <= 1}
71
+ on:click={() => --toBuy}>-</button
72
+ >
73
+ <span
74
+ class="text-xl text-sunray mx-2 font-bold inline-block text-center"
75
+ style="width: 1rem">{toBuy}</span
76
+ >
77
+ <button
78
+ type="button"
79
+ class="btn bg-gray-700 rounded-md"
80
+ class:bg-gray-400!={toBuy >= product.stock}
81
+ disabled={toBuy >= product.stock}
82
+ on:click={() => ++toBuy}>+</button
83
+ >
84
+ </div>
85
+ {/if}
86
+ <button
87
+ type="submit"
88
+ on:click|preventDefault={submit}
89
+ class="mt-4 text-xl leading-6 py-3 px-6 bg-oxford border-0 shadow text-white rounded-md cursor-pointer"
90
+ >
91
+ Acheter
92
+ </button>
93
+ <div class="flex-grow" />
94
+ </form>
95
+ {/if}
96
  </div>
97
  </article>
98
  </Container>