Skip to content

Commit

Permalink
implement app styles b00tc4mp#178
Browse files Browse the repository at this point in the history
  • Loading branch information
Debi312 committed Aug 27, 2024
1 parent adb7e14 commit baaf689
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 100 deletions.
2 changes: 1 addition & 1 deletion staff/debora-garcia/project/api/logic/getAllComments.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const getAllComments = (userId, postId) => {
return Comment.find({ post: postId }).lean()
.populate("author", "username")
.select("-__v")
.sort({ date: -1 })

.lean()
.catch(error => { throw new SystemError(error.message) })
.then(comments => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
}

.ResultsList-container {
@apply pt-[120px] pb-[90px]
@apply pt-[120px] pb-[90px]
}
.ResultsList article {
@apply flex flex-col w-full min-h-[60px] bg-white items-center pt-1 mb-5 rounded-[8px] border-solid border-[--fourth-color] border-[1px];;
@apply flex flex-col w-full h-[60px] bg-white items-center pt-1 mb-5 rounded-[8px] border-solid border-[--fourth-color] border-[1px];;
}

.ResultsList .result-header {
@apply flex gap-[1rem] w-full justify-between p-[0_1rem] items-center ;
@apply flex gap-[1rem] w-full justify-between p-[0_1rem] items-center m-0 ;
}

.ResultsList .result-details-container{
@apply flex flex-row w-full h-[40px] justify-between p-[0_1rem];
@apply flex flex-row w-full justify-between p-[0_1rem] ;
}
.ResultsList .result-details{
@apply flex flex-row flex-nowrap w-full ;
.result-details{
@apply flex flex-row flex-nowrap self-end w-full ;
}
.ResultsList .edit-resultButton{
@apply flex flex-row w-full justify-end ;
Expand Down
47 changes: 31 additions & 16 deletions staff/debora-garcia/project/app/src/views/Feed/Comments.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,46 @@

@layer components {
.Comments {
@apply fixed w-[300px] bottom-[100px] left-1/2 transform -translate-x-1/2 bg-white p-[10px] shadow-lg rounded-md;
@apply fixed w-[300px] h-[400px] bottom-[100px] left-1/2 transform -translate-x-1/2 bg-slate-500 p-[10px] shadow-lg rounded-md;
}

.form-buttons-container {
display: flex;
justify-content: center;
gap: 10px;
margin-top: 20px;
.comments-header {
@apply flex flex-row justify-between items-center;
}
.comments-container {
@apply flex flex-col h-full;
}

.form-buttons-container Button:hover {
@apply bg-[#65524d];
.CommentsList {
@apply flex flex-col flex-grow overflow-y-auto;
}
.CreateComment .Field {
@apply m-1 p-[.02rem] w-full;

.comment-form-container {
@apply flex flex-row pt-2 justify-between;
}

.cancel-button {
@apply text-[red] py-2 px-4 rounded-md;
.Comments .comment-form {
@apply flex justify-between;
}

.comment-form .Field {
@apply m-1 p-2 w-full;
}

.submit-comment-button {
@apply bg-[#a2918d] py-2 px-4 rounded-md;
}

.cancel-comment-button {
@apply bg-[#a2918d] p-[5px_10px] m-0 rounded-md;
}

.form-buttons-container Button{
@apply bg-[#a2918d]
.cancel-button {
@apply text-red-600 py-2 px-4 rounded-md;
}

.comment-form input::placeholder {
@apply text-[15px] tracking-[-0.01rem];
word-spacing: -5px;
}

}
}
50 changes: 31 additions & 19 deletions staff/debora-garcia/project/app/src/views/Feed/Comments.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useParams } from "react-router-dom";
import { useState, useEffect } from "react";


export default function Comments({ postId }) {
export default function Comments({ postId, onCancelCommentsClick, author }) {
console.log("Comments -> render")

const [comments, setComments] = useState([])
Expand All @@ -30,7 +30,6 @@ export default function Comments({ postId }) {
}
}


const handleCreateCommentSubmit = (event) => {
event.preventDefault()
const form = event.target
Expand All @@ -46,29 +45,42 @@ export default function Comments({ postId }) {
console.error(error)
}
}
console.log(comments)

const handleCancelCreateComment = () => {
onCancelCommentsClick()
}

return (

<div>
<form className="CreateCommentForm" onSubmit={handleCreateCommentSubmit}>
<Field id="text" type="text" placeholder="Add a comment" />
<div className="form-buttons-container">
<Button type="submit" className="comment-button">Send</Button>
</div>
</form>
<form className="Comments" onSubmit={handleCreateCommentSubmit}>

<div className="CommentsList">
{comments.length === 0 ? (
<p>No comments yet</p>
) : (
comments.map(comment => (
<div key={comment.id} className="comment">
<p>{comment.text}</p>
<div className="comments-container">
<div className="comments-header">
<h6>Comments</h6>
<p> <Button type="button" className="cancel-comment-button" onClick={handleCancelCreateComment}></Button></p>
</div>
<div className="CommentsList">
{comments.length === 0 ? (
<p>No comments yet</p>
) : (
comments.map(comment => (
<div key={comment.id} className="comment">
<p>{comment.text}</p>
</div>
))
)}
</div>

<div className="comment-form-container">

<div className="comment-form">
<Field id="text" type="text" placeholder={`Add a comment to ${author}...`} />
<Button type="submit" className="submit-comment-button">✉️</Button>
</div>
))
)}
</div>
</div>
</div>
</form>
</div>
)

Expand Down
45 changes: 45 additions & 0 deletions staff/debora-garcia/project/app/src/views/Feed/Post.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@tailwind components;

@layer components {
.comment-button {
@apply text-3xl;
}
.like-button {
@apply text-3xl;
}

.post-footer {
@apply flex;
}

Button .post-footer-buttons {
@apply flex flex-row justify-between;
}

.Post {
@apply flex flex-col w-[350px];
}

.Post-container {
@apply pt-[90px] pb-[90px];
}
article {
@apply flex flex-col bg-white items-center p-[10px_0] mb-5 rounded-[8px];
}

.Post .post-header {
@apply flex gap-[1rem] w-full justify-between p-[1rem] items-center;
}
.post-image {
@apply flex max-h-[20rem] max-w-[20rem];
}
.post-body {
@apply flex flex-col min-w-[20rem];
}
.post-movements {
@apply flex flex-col w-full justify-start pt-[0.5rem];
}
.Post .result-details {
@apply flex w-full justify-start p-[0.3rem_1rem] font-bold;
}
}
70 changes: 68 additions & 2 deletions staff/debora-garcia/project/app/src/views/Feed/Post.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,70 @@
import { useEffect, useState } from "react"
import logic from "../../logic"
import Heading from "../../components/Heading"
import "./Post.css"
import Button from "../../components/Button"
import Comments from "./Comments"
export default function Post({ post, onPostLikeToggled }) {

const [commentsSectionVisible, setCommentsSectionVisible] = useState(false)

const handleToggleLikePost = (post) => {
try {
logic.toggleLikePost(post.id)
.then(() => onPostLikeToggled())
.catch(error => {
console.error(error)

alert(error.message)
})
} catch (error) {
console.error(error)

alert(error.message)
}
}

const handleCancelCommentsClick = () => {
setCommentsSectionVisible(false)
}

return (
<article key={post.id} >
<div className="post-header">
<Heading level={6} className="Heading">{post.author.username}</Heading>
<time>{new Date(post.date).toLocaleDateString()}</time>
</div>
<div className="post-body">
<img src={post.image} alt={post.description} className="post-image" />
<p>{post.description}</p>
<br />

<h6>{post.workout.workoutType.toUpperCase()}</h6>
<h6>{post.workout.title}</h6>
<ul className="post-movements">
{post.workout.movements.map((movement, index) => (
<li key={index}>{movement.quantity} {movement.name}</li>
))}
</ul>
</div>
<div className="result-details">
<p>
{post.result?.time && `Time:${post.result.time} `}
{post.result?.repetitions && `${post.result.repetitions}reps `}
{post.result?.weight && `${post.result.weight}kg`}
</p>
</div>
<div className="post-footer">
<div className="post-footer-buttons">
<Button onClick={() => handleToggleLikePost(post)} className="like-button">
{`${post.likes.includes(logic.getUserId()) ? "♥︎" : "♡"} ${post.likes.length > 0 ? `${post.likes.length}` : ""}`}
</Button>
<Button onClick={() => setCommentsSectionVisible(!commentsSectionVisible)} className="comment-button"></Button>
</div>
{commentsSectionVisible && <Comments postId={post.id} author={post.author.username} onCancelCommentsClick={handleCancelCommentsClick} />}

</div>
</article>
)

export default function Post() {

}
63 changes: 7 additions & 56 deletions staff/debora-garcia/project/app/src/views/Feed/PostList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Heading from "../../components/Heading"
import "./PostList.css"
import Button from "../../components/Button"
import Comments from "./Comments"
import Post from "./Post"
export default function PostList() {
console.log("PostList ->render")

Expand All @@ -18,74 +19,24 @@ export default function PostList() {
try {
logic.getPosts()
.then((posts) => {
console.log("PostList -> setPosts")
setPosts(posts)
})
.catch(error => alert(error.message))
} catch (error) {
console.error(error)
alert(error.message)
}
}

const handleToggleLikePost = (post) => {
try {
logic.toggleLikePost(post.id)
.then(() => loadPosts())
.catch(error => {
console.error(error)

alert(error.message)
})
} catch (error) {
console.error(error)

alert(error.message)
}
const handlePostLikeToggled = () => {
loadPosts()
}


return <div className="PostList">
<div className="PostList-container">
{posts.map(post => <article key={post.id} >
<div className="post-header">
<Heading level={6} className="Heading">{post.author.username}</Heading>
<time>{new Date(post.date).toLocaleDateString()}</time>
</div>
<div className="post-body">
<img src={post.image} alt={post.description} className="post-image" />
<p>{post.description}</p>
<br />

<h6>{post.workout.workoutType.toUpperCase()}</h6>
<h6>{post.workout.title}</h6>
<ul className="post-movements">
{post.workout.movements.map((movement, index) => (
<li key={index}>{movement.quantity} {movement.name}</li>
))}
</ul>
</div>
<div className="result-details">
<p>
{post.result?.time && `Time:${post.result.time} `}
{post.result?.repetitions && `${post.result.repetitions}reps `}
{post.result?.weight && `${post.result.weight}kg`}
</p>
</div>
<div className="post-footer">

<Button onClick={() => handleToggleLikePost(post)}>
{`${post.likes.includes(logic.getUserId()) ? '❤️' : '🤍'} ${post.likes.length} like${post.likes.length === 1 ? '' : 's'}`}
</Button>

<div>
<Button onClick={() => handleToggleComments(post.id)}></Button>
</div>

<div>
<Comments postId={post.id} />
</div>


</div>
</article>)}
{posts.map(post => <Post key={post.id} post={post} onPostLikeToggled={handlePostLikeToggled} />)}
</div>
</div>

Expand Down

0 comments on commit baaf689

Please sign in to comment.