Ron Au commited on
Commit
335e0ef
1 Parent(s): 8f246ac

WIP2: New UI

Browse files
Files changed (3) hide show
  1. static/index.js +22 -22
  2. static/style.css +35 -9
  3. templates/index.html +7 -2
static/index.js CHANGED
@@ -211,8 +211,6 @@ const rotateCard = () => {
211
  const rotateX = (containerMouseEvent.clientY - rect.y - rect.height / 2) * RANGE;
212
  const rotateY = -(containerMouseEvent.clientX - rect.x - rect.width / 2) * RANGE;
213
 
214
- console.log(performance.now() - previousTime);
215
-
216
  card.style.setProperty('--card-rx', rotateX + 'deg');
217
  card.style.setProperty('--card-ry', rotateY + 'deg');
218
  }
@@ -229,14 +227,15 @@ const initialiseCardRotation = (scene) => {
229
  return mousemoveHandler;
230
  };
231
 
232
- const setScene = (scene, mode, state) => {
233
- const booster = scene.querySelector('.booster');
234
- const cardSlot = scene.querySelector('.cardSlot');
235
 
236
- scene.dataset.mode = mode;
237
- scene.dataset.state = state;
238
  };
239
 
 
 
240
  let generating = false;
241
 
242
  const booster = document.querySelector('.booster');
@@ -254,37 +253,38 @@ const generate = async () => {
254
  const cardSlot = scene.querySelector('.card-slot');
255
  const durationDisplay = document.querySelector('.duration');
256
 
257
- cardSlot.innerHTML = '';
258
- // const oldCard = cardSlot.querySelector('.pokecard');
259
  scene.removeEventListener('mousemove', mousemoveHandlerForPreviousCard, true);
 
260
 
261
  generating = true;
262
 
263
- setScene(scene, 'booster', 'generating');
264
 
265
  const details = await generateDetails();
266
- // const task = await createTask(details.energy_type);
267
 
268
- // const timer = durationTimer(durationDisplay);
269
- // const timerCleanup = timer().cleanup;
 
270
 
271
- // const longPromises = [queueTask(task.task_id), longPollTask(task)];
272
- // const completedTask = await Promise.any(longPromises);
273
- await new Promise((resolve) => setTimeout(resolve, 3_000));
274
 
275
- setScene(scene, 'booster', 'completed');
276
 
277
  await new Promise((resolve) => setTimeout(resolve, 1_000));
278
 
279
  generating = false;
280
- // timerCleanup(completedTask);
281
 
282
- // scene.innerHTML = cardHTML(details);
283
  cardSlot.innerHTML = cardHTML(details);
284
- // const picture = document.querySelector('img.picture');
285
- // picture.src = completedTask.value;
 
286
  mousemoveHandlerForPreviousCard = initialiseCardRotation(scene);
287
- setScene(scene, 'card', 'completed');
 
288
  } catch (err) {
289
  generating = false;
290
  console.error(err);
 
211
  const rotateX = (containerMouseEvent.clientY - rect.y - rect.height / 2) * RANGE;
212
  const rotateY = -(containerMouseEvent.clientX - rect.x - rect.width / 2) * RANGE;
213
 
 
 
214
  card.style.setProperty('--card-rx', rotateX + 'deg');
215
  card.style.setProperty('--card-ry', rotateY + 'deg');
216
  }
 
227
  return mousemoveHandler;
228
  };
229
 
230
+ const setOutput = (mode, state) => {
231
+ const output = document.querySelector('.output');
 
232
 
233
+ output.dataset.mode = mode;
234
+ output.dataset.state = state;
235
  };
236
 
237
+ /* Initialise */
238
+
239
  let generating = false;
240
 
241
  const booster = document.querySelector('.booster');
 
253
  const cardSlot = scene.querySelector('.card-slot');
254
  const durationDisplay = document.querySelector('.duration');
255
 
 
 
256
  scene.removeEventListener('mousemove', mousemoveHandlerForPreviousCard, true);
257
+ cardSlot.innerHTML = '';
258
 
259
  generating = true;
260
 
261
+ setOutput('booster', 'generating');
262
 
263
  const details = await generateDetails();
264
+ const task = await createTask(details.energy_type);
265
 
266
+ durationDisplay.classList.add('displayed');
267
+ const timer = durationTimer(durationDisplay);
268
+ const timerCleanup = timer().cleanup;
269
 
270
+ const longPromises = [queueTask(task.task_id), longPollTask(task)];
271
+ const completedTask = await Promise.any(longPromises);
272
+ await new Promise((resolve) => setTimeout(resolve, 1_000));
273
 
274
+ setOutput('booster', 'completed');
275
 
276
  await new Promise((resolve) => setTimeout(resolve, 1_000));
277
 
278
  generating = false;
279
+ timerCleanup(completedTask);
280
 
 
281
  cardSlot.innerHTML = cardHTML(details);
282
+ const picture = document.querySelector('img.picture');
283
+ picture.src = completedTask.value;
284
+
285
  mousemoveHandlerForPreviousCard = initialiseCardRotation(scene);
