forked from FIFA-Corp/incognitalk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
30 lines (26 loc) · 788 Bytes
/
index.js
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
import { createPost } from "./module/posts/create-post.js";
import { getPost } from "./module/posts/get-post.js";
const formElement = document.querySelector('form');
const postSectionElement = document.getElementsByClassName('post-section')[0];
const renderPost = async () => {
const posts = await getPost();
postSectionElement.innerHTML = posts.reverse().map(({ post }) => {
return `
<div>
<h1>${post}</h1>
</div>
`
}).join("")
}
formElement.addEventListener('submit', async (event) => {
try {
event.preventDefault();
const form = new FormData(formElement);
const postValue = form.get('post');
const addPost = await createPost(postValue);
renderPost();
} catch (error) {
console.error(error.message);
}
})
renderPost();