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

Happy-thoughts-Ajmal #448

Open
wants to merge 14 commits into
base: master
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
4 changes: 2 additions & 2 deletions code/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"import/no-unresolved": "off",
"import/prefer-default-export": "off",
"indent": [
"error",
"off",
2,
{
"SwitchCase": 1
Expand Down Expand Up @@ -128,4 +128,4 @@
"react-hooks/exhaustive-deps": "warn",
"semi": "off"
}
}
}
18 changes: 18 additions & 0 deletions code/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"dependencies": {
"babel-eslint": "^10.1.0",
"date-fns": "^2.29.3",
"eslint": "^8.21.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-plugin-import": "^2.26.0",
Expand Down
24 changes: 12 additions & 12 deletions code/public/index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!--
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Expand All @@ -13,13 +13,13 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Technigo React App</title>
</head>
<title>Happy thoughts</title>
</head>

<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

Expand All @@ -29,6 +29,6 @@
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</body>

</html>
</html>
45 changes: 42 additions & 3 deletions code/src/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,48 @@
import React from 'react';
/* eslint-disable max-len */
/* eslint-disable no-unused-vars */
import React, { useState, useEffect } from 'react';
import ThoughtList from 'components/ThoughtList';
import ThoughtForm from 'components/ThoughtForm';

export const App = () => {
const [thoughts, setThoughts] = useState([]);
const [newThought, setNewThought] = useState('')

const fetchMessage = () => {
fetch('https://project-happy-thoughts-api-eihxehjbzq-lz.a.run.app/thoughts', {
method: 'GET'
})
.then((res) => res.json())
.then((data) => {
setThoughts(data.response)
}).catch((error) => console.log(error))
}
const sendMessage = (event) => {
event.preventDefault()
fetch('https://project-happy-thoughts-api-eihxehjbzq-lz.a.run.app/thoughts', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: newThought, createdAt: Date.now() })
})
.then(() => setNewThought(''))
.catch((error) => console.log(error))
}

const sendLike = (_id) => {
fetch(`https://project-happy-thoughts-api-eihxehjbzq-lz.a.run.app/thoughts/${_id}/like`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' }
}).catch((error) => console.log(error))
}

useEffect(() => {
fetchMessage();
});

return (
<div>
Find me in src/app.js!
<div className="content">
<ThoughtForm newThought={newThought} setNewThought={setNewThought} onFormSubmit={sendMessage} />
<ThoughtList thoughts={thoughts} sendLike={sendLike} />
</div>
);
}
Binary file added code/src/bgImg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions code/src/components/MessageCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import { formatDistance } from 'date-fns';

const MessageCard = ({ item, sendLike }) => {
const sendHearts = () => {
// eslint-disable-next-line no-underscore-dangle
sendLike(item._id)
}
return (
<div className="messageCard">
<p>{item.message}</p>
<div className="heartRow">
<div className="heartBtnSection">
<button className="heartBtn" type="button" onClick={sendHearts}> ❤️ </button> x {item.likes}
</div>
<p className="timeStamp">
{formatDistance(new Date(item.createdAt), Date.now(), { addSuffix: true })}
</p>
</div>
</div>
);
}

export default MessageCard
15 changes: 15 additions & 0 deletions code/src/components/ThoughtForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';

const ThoughtForm = ({ newThought, setNewThought, onFormSubmit }) => {
return (
<div className="textBox">
<form className="textArea" onSubmit={onFormSubmit}>
<h1>What makes you happy?</h1>
<textarea value={newThought} onChange={(event) => setNewThought(event.target.value)} className="inputField" type="text" placeholder="Share some happy toughts..." cols="50" rows="5" />
<button className="sendBtn" type="submit">❤️Send happy toughts❤️</button>
</form>
</div>
)
}

export default ThoughtForm
15 changes: 15 additions & 0 deletions code/src/components/ThoughtList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable max-len */
/* eslint-disable indent */
import React from 'react';
import MessageCard from './MessageCard';

const ThoughtList = ({ thoughts, sendLike }) => {
return (
<div className="messageList">
{thoughts.map((item) => <MessageCard item={item} sendLike={sendLike} />)}
</div>
)
}

export default ThoughtList

97 changes: 96 additions & 1 deletion code/src/index.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,108 @@
@import url('https://fonts.googleapis.com/css2?family=VT323&display=swap');

body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
font-family: 'VT323', monospace, -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
background: radial-gradient(circle, rgba(238, 174, 202, 1) 0%, rgba(148, 187, 233, 1) 100%);
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
monospace;
}

.textArea {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
background: #dae0e6;
width: 467px;
box-shadow: 5px 10px;
}

.textBox {
display: flex;
align-items: center;
justify-content: center;
margin: 40px;
}

.inputField {
resize: none;
outline: none;
border: 1px solid;
padding: 10px;
background: aliceblue;
width: 390px;
font-size: 16px;
font-family: 'VT323', monospace, -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
sans-serif;
}

.messageCard {
border: 1px solid;
padding: 10px;
box-shadow: 5px 10px;
background: aliceblue;
width: 445px;
}

.messageList {
display: flex;
flex-direction: column;
align-items: center;
gap: 25px;
overflow-wrap: break-word;
margin-bottom: 100px;
}

.sendBtn {
margin: 15px;
font-family: 'VT323', monospace, -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
sans-serif;
border-radius: 10px;
height: 40px;
width: 180px;
font-size: 15px;
}

.sendBtn:hover {
background-color: rgba(255, 173, 173, 255);
}

.timeStamp {
text-align: end;
}

.heartRow {
display: flex;
justify-content: space-between;
align-items: center;
}

.heartBtn {
height: 30px;
width: 30px;
border-radius: 50%;
border: none;
background: rgba(234, 234, 234, 255);
}

.heartBtn:hover {
background-color: rgba(255, 173, 173, 255);
}

.heartBtn:active {
background: rgba(255, 173, 173, 255);
}

.heartBtn:focus {
background: rgba(255, 173, 173, 255);
}
1 change: 1 addition & 0 deletions code/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { createRoot } from 'react-dom/client';
import './index.css';
import './responsive.css'
import { App } from './App';

const container = document.getElementById('root');
Expand Down
52 changes: 52 additions & 0 deletions code/src/responsive.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@media screen and (max-width: 800px) {

/*Mobile*/
.messageCard {
width: 80%;
margin-bottom: 25px;
}

.textBox {
scale: 80%;
}

.inputField {
scale: 90%;
}

.heartBtn {
display: flex;
align-items: center;
justify-content: center;
}

.heartBtnSection {
display: flex;
align-items: center;
}

.sendBtn {
width: 50%;
-webkit-tap-highlight-color: transparent;
}
}

@media screen and (min-width: 801px) and (max-width: 1023px) {

/*Tablet*/
.messageCard {
width: 70%;
margin-bottom: 25px;
}

.textArea {
width: 80%;

}

.inputField {

width: 90%;

}
}