Skip to content

Commit 41d83a0

Browse files
committed
persist user ratings for levels
1 parent 02bacd4 commit 41d83a0

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

backend/server.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ const server = Bun.serve({
425425

426426
if (authentication?.user) {
427427
const rating = await sql`select thumbs_up from ratings where user_id = ${authentication.user} AND level_id = ${levelId}`
428-
console.log(rating)
429428
currentRating = rating !== [] ? rating[0].thumbs_up : null
430429
}
431430

frontend/javascript/level.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,21 @@ const serverUrl = window.location.origin
77
async function getLevel(level = 1) {
88
try {
99
const raw = await fetch(`${serverUrl}/api/level?levelId=${level}`)
10-
const levels = raw.json()
10+
const levels = await raw.json()
11+
12+
const approvalWrapper = document.querySelector(".thumbs-up-wrapper")
13+
const disapprovalWrapper = document.querySelector(".thumbs-down-wrapper")
14+
15+
console.log(levels)
16+
17+
console.log(levels.current_user_rating)
18+
19+
if (levels.current_user_rating) {
20+
approvalWrapper.classList.add("clicked")
21+
} else if (levels.current_user_rating === false) {
22+
disapprovalWrapper.classList.add("clicked")
23+
}
24+
1125
window.dispatchEvent(new CustomEvent('level:loaded', { detail: levels }))
1226
return await levels
1327
} catch (e) {
@@ -203,4 +217,4 @@ disapprovalButton.addEventListener("click", () => {
203217
approvalWrapper.classList.remove("clicked")
204218

205219
rateLevel(false)
206-
})
220+
})

todo.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
- options page
2222
- sign out button
2323
- you can still request levels from the server that are private
24-
- opening a page of a level you've rated should show your rating
2524

2625
**Editor**
2726

0 commit comments

Comments
 (0)