Skip to content

Commit

Permalink
adding if user not logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
EliNygard committed May 22, 2024
1 parent cfd1d26 commit ad45894
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions post/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,31 @@ import { generatePostPageHtml } from "../javascript/generateHtml/postPageHtml.mj
import { hideLoader, showLoader } from "../javascript/ui/loader.mjs";

async function renderBlogPostPage(url) {
showLoader();
const responseData = await getPosts(url);
console.log(responseData);
const singlePost = responseData.data;
console.log(singlePost);

try {
// Promise for testing loader, REMOVE
// await new Promise((resolve) => setTimeout(resolve, 1000));
const responseData = await getPosts(url);
console.log(responseData);
const singlePost = responseData.data;
console.log(singlePost);
const main = document.querySelector("main");
// main.innerHTML = '';
const blogPost = generatePostPageHtml(singlePost);
main.appendChild(blogPost);
}

const main = document.querySelector("main");
// main.innerHTML = '';
const blogPost = generatePostPageHtml(singlePost);
main.appendChild(blogPost);
} catch (error) {
console.error("Error", error);
async function main() {
const userName = JSON.parse(localStorage.getItem("userName"));
showLoader();
try {
if (userName) {
await renderBlogPostPage(API_BASE + API_POSTS + API_NAME + API_ID);
} else {
// If user is not logged in:
await renderBlogPostPage(API_BASE + API_POSTS + "/Leli_Nygard" + API_ID);
}
} catch {
console.error(error);
} finally {
hideLoader();
}
}

await renderBlogPostPage(API_BASE + API_POSTS + API_NAME + API_ID);
main();

0 comments on commit ad45894

Please sign in to comment.