-
Notifications
You must be signed in to change notification settings - Fork 30
/
write.js
44 lines (38 loc) · 1.72 KB
/
write.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Function to create a new journal
function createJournal(event) {
event.preventDefault();
const journalForm = document.getElementById('journal-form');
const journalTitle = journalForm.elements['journalTitle'].value;
const journalContent = journalForm.elements['journalContent'].value;
const journalImage = journalForm.elements['journalImage'].files[0];
const publicCheck = journalForm.elements['publicCheck'].checked;
// Create a new card to display the journal details
const card = document.createElement('div');
card.classList.add('card', 'journal-card', 'mb-4');
card.innerHTML = `
<img src="${journalImage ? URL.createObjectURL(journalImage) : 'images/cards.jpg'}" class="card-img-top" alt="Journal Image">
<div class="card-body">
<h5 class="card-title">${journalTitle}</h5>
<p class="card-text">${journalContent}</p>
<hr />
<p class="card-text text-end">${publicCheck ? 'Public' : 'Private'}</p>
</div>
`;
// Add the new card to the published journals container
const publishedJournals = document.getElementById('publishedJournals');
publishedJournals.appendChild(card);
// console.log(publishedJournals);
const journalData = {
title: journalTitle,
content: journalContent,
image: journalImage ? URL.createObjectURL(journalImage) : null,
isPublic: publicCheck
};
// console.log(journalData);
localStorage.setItem('journalData', JSON.stringify(journalData));
// Reset the form fields
journalForm.reset();
}
// Event listener for the form submission
const journalForm = document.getElementById('journal-form');
journalForm.addEventListener('submit', createJournal);