From e4c0caadc07b050ca827483263d15d2c118df3d2 Mon Sep 17 00:00:00 2001 From: Guillermo Serrahima Date: Fri, 20 Feb 2026 16:13:42 +0100 Subject: cleanup --- frontend/src/main.ts | 58 ++++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/frontend/src/main.ts b/frontend/src/main.ts index d5f4d53..099193a 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -1,33 +1,37 @@ import './style.css' -const app = document.querySelector('#app'); -if (!app) { - console.error('App container not found'); - throw new Error('App container not found'); -} +async function main() { + const app = document.querySelector('#app'); + if (!app) { + console.error('App container not found'); + throw new Error('App container not found'); + } + + app.innerHTML = '
'; -app.innerHTML = '
'; + try { + const response = await fetch('http://localhost:8080/api/posts'); + if (!response.ok) throw new Error(`HTTP ${response.status}`); -try { - const response = await fetch('http://localhost:8080/api/posts'); - if (!response.ok) throw new Error(`HTTP ${response.status}`); - - const posts = await response.json(); - app.innerHTML = ''; - - for (const post of posts) { - const postHTML = ` -
- avatar -
-
@${post.authorHandle}
-
${post.text || '
'}
-
${new Date(post.createdAt).toLocaleString()}
+ const posts = await response.json(); + app.innerHTML = ''; + + for (const post of posts) { + const postHTML = ` +
+ avatar +
+
@${post.authorHandle}
+
${post.text || '
'}
+
${new Date(post.createdAt).toLocaleString()}
+
-
- `; - app.innerHTML += postHTML; + `; + app.innerHTML += postHTML; + } + } catch (err) { + app.innerHTML = `
error loading posts: ${err}
`; } -} catch (err) { - app.innerHTML = `
error loading posts: ${err}
`; -} \ No newline at end of file +} + +main(); -- cgit v1.2.3