-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.svelte
70 lines (61 loc) · 1.52 KB
/
index.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<script>
import marked from "marked";
import Notes from "../components/Notes.svelte";
let title = "";
let body = "";
function addNote() {
if (!body) {
return;
}
if (!title) {
return;
}
const note = { title: title, body: body };
fetch("notes.json", {
method: "POST",
body: JSON.stringify(note),
headers: {
"Content-Type": "application/json",
},
})
.then((r) => {
title = "";
body = "";
r.json().then(function (result) {
// The data is posted: do something with the result...
});
})
.catch((err) => {
// POST error: do something...
console.log("POST error", err.message);
});
}
</script>
<style>
</style>
<svelte:head>
<title>Evergreen</title>
</svelte:head>
<div class="container">
<div class="row">
<div class="col">
<div><input type="text" bind:value={title} /></div>
<div>
<!-- Declare a textarea where the user can enter markdown, and bind it to the variable `markdown` -->
<textarea rows="30" cols="60" bind:value={body} placeholder="Enter markdown here" />
</div>
<div>
<button class="save" on:click={addNote}>
<span class="circle" aria-hidden="true"> <span class="icon arrow" /> </span>
<span class="button-text">Save</span>
</button>
</div>
</div>
<div class="col">
<div>
{@html marked(body)}
</div>
</div>
</div>
</div>
<Notes bind:newNote={body} />