dylanebert HF staff commited on
Commit
0818503
1 Parent(s): 0965b80

see model after vote

Browse files
Files changed (2) hide show
  1. src/routes/Vote.svelte +32 -10
  2. static/global.css +22 -0
src/routes/Vote.svelte CHANGED
@@ -24,6 +24,9 @@
24
  let overlayB: HTMLDivElement;
25
  let loadingBarFillA: HTMLDivElement;
26
  let loadingBarFillB: HTMLDivElement;
 
 
 
27
  let statusMessage: string = "Loading...";
28
  let errorMessage: string = "";
29
  let data: Data;
@@ -100,8 +103,9 @@
100
  }
101
 
102
  async function vote(option: "A" | "B") {
103
- statusMessage = "Processing vote...";
104
- errorMessage = "";
 
105
 
106
  const payload = {
107
  username: getUsername(),
@@ -111,6 +115,8 @@
111
  };
112
  const url = `https://dylanebert-3d-arena-backend.hf.space/vote`;
113
 
 
 
114
  try {
115
  const response = await fetch(url, {
116
  method: "POST",
@@ -122,10 +128,18 @@
122
  body: JSON.stringify(payload),
123
  });
124
 
 
 
 
125
  if (response.ok) {
126
  const result = await response.json();
127
  console.log(result);
128
- loadScenes();
 
 
 
 
 
129
  } else {
130
  errorMessage = "Failed to process vote.";
131
  }
@@ -135,6 +149,10 @@
135
  }
136
  }
137
 
 
 
 
 
138
  function handleResize() {
139
  requestAnimationFrame(() => {
140
  if (canvasA && containerA) {
@@ -184,6 +202,7 @@
184
  <div bind:this={loadingBarFillA} class="loading-bar-fill" />
185
  </div>
186
  </div>
 
187
  <canvas bind:this={canvasA} class="viewer-canvas" id="canvas1"> </canvas>
188
  <div class="stats">
189
  {#if viewerA}
@@ -218,6 +237,7 @@
218
  <div bind:this={loadingBarFillB} class="loading-bar-fill" />
219
  </div>
220
  </div>
 
221
  <canvas bind:this={canvasB} class="viewer-canvas" id="canvas2"></canvas>
222
  <div class="stats">
223
  {#if viewerB}
@@ -247,11 +267,13 @@
247
  </div>
248
  </div>
249
  </div>
250
- <div class="vote-buttons-container">
251
- <button class="vote-button" on:click={() => vote("A")}>A is Better</button>
252
- <button class="vote-button" on:click={() => vote("B")}>B is Better</button>
253
- </div>
254
- <div class="skip-container">
255
- <button class="vote-button" on:click={() => loadScenes()}>Skip</button>
256
- </div>
 
 
257
  {/if}
 
24
  let overlayB: HTMLDivElement;
25
  let loadingBarFillA: HTMLDivElement;
26
  let loadingBarFillB: HTMLDivElement;
27
+ let voteOverlay: boolean = false;
28
+ let voteOverlayA: HTMLDivElement;
29
+ let voteOverlayB: HTMLDivElement;
30
  let statusMessage: string = "Loading...";
31
  let errorMessage: string = "";
32
  let data: Data;
 
103
  }
104
 
105
  async function vote(option: "A" | "B") {
106
+ voteOverlay = true;
107
+ voteOverlayA.classList.add("show");
108
+ voteOverlayB.classList.add("show");
109
 
110
  const payload = {
111
  username: getUsername(),
 
115
  };
116
  const url = `https://dylanebert-3d-arena-backend.hf.space/vote`;
117
 
118
+ const startTime = Date.now();
119
+
120
  try {
121
  const response = await fetch(url, {
122
  method: "POST",
 
128
  body: JSON.stringify(payload),
129
  });
130
 
131
+ const elapsedTime = Date.now() - startTime;
132
+ const remainingTime = Math.max(1200 - elapsedTime, 0);
133
+
134
  if (response.ok) {
135
  const result = await response.json();
136
  console.log(result);
137
+ setTimeout(() => {
138
+ voteOverlayA.classList.remove("show");
139
+ voteOverlayB.classList.remove("show");
140
+ voteOverlay = false;
141
+ loadScenes();
142
+ }, remainingTime);
143
  } else {
144
  errorMessage = "Failed to process vote.";
145
  }
 
149
  }
150
  }
151
 
152
+ function skip() {
153
+ loadScenes();
154
+ }
155
+
156
  function handleResize() {
157
  requestAnimationFrame(() => {
158
  if (canvasA && containerA) {
 
202
  <div bind:this={loadingBarFillA} class="loading-bar-fill" />
203
  </div>
204
  </div>
205
+ <div bind:this={voteOverlayA} class="vote-overlay">{data.model1}</div>
206
  <canvas bind:this={canvasA} class="viewer-canvas" id="canvas1"> </canvas>
207
  <div class="stats">
208
  {#if viewerA}
 
237
  <div bind:this={loadingBarFillB} class="loading-bar-fill" />
238
  </div>
239
  </div>
240
+ <div bind:this={voteOverlayB} class="vote-overlay">{data.model2}</div>
241
  <canvas bind:this={canvasB} class="viewer-canvas" id="canvas2"></canvas>
242
  <div class="stats">
243
  {#if viewerB}
 
267
  </div>
268
  </div>
269
  </div>
270
+ {#if !voteOverlay}
271
+ <div class="vote-buttons-container">
272
+ <button class="vote-button" on:click={() => vote("A")}>A is Better</button>
273
+ <button class="vote-button" on:click={() => vote("B")}>B is Better</button>
274
+ </div>
275
+ <div class="skip-container">
276
+ <button class="vote-button" on:click={() => skip()}>Skip</button>
277
+ </div>
278
+ {/if}
279
  {/if}
static/global.css CHANGED
@@ -129,6 +129,28 @@ body {
129
  font-size: 16px;
130
  }
131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  .loading-bar {
133
  position: relative;
134
  width: 256px;
 
129
  font-size: 16px;
130
  }
131
 
132
+ .vote-overlay {
133
+ position: absolute;
134
+ top: 0;
135
+ left: 0;
136
+ width: 100%;
137
+ height: 100%;
138
+ background-color: rgb(0, 0, 0, 0);
139
+ color: rgba(255, 255, 255, 0);
140
+ display: flex;
141
+ flex-direction: column;
142
+ justify-content: center;
143
+ align-items: center;
144
+ z-index: 110;
145
+ transition: background-color 0.1s ease, color 0.1s ease;
146
+ pointer-events: none;
147
+ }
148
+
149
+ .vote-overlay.show {
150
+ background-color: rgb(0, 0, 0, 1);
151
+ color: rgba(255, 255, 255, 1);
152
+ }
153
+
154
  .loading-bar {
155
  position: relative;
156
  width: 256px;