286
+
287
+ setOutput('card', 'completed');
288
  } catch (err) {
289
  generating = false;
290
  console.error(err);
static/style.css CHANGED
@@ -73,10 +73,6 @@ section {
73
  height: min-content;
74
  }
75
 
76
- .output {
77
- height: min-content;
78
- }
79
-
80
  .poke-trio {
81
  display: flex;
82
  flex-direction: row;
@@ -203,6 +199,14 @@ input:focus {
203
 
204
  /* Output Section */
205
 
 
 
 
 
 
 
 
 
206
  .output .actions {
207
  display: flex;
208
  flex-direction: row;
@@ -210,7 +214,20 @@ input:focus {
210
  align-items: center;
211
  gap: 1rem;
212
  width: 100%;
213
- margin: 1rem auto 2.5rem;
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  }
215
 
216
  @media (max-width: 500px) {
@@ -242,12 +259,20 @@ input:focus {
242
 
243
  .duration {
244
  color: var(--theme-subtext);
245
- margin-left: auto;
246
  text-align: right;
247
  width: max-content;
248
  background-color: var(--theme-highlight);
249
  padding: 0.5rem 1rem;
250
  border-radius: 1rem;
 
 
 
 
 
 
 
 
251
  }
252
 
253
  button {
@@ -278,7 +303,8 @@ button:active {
278
  .scene {
279
  --scale: 0.9;
280
  perspective: 100rem;
281
- margin: 0.5rem;
 
282
  height: 40rem;
283
  /* height: 100%; */
284
 
@@ -959,9 +985,9 @@ img.hf-logo {
959
  animation: 5s bounce infinite ease-out;
960
  }
961
 
962
- [data-state='generating'].scene {
963
  animation: 15s spin-x infinite linear;
964
- height: auto;
965
  transform-origin: center;
966
  }
967
  [data-state='generating'] .booster {
 
73
  height: min-content;
74
  }
75
 
 
 
 
 
76
  .poke-trio {
77
  display: flex;
78
  flex-direction: row;
 
199
 
200
  /* Output Section */
201
 
202
+ .output {
203
+ display: flex;
204
+ flex-direction: column;
205
+ justify-content: space-around;
206
+ height: max-content;
207
+ perspective: 100rem;
208
+ }
209
+
210
  .output .actions {
211
  display: flex;
212
  flex-direction: row;
 
214
  align-items: center;
215
  gap: 1rem;
216
  width: 100%;
217
+ margin: 1rem auto 1.5rem;
218
+ transform-style: preserve-3d;
219
+ transform-origin: bottom;
220
+ transform: translateY(-25%);
221
+ transition: transform 0.5s, opacity 0.5s;
222
+ visibility: hidden;
223
+ opacity: 0;
224
+ }
225
+
226
+ [data-mode='card'][data-state='completed'] .actions {
227
+ visibility: visible;
228
+ transform: translateY(0);
229
+ opacity: 1;
230
+ /* pointer-events: none; */
231
  }
232
 
233
  @media (max-width: 500px) {
 
259
 
260
  .duration {
261
  color: var(--theme-subtext);
262
+ margin: 0 auto;
263
  text-align: right;
264
  width: max-content;
265
  background-color: var(--theme-highlight);
266
  padding: 0.5rem 1rem;
267
  border-radius: 1rem;
268
+ visibility: hidden;
269
+ opacity: 0;
270
+ transition: opacity 0.2s ease-in;
271
+ }
272
+
273
+ .duration.displayed {
274
+ visibility: visible;
275
+ opacity: 1;
276
  }
277
 
278
  button {
 
303
  .scene {
304
  --scale: 0.9;
305
  perspective: 100rem;
306
+ /* margin: 0.5rem; */
307
+ margin: 2rem;
308
  height: 40rem;
309
  /* height: 100%; */
310
 
 
985
  animation: 5s bounce infinite ease-out;
986
  }
987
 
988
+ [data-state='generating'] .scene {
989
  animation: 15s spin-x infinite linear;
990
+ /* height: auto; */
991
  transform-origin: center;
992
  }
993
  [data-state='generating'] .booster {
templates/index.html CHANGED
@@ -4,6 +4,11 @@
4
  <meta charset="UTF-8" />
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
  <title>This Pokémon Does Not Exist</title>
 
 
 
 
 
7
  <link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}" />
8
  <link rel="stylesheet" id="stylesheet-tag" />
9
  <script type="module" id="script-tag"></script>
@@ -34,7 +39,7 @@
34
  >
35
  </p>
36
  </section>
37
- <section class="output">
38
  <div class="actions">
39
  <button class="share">Share</button>
40
  <button class="save">Save</button>
@@ -42,7 +47,7 @@
42
  <button class="generate-new">New Pokémon</button>
43
  </div>
44
  <div class="duration"><span class="elapsed">0.0</span>s (ETA: <span class="eta">40</span>s)</div>
45
- <div class="scene" data-mode="booster" data-state="ready">
46
  <div class="booster">
47
  <div class="foil triangle top left"></div>
48
  <div class="foil triangle top right"></div>
 
4
  <meta charset="UTF-8" />
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
  <title>This Pokémon Does Not Exist</title>
7
+ <style>
8
+ .actions, .duration {
9
+ opacity: 0;
10
+ }
11
+ </style>
12
  <link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}" />
13
  <link rel="stylesheet" id="stylesheet-tag" />
14
  <script type="module" id="script-tag"></script>
 
39
  >
40
  </p>
41
  </section>
42
+ <section class="output" data-mode="booster" data-state="ready">
43
  <div class="actions">
44
  <button class="share">Share</button>
45
  <button class="save">Save</button>
 
47
  <button class="generate-new">New Pokémon</button>
48
  </div>
49
  <div class="duration"><span class="elapsed">0.0</span>s (ETA: <span class="eta">40</span>s)</div>
50
+ <div class="scene">
51
  <div class="booster">
52
  <div class="foil triangle top left"></div>
53
  <div class="foil triangle top right"></div>