radames commited on
Commit
d92c610
β€’
1 Parent(s): 13fd302

scroll into view

Browse files
Files changed (2) hide show
  1. Makefile +1 -1
  2. frontend/src/routes/+page.svelte +17 -10
Makefile CHANGED
@@ -5,7 +5,7 @@ build-dev:
5
  run-front-dev:
6
  cd frontend && npm install && PUBLIC_DEV_MODE=DEV npm run dev
7
  run-dev:
8
- FLASK_ENV=development python app.py
9
  run-prod:
10
  python app.py
11
  build-all: run-prod
 
5
  run-front-dev:
6
  cd frontend && npm install && PUBLIC_DEV_MODE=DEV npm run dev
7
  run-dev:
8
+ rm -rf .data/ && FLASK_ENV=development python app.py
9
  run-prod:
10
  python app.py
11
  build-all: run-prod
frontend/src/routes/+page.svelte CHANGED
@@ -14,14 +14,23 @@
14
 
15
  let promptsData: ColorsPrompt[];
16
  let prompt: string;
 
17
 
18
  onMount(() => {
19
- fetch(apiUrl + '/data')
20
- .then((d) => d.json())
21
- .then((palettes) => {
22
- promptsData = sortData(palettes);
23
- });
24
  });
 
 
 
 
 
 
 
 
25
  $: promptsTotal = promptsData?.length || 0;
26
 
27
  function sortData(_promptData: ColorsPrompt[]) {
@@ -144,10 +153,7 @@
144
  }
145
  function remix(e: CustomEvent) {
146
  prompt = e.detail.prompt;
147
- window.scrollTo({
148
- top: 0,
149
- behavior: 'smooth'
150
- });
151
  }
152
  </script>
153
 
@@ -166,9 +172,10 @@
166
  </a>,
167
  <a class="link" href="https://drib.net/homage"> dribnet </a>
168
  </p>
169
- <div class="relative sticky top-0 z-50 bg-white dark:bg-black py-3">
170
  <form class="grid grid-cols-6" on:submit|preventDefault={() => generatePalette(prompt)}>
171
  <input
 
172
  class="input"
173
  placeholder="A photo of a beautiful sunset in San Francisco"
174
  title="Input prompt to generate image and obtain palette"
 
14
 
15
  let promptsData: ColorsPrompt[];
16
  let prompt: string;
17
+ let promptInput: HTMLElement;
18
 
19
  onMount(() => {
20
+ fetchData();
21
+ const interval = window.setInterval(fetchData, 5000);
22
+ return () => {
23
+ clearInterval(interval);
24
+ };
25
  });
26
+
27
+ async function fetchData() {
28
+ const palettes = await fetch(apiUrl + '/data').then((d) => d.json());
29
+ if (!promptsData || palettes.length > promptsData.length) {
30
+ promptsData = sortData(palettes);
31
+ }
32
+ }
33
+
34
  $: promptsTotal = promptsData?.length || 0;
35
 
36
  function sortData(_promptData: ColorsPrompt[]) {
 
153
  }
154
  function remix(e: CustomEvent) {
155
  prompt = e.detail.prompt;
156
+ promptInput.scrollIntoView({ behavior: 'smooth' });
 
 
 
157
  }
158
  </script>
159
 
 
172
  </a>,
173
  <a class="link" href="https://drib.net/homage"> dribnet </a>
174
  </p>
175
+ <div class="relative top-0 z-50 bg-white dark:bg-black py-3">
176
  <form class="grid grid-cols-6" on:submit|preventDefault={() => generatePalette(prompt)}>
177
  <input
178
+ bind:this={promptInput}
179
  class="input"
180
  placeholder="A photo of a beautiful sunset in San Francisco"
181
  title="Input prompt to generate image and obtain palette"