Skip to content
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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ module.exports = {
'warn',
{ allowConstantExport: true },
],
"react/prop-types": 0
},
}
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,28 @@

# Happy thoughts Project

In this week's project, you'll be able to practice your React state skills by fetching and posting data to an API.
The purpose of this project was to create a web app where users can post happy thoughts, like others' posts, and see how long ago each thought was shared. The app shows the latest 20 messages, with each interaction updating the API data to ensure all users see the most recent posts and likes in real-time.

## Getting Started with the Project

### Dependency Installation & Startup Development Server
I created three main components, one that manages data fetching, posting, and updating thoughts in the UI. One for the posting form that allows users to submit a new happy thought, and one that renders the list of messages, likes, and timestamps.

Once cloned, navigate to the project's root directory and this project uses npm (Node Package Manager) to manage its dependencies.
### The Problem

The command below is a combination of installing dependencies, opening up the project on VS Code and it will run a development server on your terminal.
Data Management: Fetching and updating messages on load and upon posting required using useEffect and useState hooks. I also implemented a POST call to ensure the API updates with each new message.

```bash
npm i && code . && npm run dev
```
Accessibility: Styling was adjusted for readability and contrast, which led to a few deviations from the original design layout.

Responsive Styling: Ensuring responsive layout and consistent component spacing presented styling challenges.

### The Problem

Describe how you approached to problem, and what tools and techniques you used to solve it. How did you plan? What technologies did you use? If you had more time, what would be next?
If I had more time, I would:
- Refine styling for enhanced visual appeal.
- Add a character counter for message input, allowing a maximum of 140 characters.

### View it live

Every project should be deployed somewhere. Be sure to include the link to the deployed project so that the viewer can click around and see what it's all about.
Deployed link: https://fh-happythoughtsapp.netlify.app/

## Instructions

Expand Down
30 changes: 19 additions & 11 deletions index.html
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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

</head>

<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>

</html>
11 changes: 10 additions & 1 deletion src/App.jsx
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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One empty line is enough

166 changes: 166 additions & 0 deletions src/assets/components/DisplayThought.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
.thought-list {
list-style-type: none;
Copy link
Contributor

Choose a reason for hiding this comment

The 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;
}
}
58 changes: 58 additions & 0 deletions src/assets/components/DisplayThought.jsx
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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>
</>

);
};
Loading