Make it autorefresh

This commit is contained in:
Bruno Rybársky 2024-02-22 14:08:55 +01:00
parent 4b288b48c8
commit cd46a52f83

@ -1,4 +1,5 @@
let UserInfo = {};
let PageIntervals = [];
function isLoggedIn(){
return UserInfo.Email && UserInfo.Email.length > 0;
@ -179,8 +180,23 @@ async function togglearticlecreate(){
articleContainerElement.classList.toggle("hidden");
}
async function renderarticle(articledata){
async function renderarticles(){
let template = document.querySelector('template[data-template-name="article"]').content.toString();
let articles = await doAction(
"/newsarticle",
{
action: "getNewsArticles"
},
"Články načítané",
"Nastala chyba pri načítavaní článkov",
true
);
let articleout = "";
for (const article of articles) {
articleout += template.replace("__TEMPLATE_ARTICLE_TITLE__", article.Title).replace("__TEMPLATE_ARTICLE_AUTHOR__", article.WrittenByName).replace("__TEMPLATE_ARTICLE_DATE__", article.WrittenAt).replace("__TEMPLATE_ARTICLE_BODY__", article.Body)
}
document.getElementById("articleslist").innerHTML = articleout;
}
async function submitarticle(){
@ -206,12 +222,18 @@ async function articleInit(){
togglearticlecreate();
}
})
PageIntervals.push(setInterval(renderarticles, 300000));
}
async function onPageLoad() {
await restoreUserInfo();
let currentSite = localStorage.getItem("currentSite");
let currentPage = localStorage.getItem("currentPage");
for(let interval of PageIntervals) {
clearInterval(interval);
}
if (currentSite === "home" && currentPage === "settings") {
if (document.getElementById("user-settings")) {
await populateUserInfoFields(UserInfo);