Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions front-end/components/logout.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {apiService} from "../index.mjs";
import { apiService } from "../index.mjs";
import { state } from "../index.mjs";

/**
* Create a logout component
Expand All @@ -14,11 +15,15 @@ function createLogout(template, isLoggedIn) {
}

async function handleLogout(event) {
event.preventDefault();
try {
apiService.logout();
} catch (error) {
throw error;
} finally {
state.isLoggedIn = false;
state.user = null;

window.location.hash = "#/";
}
}

export {createLogout, handleLogout};
export { createLogout, handleLogout };
22 changes: 9 additions & 13 deletions front-end/index.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Purple Forest</title>
<link href="/index.css" rel="stylesheet" />
<link href="./index.css" rel="stylesheet" />
</head>
<body id="app">
<header>
<a href="/"
><h1>
<img
src="/logo.svg"
alt="Purple Forest "
width="50"
height="60"
/>
<img src="./logo.svg" alt="Purple Forest " width="50" height="60" />
PurpleForest
</h1></a
>
Expand Down Expand Up @@ -43,7 +38,7 @@ <h3>This Legacy Code project is coursework from Code Your Future</h3>
<!-- Login Component Template -->
<template id="login-template">
<section aria-label="Log in or sign up" class="login">
<form data-form="login" class="login__form" method="post">
<form data-form="login" class="login__form">
<div class="login__field">
<label class="login__label is-invisible" for="username"
>Username</label
Expand Down Expand Up @@ -189,8 +184,7 @@ <h1 id="signup-heading" class="signup__title">Create your account</h1>
</div>
<div class="profile__who-to-follow">
<h4>Who to follow</h4>
<ul data-who-to-follow>
</ul>
<ul data-who-to-follow></ul>
</div>
</section>
</template>
Expand Down Expand Up @@ -236,7 +230,9 @@ <h2 id="bloom-form-title" class="bloom-form__title">Share a Bloom</h2>
<article class="bloom box" data-bloom data-bloom-id="">
<div class="bloom__header flex">
<a href="#" class="bloom__username" data-username>Username</a>
<a href="#" class="bloom__time"><time class="bloom__time" data-time>2m</time></a>
<a href="#" class="bloom__time"
><time class="bloom__time" data-time>2m</time></a
>
</div>
<div class="bloom__content" data-content></div>
</article>
Expand All @@ -256,6 +252,6 @@ <h2 id="bloom-form-title" class="bloom-form__title">Share a Bloom</h2>
<p>Please enable JavaScript in your browser.</p>
</noscript>

<script type="module" src="/index.mjs"></script>
<script type="module" src="./index.mjs"></script>
</body>
</html>
22 changes: 11 additions & 11 deletions front-end/views/hashtag.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {renderOne, renderEach, destroy} from "../lib/render.mjs";
import { renderOne, renderEach, destroy } from "../lib/render.mjs";
import {
state,
apiService,
Expand All @@ -7,10 +7,10 @@ import {
getTimelineContainer,
getHeadingContainer,
} from "../index.mjs";
import {createLogin, handleLogin} from "../components/login.mjs";
import {createLogout, handleLogout} from "../components/logout.mjs";
import {createBloom} from "../components/bloom.mjs";
import {createHeading} from "../components/heading.mjs";
import { createLogin, handleLogin } from "../components/login.mjs";
import { createLogout, handleLogout } from "../components/logout.mjs";
import { createBloom } from "../components/bloom.mjs";
import { createHeading } from "../components/heading.mjs";

// Hashtag view: show all tweets containing this tag

Expand All @@ -23,7 +23,7 @@ function hashtagView(hashtag) {
state.isLoggedIn,
getLogoutContainer(),
"logout-template",
createLogout
createLogout,
);
document
.querySelector("[data-action='logout']")
Expand All @@ -32,24 +32,24 @@ function hashtagView(hashtag) {
state.isLoggedIn,
getLoginContainer(),
"login-template",
createLogin
createLogin,
);
document
.querySelector("[data-action='login']")
?.addEventListener("click", handleLogin);
?.addEventListener("submit", handleLogin);

renderOne(
state.currentHashtag,
getHeadingContainer(),
"heading-template",
createHeading
createHeading,
);
renderEach(
state.hashtagBlooms || [],
getTimelineContainer(),
"bloom-template",
createBloom
createBloom,
);
}

export {hashtagView};
export { hashtagView };