Switch to Svelte
This commit is contained in:
5
frontend/src/lib/Counter.svelte
Normal file
5
frontend/src/lib/Counter.svelte
Normal file
@@ -0,0 +1,5 @@
|
||||
<script>
|
||||
let count = $state(0)
|
||||
</script>
|
||||
|
||||
<button type="button" class="counter" onclick={() => count++}>Count is {count}</button>
|
||||
23
frontend/src/lib/api.js
Normal file
23
frontend/src/lib/api.js
Normal file
@@ -0,0 +1,23 @@
|
||||
export async function apiRequest(endpoint, method = 'GET', data = null) {
|
||||
const options = {
|
||||
method,
|
||||
headers: {},
|
||||
};
|
||||
|
||||
if (data) {
|
||||
options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
||||
options.body = new URLSearchParams(data).toString();
|
||||
}
|
||||
|
||||
const res = await fetch(`/api${endpoint}`, options);
|
||||
if (!res.ok) {
|
||||
let msg = res.statusText;
|
||||
try {
|
||||
const errBody = await res.json();
|
||||
if (errBody.error) msg = errBody.error;
|
||||
else if (errBody.detail) msg = errBody.detail;
|
||||
} catch(e) {}
|
||||
throw new Error(msg);
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
1423
frontend/src/lib/suggestions.js
Normal file
1423
frontend/src/lib/suggestions.js
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user