updated styling

This commit is contained in:
Mike 2025-02-22 17:26:49 -05:00
parent d19e935069
commit 231902ab6d
11 changed files with 127 additions and 26 deletions

View file

@ -4,6 +4,17 @@
--desktop-line-height: 1; --desktop-line-height: 1;
--mobile-heading-font-size: 4em; --mobile-heading-font-size: 4em;
--mobile-line-height: 0.8; --mobile-line-height: 0.8;
/* colors */
--100-blue: hsl(219, 64%, 96%, 100%);
--200-blue: hsl(222, 81%, 94%, 100%);
--300-blue: hsl(221, 86%, 92%, 100%);
--400-blue: hsl(222, 92%, 90%, 100%);
--500-blue: hsl(222, 97%, 88%, 100%);
--600-blue: hsl(222, 97%, 85%, 100%);
--700-blue: hsl(222, 100%, 84%, 100%);
--800-blue: hsl(222, 100%, 34%, 100%);
} }
/* 1. Use a more-intuitive box-sizing model */ /* 1. Use a more-intuitive box-sizing model */
*, *,
@ -23,6 +34,7 @@ body {
/* 4. Improve text rendering */ /* 4. Improve text rendering */
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
font-family: "Lato, serif"; font-family: "Lato, serif";
background: var(--200-blue);
} }
/* 5. Improve media defaults */ /* 5. Improve media defaults */
@ -67,6 +79,10 @@ h6 {
text-wrap: balance; text-wrap: balance;
} }
a {
color: var(--800-blue);
}
/* /*
9. Create a root stacking context 9. Create a root stacking context
*/ */
@ -81,7 +97,7 @@ a {
nav { nav {
font-size: 1.5rem; font-size: 1.5rem;
margin: 1em 0 2em; padding: 1em 0;
} }
nav > ul { nav > ul {
@ -100,6 +116,10 @@ ul > li {
text-align: center; text-align: center;
} }
li a {
color: black;
}
form { form {
width: 100%; width: 100%;
max-width: 50vw; max-width: 50vw;
@ -109,6 +129,18 @@ input {
padding: 0.75em; padding: 0.75em;
} }
footer {
position: absolute;
bottom: 0;
}
.divider {
height: 0.25em;
background: var(--300-blue);
width: 80vw;
margin: 0 auto 1em;
}
.flex { .flex {
display: flex; display: flex;
} }
@ -227,6 +259,16 @@ input {
justify-content: space-between; justify-content: space-between;
} }
.likes {
flex: 1;
flex-grow: 0;
}
.card__likes {
padding: 0;
font-weight: 300;
}
.card .card__message { .card .card__message {
margin-bottom: 1em; margin-bottom: 1em;
} }
@ -261,7 +303,7 @@ input {
height: 2px; height: 2px;
bottom: 0; bottom: 0;
left: 0; left: 0;
background-color: black; background-color: var(--700-blue);
transform-origin: bottom left; transform-origin: bottom left;
transition: transform 0.25s ease-out; transition: transform 0.25s ease-out;
} }

View file

@ -3,7 +3,10 @@ const db = require("../models/query");
const { validationResult } = require("express-validator"); const { validationResult } = require("express-validator");
function loginGet(req, res, next) { function loginGet(req, res, next) {
res.render("login", { pageTitle: "InspiredCliches | Login" }); res.render("login", {
pageTitle: "InspiredCliches | Login",
errors: req.session.messages,
});
} }
function logOut(req, res, next) { function logOut(req, res, next) {

View file

@ -42,6 +42,19 @@ function addNotePost(req, res, next) {
res.redirect("/"); res.redirect("/");
} }
function deleteNote(req, res) {
const { messageId, userId } = req.query;
if (res.locals.currentUser) {
const message = db.getNoteById(messageId);
if (message.user_id === Number(userId)) {
db.deleteNote(Number(messageId));
}
res.redirect("/");
}
}
function addNoteGet(req, res, next) { function addNoteGet(req, res, next) {
res.render("note-form", { pageTitle: "InspiredCliches | New Note" }); res.render("note-form", { pageTitle: "InspiredCliches | New Note" });
} }
@ -69,6 +82,7 @@ module.exports = {
indexGet, indexGet,
addNoteGet, addNoteGet,
addNotePost, addNotePost,
deleteNote,
addLike, addLike,
getProfile, getProfile,
}; };

View file

@ -4,27 +4,33 @@ const LocalStrategy = require("passport-local");
const passport = require("passport"); const passport = require("passport");
passport.use( passport.use(
new LocalStrategy(async (username, password, done) => { new LocalStrategy(
try { { passReqToCallback: true },
const query = db.query(`SELECT * FROM users WHERE username = $1`); async (req, username, password, done) => {
const user = query.get({ $1: username }); try {
req.session.messages = [];
const query = db.query(`SELECT * FROM users WHERE username = $1`);
const user = query.get({ $1: username });
if (!user) { if (!user) {
return done(null, false, { return done(null, false, {
message: "Incorrect username or password.", message: "Incorrect username or password.",
}); });
}
const match = await bcryptjs.compare(password, user.password);
if (!match) {
return done(null, false, {
message: "Incorrect username or password.",
});
}
return done(null, user);
} catch (err) {
return done(err);
} }
},
const match = await bcryptjs.compare(password, user.password); ),
if (!match) {
return done(null, false, { message: "Incorrect username or password" });
}
return done(null, user);
} catch (err) {
return done(err);
}
}),
); );
passport.serializeUser((user, done) => { passport.serializeUser((user, done) => {

View file

@ -26,6 +26,17 @@ function putNewNote(note) {
query.run({ $1: message, $2: media, $3: userId, $4: date }); query.run({ $1: message, $2: media, $3: userId, $4: date });
} }
function deleteNote(messageId) {
try {
const query = db.query(`DELETE FROM likes WHERE message_id = $1`);
query.run({ $1: messageId });
const queryTwo = db.query(`DELETE FROM messages WHERE message_id = $1`);
queryTwo.run({ $1: messageId });
} catch (e) {
console.log(e);
}
}
function getLikesByUser(userId) { function getLikesByUser(userId) {
const query = db.query(`SELECT message_id FROM likes WHERE user_id = $1`); const query = db.query(`SELECT message_id FROM likes WHERE user_id = $1`);
@ -38,7 +49,9 @@ function getTotalLikesByMessageId(messageId) {
} }
function getNoteById(noteId) { function getNoteById(noteId) {
const query = db.query(`SELECT message from messages WHERE message_id = $1`); const query = db.query(
`SELECT message, user_id from messages WHERE message_id = $1`,
);
return query.get({ $1: noteId }); return query.get({ $1: noteId });
} }
@ -107,6 +120,7 @@ module.exports = {
putNewNote, putNewNote,
insertLike, insertLike,
deleteLike, deleteLike,
deleteNote,
checkIfNotedLiked, checkIfNotedLiked,
insertUser, insertUser,
getLikesByUser, getLikesByUser,

View file

@ -12,6 +12,7 @@ authRouter.post(
passport.authenticate("local", { passport.authenticate("local", {
successRedirect: "/", successRedirect: "/",
failureRedirect: "/auth/login", failureRedirect: "/auth/login",
failureMessage: true,
}), }),
); );
authRouter.get("/logout", authController.logOut); authRouter.get("/logout", authController.logOut);

View file

@ -8,5 +8,6 @@ indexRouter.get("/like", indexController.addLike);
indexRouter.get("/new", indexController.addNoteGet); indexRouter.get("/new", indexController.addNoteGet);
indexRouter.post("/new", indexController.addNotePost); indexRouter.post("/new", indexController.addNotePost);
indexRouter.get("/profile", indexController.getProfile); indexRouter.get("/profile", indexController.getProfile);
indexRouter.get("/delete", indexController.deleteNote);
module.exports = { indexRouter }; module.exports = { indexRouter };

View file

@ -13,12 +13,15 @@
<p class="card__message"><%= note.message %></p> <p class="card__message"><%= note.message %></p>
<div class="container flex grid__card__metadata"> <div class="container flex grid__card__metadata">
<p class="card__author"><a href="/profile?userId=<%= note.user_id %>"><%= note.user %></a></p> <p class="card__author"><a href="/profile?userId=<%= note.user_id %>"><%= note.user %></a></p>
<p><%= note.likes_count %> Likes</p> <div class="likes flex">
<a href="/like?noteId=<%= note.message_id %>"> <a href="/like?noteId=<%= note.message_id %>">
<% if (likedPost) { %><i class="fa-solid fa-heart red"></i><% } else { %><i class="fa-regular fa-heart red"></i><% }; %> <% if (likedPost) { %><i class="fa-solid fa-heart red"></i><% } else { %><i class="fa-regular fa-heart red"></i><% }; %>
</a> </a>
<p class="card__likes"><%= note.likes_count %></p>
</div>
<% if (currentUser.user_id === note.user_id) { %> <% if (currentUser.user_id === note.user_id) { %>
<a href="#">&nbsp;Delete</a> <a href="/delete?userId=<%= currentUser.user_id %>&messageId=<%= note.message_id %>">&nbsp;X</a>
<% }; %> <% }; %>
</div> </div>
</div> </div>

View file

@ -1,3 +1,6 @@
<footer>
<div> Test </div>
</footer>
<script src="/js/script.js"></script> <script src="/js/script.js"></script>
</body> </body>
</html> </html>

View file

@ -16,8 +16,12 @@
<body> <body>
<nav> <nav>
<ul class="container flex"> <ul class="container flex">
<li><a class="hover__underline" href="/">Home</a></li> <% if (!currentUser) { %>
<li><a class="hover__underline" href="/auth/register">Sign Up</a></li>
<% } %>
<% if (currentUser) { %> <% if (currentUser) { %>
<li><a class="hover__underline" href="/">Home</a></li>
<li><a class="hover__underline" href="/new" class="new-link">New Cliche</a></li> <li><a class="hover__underline" href="/new" class="new-link">New Cliche</a></li>
<li><a class="hover__underline" href="/profile?userId=<%= currentUser.user_id %>">Profile</a></li> <li><a class="hover__underline" href="/profile?userId=<%= currentUser.user_id %>">Profile</a></li>
<li><a class="hover__underline" href="/auth/logout">Logout</a></li> <li><a class="hover__underline" href="/auth/logout">Logout</a></li>
@ -26,4 +30,5 @@
<% }; %> <% }; %>
</ul> </ul>
</nav> </nav>
<div class="divider"></div>

View file

@ -1,4 +1,13 @@
<%- include('header') %> <%- include('header') %>
<% if (locals.errors) {%>
<div class="center-horizontal">
<ul>
<% errors.forEach(function(error) { %>
<li><%= error %></li>
<% }); %>
</ul>
</div>
<% }; %>
<form class="center-horizontal" method="POST" action="/auth/login"> <form class="center-horizontal" method="POST" action="/auth/login">
<div class="form-item flex"> <div class="form-item flex">
<label for="username">UserName</label> <label for="username">UserName</label>