Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

Commit 7519605

Browse files
committed
use json instead of yaml
1 parent 6c01a5a commit 7519605

5 files changed

Lines changed: 1246 additions & 75 deletions

File tree

src/App.svelte

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
11
<script>
2-
import {onMount} from 'svelte';
3-
import yaml from 'js-yaml';
4-
// import * as api from './api';
2+
import { onMount } from 'svelte';
3+
4+
import allThemes from './assets/themes.json';
55
// import {app} from '../src2/$app';
66
// import Panel from '~src/components/Panel.svelte';
77
import Loading from '~components/Loading.svelte';
88
99
onMount(async _ => {
10-
console.log('did');
11-
// $app.loading = true;
12-
// // Just waiting
13-
// await new Promise(resolve => setTimeout(resolve, 1000));
14-
// // Now fetching
15-
// const themesYml = await api.get('themes.yml');
16-
// const allThemes = yaml.load(themesYml);
17-
// const themes = [
18-
// ...allThemes.material,
19-
// ...allThemes.other,
20-
// ];
21-
//
22-
// // Load themes
23-
// $app.loadThemes(themes);
24-
// // Get settings from local storage
25-
// await $app.fetchSettings();
26-
// // Add defaults
27-
// $app.loadDefaults();
28-
//
29-
// $app.loading = false;
10+
// $app.loading = true;
11+
// // Just waiting
12+
// await new Promise(resolve => setTimeout(resolve, 1000));
13+
// // Now fetching
14+
const themes = [
15+
...allThemes.material,
16+
...allThemes.other
17+
];
18+
//
19+
// // Load themes
20+
// $app.loadThemes(themes);
21+
// // Get settings from local storage
22+
// await $app.fetchSettings();
23+
// // Add defaults
24+
// $app.loadDefaults();
25+
//
26+
// $app.loading = false;
3027
});
3128
</script>
3229

src/api.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
async function send({ method, path, data = null, token }) {
2+
const fetch = window.fetch;
3+
4+
const opts: RequestInit = { method, headers: {} };
5+
6+
if (data) {
7+
opts.headers['Content-Type'] = 'application/json';
8+
opts.body = JSON.stringify(data);
9+
}
10+
11+
if (token) {
12+
opts.headers['Authorization'] = `Token ${token}`;
13+
}
14+
15+
let r = await fetch(`${path}`, opts);
16+
let json: string = await r.text();
17+
try {
18+
return JSON.parse(json);
19+
} catch (err) {
20+
return json;
21+
}
22+
}
23+
24+
export function get(path: string, token: string) {
25+
return send({ method: 'GET', path, token });
26+
}
27+
28+
export function del(path: string, token: string) {
29+
return send({ method: 'DELETE', path, token });
30+
}
31+
32+
export function post(path: string, data: unknown, token: string) {
33+
return send({ method: 'POST', path, data, token });
34+
}
35+
36+
export function put(path: string, data: unknown, token: string) {
37+
return send({ method: 'PUT', path, data, token });
38+
}

0 commit comments

Comments
 (0)