Add article creation frontend

This commit is contained in:
Bruno Rybársky 2024-02-22 10:43:18 +01:00
parent 5be90d8e95
commit ac95ba5b60
3 changed files with 55 additions and 1 deletions

@ -173,6 +173,28 @@ async function initAjax() {
await onPageLoad(); await onPageLoad();
} }
async function togglearticlecreate(){
let articleContainerElement = document.getElementById("articlecreatecontainer");
articleContainerElement.classList.toggle("hidden");
}
async function submitarticle(){
let articleTitleElement = document.getElementById("articletitleinput");
let articleBodyElement = document.getElementById("articlebodyinput");
await doAction("/newsarticle", {
action: "addNewsArticle",
title: articleTitleElement,
body: articleBodyElement
});
}
async function articleInit(){
let articleSubmitElement = document.getElementById("articlesubmit");
await togglearticlecreate();
articleSubmitElement.addEventListener("click", submitarticle);
}
async function onPageLoad() { async function onPageLoad() {
await restoreUserInfo(); await restoreUserInfo();
let currentSite = localStorage.getItem("currentSite"); let currentSite = localStorage.getItem("currentSite");
@ -189,6 +211,9 @@ async function onPageLoad() {
if (currentSite === "home" && currentPage === "account" && isLoggedIn()) { if (currentSite === "home" && currentPage === "account" && isLoggedIn()) {
await showDashboardGreeting(); await showDashboardGreeting();
} }
if (currentSite === "news" && currentPage === "index" && isLoggedIn()) {
await articleInit();
}
} }
async function navigateTo(site, page) { async function navigateTo(site, page) {

@ -365,3 +365,21 @@ body:has(.ye-span:hover) {
background-repeat: repeat !important; background-repeat: repeat !important;
background-size: 10% !important; background-size: 10% !important;
} }
#articlecreate {
position: fixed;
border: 5px solid var(--primary);
z-index: 5;
}
#articlecreatecontainer{
position: fixed;
width: 100vw;
height: 100vh;
z-index: 4;
backdrop-filter: blur(2px);
}
.hidden {
display: none !important;
}

@ -1,6 +1,17 @@
<header> <header>
<h1 class="title"></h1> <h1 class="title"></h1>
<p>Adlerka študentské news</p> <p>Adlerka študentské news</p>
<button id="articlecreateopen" onclick="togglearticlecreate()"><i class="ri-add-circle-line"></i></button>
<hr> <hr>
__TEMPLATE__ARTICLES_HERE__
</header> </header>
<div id="articleslist">
__TEMPLATE__ARTICLES_HERE__
</div>
<div id="articlecreatecontainer" class="hidden">
<div id="articlecreate">
<input type="text" placeholder="Article Title" id="articletitleinput"><br>
<textarea id="articlebodyinput" placeholder="Article Body"></textarea><br>
<button id="articlesubmit" onclick="submitArticle()"></button>
</div>
</div>