-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fannys happy-thought-app #101
base: main
Are you sure you want to change the base?
Changes from all commits
fddcaf8
860af8c
ea4eca8
5719f79
0dcbca4
f7e8967
3b0cbb9
df1b9a8
40eb00e
431d03e
6396182
6faf312
123ac92
0f3cf89
0bbe791
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,5 +16,6 @@ module.exports = { | |
'warn', | ||
{ allowConstantExport: true }, | ||
], | ||
"react/prop-types": 0 | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Happy Thought - Project - Week 7</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.jsx"></script> | ||
</body> | ||
</html> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0"> | ||
<link rel=" preconnect" href="https://fonts.googleapis.com"> | ||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> | ||
<link | ||
href="https://fonts.googleapis.com/css2?family=Inconsolata:[email protected]&family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap" | ||
rel="stylesheet"> | ||
<title>Fannys Happy Thought App</title> | ||
</head> | ||
|
||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.jsx"></script> | ||
</body> | ||
|
||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
import { ThoughtPage } from "./assets/components/ThoughtPage.jsx" | ||
|
||
export const App = () => { | ||
return <div>Find me in src/app.jsx!</div>; | ||
return ( | ||
<> | ||
<ThoughtPage /> | ||
</> | ||
Comment on lines
+5
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for React fragment if you're only returning one element |
||
); | ||
}; | ||
|
||
|
||
|
||
Comment on lines
+10
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One empty line is enough |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
.thought-list { | ||
list-style-type: none; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please set your VSC so one tab = 2 spaces. It gets easier to read |
||
display: flex; | ||
flex-direction: column; | ||
gap: 30px; | ||
margin-top: 30px; | ||
padding: 0; | ||
} | ||
|
||
.thought-display { | ||
width: 500px; | ||
height: 150px; | ||
padding-left: 20px; | ||
padding-right: 20px; | ||
border: 1px solid black; | ||
box-sizing: border-box; | ||
overflow-x: hidden; | ||
box-shadow: 7px 7px; | ||
position: relative; | ||
|
||
} | ||
|
||
.info-like-container { | ||
margin-left: 0; | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: flex-start; | ||
gap: 225px; | ||
position: absolute; | ||
bottom: 10px; | ||
flex-wrap: wrap; | ||
} | ||
|
||
.like-container { | ||
display: flex; | ||
gap: 5px; | ||
} | ||
|
||
.like-container button { | ||
width: 55px; | ||
padding: 15px; | ||
border: none; | ||
border-radius: 100%; | ||
font-size: 17px; | ||
background-color: #ededed; | ||
; | ||
} | ||
|
||
.like-container p { | ||
opacity: 0.6; | ||
} | ||
|
||
.info-like-container button:hover { | ||
transition: 0.3s; | ||
background-color: #ff9696; | ||
|
||
} | ||
|
||
.info-container { | ||
opacity: 0.6; | ||
} | ||
|
||
@media (min-width:436px) and (max-width:550px) { | ||
|
||
.thought-display { | ||
margin: 0 auto; | ||
width: 400px; | ||
height: 150px; | ||
padding-top: 0px; | ||
padding-left: 15px; | ||
padding-right: 15px; | ||
} | ||
|
||
.info-like-container { | ||
margin-top: 10px; | ||
display: flex; | ||
gap: 175px; | ||
} | ||
|
||
.like-container button { | ||
width: 45px; | ||
height: 45px; | ||
padding: 10px; | ||
font-size: 13px; | ||
} | ||
|
||
.like-container p { | ||
margin-top: 17px; | ||
font-size: 13px; | ||
} | ||
|
||
.info-container { | ||
font-size: 13px; | ||
} | ||
} | ||
|
||
@media (max-width:435px) { | ||
.thought-display { | ||
margin: 0 auto; | ||
width: 320px; | ||
height: 120px; | ||
padding-top: 0px; | ||
padding-left: 15px; | ||
padding-right: 15px; | ||
} | ||
|
||
.thought-display p { | ||
margin-top: 14px; | ||
font-size: 12px; | ||
} | ||
|
||
.info-like-container { | ||
margin-top: 10px; | ||
display: flex; | ||
gap: 120px; | ||
} | ||
|
||
.like-container button { | ||
margin-top: 5px; | ||
width: 36px; | ||
height: 36px; | ||
padding: 9px; | ||
font-size: 13px; | ||
} | ||
|
||
.like-container p { | ||
margin-top: 17px; | ||
font-size: 12px; | ||
} | ||
|
||
.info-container { | ||
font-size: 11px; | ||
} | ||
} | ||
|
||
@media (min-width:300px) and (max-width:345px) { | ||
.thought-display { | ||
width: 300px; | ||
height: 110px; | ||
} | ||
|
||
.thought-display p { | ||
margin-top: 14px; | ||
font-size: 12px; | ||
} | ||
|
||
.info-like-container { | ||
gap: 100px; | ||
} | ||
|
||
.like-container button { | ||
width: 36px; | ||
height: 34px; | ||
font-size: 13px; | ||
} | ||
|
||
.like-container p { | ||
margin-top: 17px; | ||
font-size: 13px; | ||
} | ||
|
||
.info-container { | ||
margin-top: 10px; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//Child-component that retrieves the list of happy thoughts from the API and display them. | ||
|
||
import "./DisplayThought.css" | ||
|
||
export const DisplayThoughts = ({ happyThoughts, isLoading, postLike }) => { | ||
if (isLoading) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here - hard to read with this super big indentation 😅 |
||
return <p>Loading thoughts...</p>; | ||
} | ||
|
||
|
||
// Function to convert the "time ago" for each thought to seconds, minutes, hours or days. | ||
const timeAgo = (createdAt) => { | ||
const now = new Date(); | ||
const timeDifference = Math.floor((now - new Date(createdAt)) / 1000); | ||
if (timeDifference < 60) { | ||
return `${timeDifference} seconds ago`; | ||
} else if (timeDifference < 3600) { | ||
const minutes = Math.floor(timeDifference / 60); | ||
return `${minutes} minutes ago`; | ||
} else if (timeDifference < 86400) { | ||
const hours = Math.floor(timeDifference / 3600); | ||
return `${hours} hours ago`; | ||
} else { // More than a day | ||
const days = Math.floor(timeDifference / 86400); | ||
return `${days} days ago`; | ||
} | ||
}; | ||
|
||
const onClick = (thought) => { | ||
postLike(thought._id) | ||
} | ||
|
||
|
||
|
||
return ( | ||
<> | ||
<ul className="thought-list"> | ||
{happyThoughts.map((thought) => ( | ||
<li key={thought._id} className="thought-item"> | ||
<div className="thought-display"> | ||
<p>{thought.message}</p> | ||
<div className="info-like-container"> | ||
<div className="like-container" onClick={() => onClick(thought)}> | ||
<button>❤️</button> | ||
<p>x {thought.hearts}</p> | ||
</div> | ||
<div className="info-container"> | ||
<p>{timeAgo(thought.createdAt)} ago</p> | ||
</div> | ||
</div> | ||
</div> | ||
</li> | ||
))} | ||
</ul> | ||
</> | ||
|
||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⭐