forked from b00tc4mp/isdi-parttime-202403
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
189 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters