-
Notifications
You must be signed in to change notification settings - Fork 434
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
Project Happy Thoughts - Hannah Ek #435
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
import React from 'react'; | ||
import { ThoughtFeed } from 'components/ThoughtFeed'; | ||
import { NewThought } from 'components/NewThought'; | ||
|
||
export const App = () => { | ||
return ( | ||
<div> | ||
Find me in src/app.js! | ||
</div> | ||
); | ||
} | ||
<> | ||
<section> | ||
<NewThought /> | ||
</section> | ||
<section> | ||
<ThoughtFeed /> | ||
</section> | ||
</> | ||
Comment on lines
+7
to
+14
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. If you look in the inspector, the
|
||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React, { useState } from 'react'; | ||
|
||
export const NewThought = () => { | ||
const [newThought, setNewThought] = useState(''); | ||
|
||
const HandleFormSubmit = (event) => { | ||
event.preventDefault(); | ||
if (newThought.length < 5) { | ||
return alert('Get on that keyboard, more than 5 characters, please!') | ||
} else if (newThought.length > 140) { | ||
return alert('Are you some sort of hacker?! No more than 140 characters, please!') | ||
} else { | ||
Comment on lines
+8
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. Love the messages haha! Also great and condense way of writing the error conditionals. |
||
const Submit = { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ message: newThought }) | ||
}; | ||
fetch('https://happy-thoughts-ux7hkzgmwa-uc.a.run.app/thoughts', Submit) | ||
.then((response) => response.json()) | ||
.then(() => { | ||
setNewThought(''); | ||
setTimeout(() => window.location.reload(), 3000) | ||
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. Really great idea to use the timed function here! |
||
}) | ||
} | ||
}; | ||
|
||
return ( | ||
<section className="main-container"> | ||
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. I like that you re-used the className for both the NewThought section and the ThoughtFeed section. Great way of keeping down the amount of code! It shows that you have really thought it through :) |
||
<form onSubmit={HandleFormSubmit} className="form-card"> | ||
<label htmlFor="newThought" className="head-thought">What is making you happy right now? | ||
<textarea | ||
id="newThought" | ||
type="text" | ||
placeholder="Type your happy thoughts here..." | ||
rows="4" | ||
cols="40" | ||
value={newThought} | ||
onChange={(event) => setNewThought(event.target.value)} /> | ||
</label> | ||
<p className={newThought.length > 140 ? 'counter' : 'counter'}>{newThought.length} / 140</p> | ||
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. Also a comment regarding the speak-reader. Now it never reads the "/", which makes it confusing to understand the length that is written and allowed. I recommend adding an aria-label to this section.
|
||
<button className="submitBtn" type="submit"> | ||
<span> | ||
<span className="heart" role="img" aria-label="heart"> 💗 </span> | ||
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. Nice with the aria label! Sounded good when I listened to it. |
||
Send happy thought | ||
<span className="heart" role="img" aria-label="heart"> 💗 </span> | ||
</span> | ||
</button> | ||
</form> | ||
</section> | ||
) | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react' | ||
|
||
const Spinning = () => ( | ||
<div className="loading-thoughts"> | ||
<div className="loading-spinner"> | ||
💖 | ||
</div> | ||
</div> | ||
Comment on lines
+3
to
+8
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. This thing looks great! Nice job! |
||
) | ||
|
||
export default Spinning; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* eslint-disable no-underscore-dangle */ | ||
import React, { useState, useEffect } from 'react'; | ||
import { formatDistance } from 'date-fns'; | ||
import Spinning from './Spinning'; | ||
// import { Loading } from './Loading' | ||
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. Remove this? :) |
||
|
||
const API = 'https://happy-thoughts-ux7hkzgmwa-uc.a.run.app/thoughts' | ||
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. Nice idea to have the fetch adress outside the function, makes it look a lot cleaner inside the fetch! |
||
|
||
export const ThoughtFeed = () => { | ||
const [thoughtsList, setThoughtsList] = useState([]); | ||
const [loading, setLoading] = useState(false); | ||
|
||
useEffect(() => { | ||
setLoading(true); | ||
fetch(`${API}`) | ||
.then((res) => res.json()) | ||
.then((data) => setThoughtsList(data)) | ||
.catch((error) => console.log(error)) | ||
.finally(() => { setLoading(false) }) | ||
}, []); | ||
|
||
const HandleLike = (thoughtId) => { | ||
fetch(`${API}/${thoughtId}/like`, { method: 'POST' }) | ||
.then((res) => res.json()) | ||
.then((data) => { | ||
const UpdateHearts = thoughtsList.map((like) => { | ||
if (like._id === data._id) { | ||
like.hearts += 1 | ||
return like | ||
} else { return like } | ||
}) | ||
setThoughtsList(UpdateHearts) | ||
}) | ||
}; | ||
|
||
return ( | ||
<> | ||
<section className="main-container"> | ||
{!loading && thoughtsList.map((thought) => { | ||
return ( | ||
<div key={thought._id} className="card"> | ||
<p className="post-text">{thought.message}</p> | ||
<button type="button" className={thought.hearts === 0 ? 'noLikesBtn' : 'likesBtn'} onClick={() => HandleLike(thought._id)}> | ||
<span role="img" aria-label="Like this post">💗</span> | ||
</button> | ||
<span className="sum-hearts">x {thought.hearts}</span> | ||
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. I listened to your app and this sounds a bit funny, it really says e.g. "x four". Could you maybe add an aria-label to it, so that the speaker reads "likes times four" or similar?
|
||
<p className="date"> {formatDistance(new Date(thought.createdAt), Date.now(), { addSuffix: true })}</p> | ||
</div> | ||
) | ||
})} | ||
</section> | ||
{loading && (<Spinning />)} | ||
</> | ||
) | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,178 @@ body { | |
sans-serif; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
code { | ||
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", | ||
monospace; | ||
} | ||
|
||
.main-container { | ||
padding: 0 18px; | ||
box-sizing: border-box; | ||
width: 400px; | ||
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. This fixed width could easily be changed into a more responsive one I think if you'd like that. It looks good for desktop and tablets, but the smallest phone sizes (320px) get a side scroll. |
||
margin: 0 auto; | ||
} | ||
|
||
.form-card { | ||
box-sizing: border-box; | ||
background-color: #f0f0f0f3; | ||
margin: 20px 0; | ||
padding: 15px; | ||
border: 1px solid #000000; | ||
box-shadow: 4px 4px #000000; | ||
} | ||
|
||
.head-thought { | ||
font-family: "Courier New"; | ||
font-weight: bold; | ||
font-size: 15px; | ||
} | ||
|
||
textarea { | ||
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. To prevent users from resizing the textarea by dragging the corner, you can use the resize property and set its value to none. This will disable the resizing feature of the textarea. resize: none; |
||
border: none; | ||
color: #000; | ||
padding: 8px; | ||
margin: 15px 0 10px; | ||
width: 100%; | ||
box-sizing: border-box; | ||
} | ||
|
||
.submitBtn { | ||
font-family: "Courier New"; | ||
font-size: 12px; | ||
font-weight: bold; | ||
border: none; | ||
border-radius: 50px; | ||
color: #380118; | ||
background-color: #ffadad; | ||
padding: 10px 20px; | ||
cursor: pointer; | ||
margin-left: 45px; | ||
} | ||
|
||
.heart { | ||
margin: 8px; | ||
} | ||
|
||
.img { | ||
margin: 0px 2px; | ||
} | ||
|
||
.card { | ||
box-sizing: border-box; | ||
background-color: rgb(255, 255, 255); | ||
border: 1px solid #000000; | ||
margin: 18px 0; | ||
padding: 10px 20px; | ||
box-shadow: 4.5px 5px #000000; | ||
overflow-wrap: break-word; | ||
font-weight: bold; | ||
} | ||
|
||
.post-text { | ||
font-family: "Courier New"; | ||
font-size: 13px; | ||
color: black; | ||
margin: 0; | ||
padding: 18px 0; | ||
min-height: 20px; | ||
} | ||
|
||
.heartEmo { | ||
font-size: 12px; | ||
transition: font-size 0.1s ease-in-out; | ||
} | ||
|
||
.heartEmo:hover { | ||
cursor: pointer; | ||
font-size: 18px; | ||
} | ||
Comment on lines
+92
to
+100
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. I can't find "heartEmo" anywhere other than in the css file. Is it supposed to be named something else? Also, " cursor:pointer; " can be added directly to the non-hover property, since it will be the same outcome :) |
||
|
||
.hearts { | ||
margin-right: 10px; | ||
border: none; | ||
border-radius: 50%; | ||
height: 38px; | ||
width: 38px; | ||
cursor: pointer; | ||
background-color: #e2016a51; | ||
} | ||
|
||
.likesBtn, | ||
.noLikesBtn { | ||
background-color: #ffacac; | ||
margin-right: 8px; | ||
border: none; | ||
border-radius: 55%; | ||
height: 32px; | ||
width: 32px; | ||
cursor: pointer; | ||
} | ||
|
||
.noLikesBtn { | ||
background-color: #f3f3f3a4; | ||
} | ||
|
||
.sum-hearts, | ||
.counter { | ||
font-size: 12px; | ||
color: #7d7a7af3; | ||
text-align: right; | ||
margin: 0; | ||
position: absolute; | ||
margin-top: 10px; | ||
} | ||
|
||
.date { | ||
float: right; | ||
position: relative; | ||
font-size: 12px; | ||
color: #7d7a7af3; | ||
text-align: right; | ||
} | ||
|
||
.loading-spinner { | ||
animation-name: loadspinner; | ||
display: block; | ||
width: 40px; | ||
height: 40px; | ||
font-size: 40px; | ||
margin-top: 30px; | ||
margin: 30px auto; | ||
animation-duration: 800ms; | ||
animation-iteration-count: infinite; | ||
animation-timing-function: linear; | ||
} | ||
|
||
@keyframes loadspinner { | ||
from { | ||
transform: rotate(0deg) | ||
|
||
} | ||
to { | ||
transform: rotate(360deg) | ||
} | ||
} | ||
|
||
|
||
|
||
/*--MEDIA QUERIES--*/ | ||
|
||
@media (min-width: 768px) { | ||
.mainContainer { | ||
width: 450px; | ||
} | ||
} | ||
|
||
@media (min-width: 1024px) { | ||
.mainContainer { | ||
width: 500px; | ||
} | ||
} |
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.
Nice job including the og tags! I suggest you check what it looks like through this page: https://www.opengraph.xyz/url/https%3A%2F%2Fproject-happy-thoughts-hannah-ek.netlify.app%2F
I think it would look even better if you make the image wider with white space, then more of it will be shown and not "cut".