Skip to content

Commit 687a5ba

Browse files
committed
It works!
1 parent 720555f commit 687a5ba

3 files changed

Lines changed: 76 additions & 10 deletions

File tree

index.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111

1212
<form>
13-
<textarea name="message">
14-
What is populated with it
15-
</textarea>
13+
<textarea name="message" placeholder="What is populated with it"></textarea>
1614
<input type="submit" />
1715
</form>
1816

src/main.ts

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,79 @@
11
import './style.css'
2+
import Dexie from 'dexie';
23

3-
const form = document.querySelector('form')
4-
const posts = document.querySelector('ol')
54

6-
form?.addEventListener('submit', e => {
5+
const db = new Dexie('Cycleoops');
6+
7+
// Declare tables, IDs and indexes
8+
db.version(1).stores({
9+
notes: '++id, time, text, lat, lon'
10+
});
11+
12+
const form = document.querySelector('form')!
13+
const posts = document.querySelector('ol')!
14+
15+
16+
async function update() {
17+
const notes = await db.notes
18+
.orderBy("time")
19+
.reverse()
20+
.toArray();
21+
22+
console.log(notes)
23+
24+
posts.innerHTML = ''
25+
26+
for(const note of notes) {
27+
28+
const li = document.createElement('li')
29+
30+
li.innerText = JSON.stringify(note);
31+
32+
posts.appendChild(li)
33+
34+
35+
}
36+
37+
}
38+
39+
update()
40+
41+
form?.addEventListener('submit', async e => {
742
e.preventDefault()
843

944
const data = new FormData(e.target)
10-
console.log("d", data.get('message'))
45+
const text = data.get("message")
46+
const time = Date.now()
47+
48+
49+
const [lat, lon] = await new Promise((resolve, reject) => {
50+
51+
navigator.geolocation.getCurrentPosition((position) => {
52+
console.log(position.coords);
53+
resolve([position.coords.latitude, position.coords.longitude])
54+
55+
56+
}, () => {
57+
58+
resolve([0,0])
59+
60+
});
61+
62+
63+
})
64+
65+
66+
const noteId = await db.notes.add({
67+
time,
68+
text,
69+
lat,
70+
lon
71+
})
72+
73+
console.log(noteId)
74+
75+
76+
update()
77+
1178

1279
})

src/style.css

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ a:hover {
2323
}
2424

2525
body {
26-
margin: 0;
27-
display: flex;
28-
place-items: center;
26+
margin: 3em;
27+
/* display: flex; */
28+
/* flex-direction: column; */
29+
/* place-items: center; */
2930
min-width: 320px;
3031
min-height: 100vh;
3132
}

0 commit comments

Comments
 (0)