-
❤️ x{hearts}
- {/* update the number of likes with the state value */}
+
❤️x{props.hearts}
{moment(props.timestamp).startOf('hour').fromNow()}
From 5cf620bb527f7860f7d716a3da684e1069b94516 Mon Sep 17 00:00:00 2001
From: Ylva Karlsson <121539816+YlvaKarlsson@users.noreply.github.com>
Date: Fri, 24 Mar 2023 23:38:40 +0100
Subject: [PATCH 04/12] added a component for new happy thought but now the app
isn't working, will do more tomorrow
---
code/src/HappyThought.js | 54 +++++++++++++++++++++++++++++------
code/src/HappyThoughtsFeed.js | 2 ++
code/src/NewHappyThought.js | 35 +++++++++++++++++++++++
code/src/index.css | 25 ++++++++++++++++
4 files changed, 107 insertions(+), 9 deletions(-)
create mode 100644 code/src/NewHappyThought.js
diff --git a/code/src/HappyThought.js b/code/src/HappyThought.js
index ae97697d7..a4e753496 100644
--- a/code/src/HappyThought.js
+++ b/code/src/HappyThought.js
@@ -1,22 +1,58 @@
/* eslint-disable linebreak-style */
+/* eslint-disable padded-blocks */
+/* eslint-disable no-trailing-spaces */
import React from 'react';
import moment from 'moment';
// {props.text}
-const HappyThought = (props) => {
+// const HappyThought = (props) => {
+const HappyThought = ({ thoughtId, messageText, hearts, timestamp, onHeartClick }) => {
+
+ const heartButtonGrey = (
+
onHeartClick(thoughtId)}>
+ ❤️
+
+ );
+
+ const heartButtonPink = (
+
onHeartClick(thoughtId)}>
+ ❤️
+
+ );
+
return (
-
-
{props.text}
-
-
-
❤️x{props.hearts}
+
+ {messageText}
+
+
+ {hearts !== 0 ? heartButtonPink : heartButtonGrey}
+ x {hearts}
-
-
{moment(props.timestamp).startOf('hour').fromNow()}
+
+
{moment(timestamp).startOf('hour').fromNow()}
-
+
);
+ // return (
+ //
+ //
{props.text}
+ //
+ //
+ //
❤️x{props.hearts}
+ //
+ //
+ //
{moment(props.timestamp).startOf('hour').fromNow()}
+ //
+ //
+ //
+ // );
};
export default HappyThought;
diff --git a/code/src/HappyThoughtsFeed.js b/code/src/HappyThoughtsFeed.js
index 16f54fae5..fc221f674 100644
--- a/code/src/HappyThoughtsFeed.js
+++ b/code/src/HappyThoughtsFeed.js
@@ -2,6 +2,7 @@
/* eslint-disable import/no-named-as-default */
/* eslint-disable no-trailing-spaces */
import React, { useState, useEffect } from 'react';
+import NewHappyThought from 'NewHappyThought';
import HappyThought from './HappyThought';
import Footer from './Footer';
import './index.css';
@@ -53,6 +54,7 @@ const HappyThoughtsFeed = () => {
onChange={handleChange} />
Klicka här
+
{!loading && thoughtsList.map((thought) => (
{
+ const isSubmitButtonDisabled = newHappyThought.length < 5 || newHappyThought.length > 140;
+
+ return (
+
+ );
+};
+
+export default NewHappyThought;
\ No newline at end of file
diff --git a/code/src/index.css b/code/src/index.css
index 7c94ce644..ae6fadf80 100644
--- a/code/src/index.css
+++ b/code/src/index.css
@@ -40,3 +40,28 @@ code {
flex-direction: row;
justify-content: space-between;
}
+
+.happy-thought-card {
+
+}
+
+.heart-btn-pink {
+ background-color: pink;
+ border-radius: 80rem;
+}
+
+.heart-btn-grey {
+ background-color: lightgrey;
+}
+
+.card-bottom {
+
+}
+
+.card-bottom-left {
+
+}
+
+.card-bottom-right-timestamp {
+
+}
\ No newline at end of file
From 9242d6876e4fbd383e8ef85cbc3e6061d54ff81e Mon Sep 17 00:00:00 2001
From: Ylva Karlsson <121539816+YlvaKarlsson@users.noreply.github.com>
Date: Sun, 26 Mar 2023 23:39:35 +0200
Subject: [PATCH 05/12] TOTAL FAILUREgit add . git add .
---
code/src/App.js | 3 +-
code/src/HappyThoughtsFeed.js | 75 ---------
code/src/{ => components}/Footer.js | 0
code/src/{ => components}/HappyThought.js | 19 +--
code/src/components/HappyThoughtsFeed.js | 111 +++++++++++++
code/src/components/HappyThoughtsList.js | 20 +++
code/src/components/Loading.js | 11 ++
code/src/{ => components}/NewHappyThought.js | 7 +-
code/src/index.css | 163 +++++++++++--------
9 files changed, 249 insertions(+), 160 deletions(-)
delete mode 100644 code/src/HappyThoughtsFeed.js
rename code/src/{ => components}/Footer.js (100%)
rename code/src/{ => components}/HappyThought.js (66%)
create mode 100644 code/src/components/HappyThoughtsFeed.js
create mode 100644 code/src/components/HappyThoughtsList.js
create mode 100644 code/src/components/Loading.js
rename code/src/{ => components}/NewHappyThought.js (76%)
diff --git a/code/src/App.js b/code/src/App.js
index c8da02960..c7ca5282d 100644
--- a/code/src/App.js
+++ b/code/src/App.js
@@ -1,5 +1,6 @@
import React from 'react';
-import HappyThoughtsFeed from './HappyThoughtsFeed';
+import HappyThoughtsFeed from './components/HappyThoughtsFeed';
+import 'index.css';
export const App = () => {
return ;
diff --git a/code/src/HappyThoughtsFeed.js b/code/src/HappyThoughtsFeed.js
deleted file mode 100644
index fc221f674..000000000
--- a/code/src/HappyThoughtsFeed.js
+++ /dev/null
@@ -1,75 +0,0 @@
-/* eslint-disable linebreak-style */
-/* eslint-disable import/no-named-as-default */
-/* eslint-disable no-trailing-spaces */
-import React, { useState, useEffect } from 'react';
-import NewHappyThought from 'NewHappyThought';
-import HappyThought from './HappyThought';
-import Footer from './Footer';
-import './index.css';
-
-const HappyThoughtsFeed = () => {
- const [thoughtsList, setThoughtsList] = useState([]);
- const [loading, setLoading] = useState(false);
- const [happyThought, setHappyThought] = useState('');
-
- const API_URL = 'https://happy-thoughts-ux7hkzgmwa-uc.a.run.app/thoughts';
-
- useEffect(() => {
- setLoading(true);
- fetch(API_URL)
- .then((response) => response.json())
- .then((data) => setThoughtsList(data))
- .catch((error) => console.log(error))
- .finally(() => {
- setLoading(false);
- });
- }, []);
- const handleChange = (event) => {
- setHappyThought(event.target.value);
- };
- const CreateThought = (event) => {
- event.preventDefault();
- fetch(API_URL, {
- method: 'POST',
- body: JSON.stringify({ message: happyThought }),
- headers: {
- 'Content-Type': 'application/json',
- Accept: 'application/json'
- }
- })
- .then((response) => response.json())
- .then((status) => console.log(status))
- .catch((error) => console.log(error));
- setHappyThought('');
- };
- return (
-
-
Happy Thoughts!
-
-
Textruta
-
-
- Klicka här
-
-
-
- {!loading && thoughtsList.map((thought) => (
-
- ))}
- {loading &&
LOADING }
-
-
-
-
- );
-};
-
-export default HappyThoughtsFeed;
diff --git a/code/src/Footer.js b/code/src/components/Footer.js
similarity index 100%
rename from code/src/Footer.js
rename to code/src/components/Footer.js
diff --git a/code/src/HappyThought.js b/code/src/components/HappyThought.js
similarity index 66%
rename from code/src/HappyThought.js
rename to code/src/components/HappyThought.js
index a4e753496..6a9414b1b 100644
--- a/code/src/HappyThought.js
+++ b/code/src/components/HappyThought.js
@@ -6,13 +6,13 @@ import moment from 'moment';
// {props.text}
// const HappyThought = (props) => {
-const HappyThought = ({ thoughtId, messageText, hearts, timestamp, onHeartClick }) => {
+const HappyThought = ({ thoughtId, messageText, hearts, timestamp, handleHearts }) => {
const heartButtonGrey = (
onHeartClick(thoughtId)}>
+ onClick={() => handleHearts(thoughtId)}>
❤️
);
@@ -21,7 +21,7 @@ const HappyThought = ({ thoughtId, messageText, hearts, timestamp, onHeartClick
onHeartClick(thoughtId)}>
+ onClick={() => handleHearts(thoughtId)}>
❤️
);
@@ -40,19 +40,6 @@ const HappyThought = ({ thoughtId, messageText, hearts, timestamp, onHeartClick
);
- // return (
- //
- //
{props.text}
- //
- //
- //
❤️x{props.hearts}
- //
- //
- //
{moment(props.timestamp).startOf('hour').fromNow()}
- //
- //
- //
- // );
};
export default HappyThought;
diff --git a/code/src/components/HappyThoughtsFeed.js b/code/src/components/HappyThoughtsFeed.js
new file mode 100644
index 000000000..09270e1bb
--- /dev/null
+++ b/code/src/components/HappyThoughtsFeed.js
@@ -0,0 +1,111 @@
+/* eslint-disable react/jsx-closing-bracket-location */
+/* eslint-disable no-underscore-dangle */
+/* eslint-disable brace-style */
+/* eslint-disable object-curly-newline */
+/* eslint-disable linebreak-style */
+/* eslint-disable import/no-named-as-default */
+/* eslint-disable no-trailing-spaces */
+import React, { useState, useEffect } from 'react';
+import NewHappyThought from 'components/NewHappyThought';
+import HappyThoughtsList from './HappyThoughtsList';
+import Loading from './Loading';
+import Footer from './Footer';
+import 'index.css';
+
+const HappyThoughtsFeed = () => {
+ const [thoughtsList, setThoughtsList] = useState([]);
+ const [loading, setLoading] = useState(false);
+ const [happyThought, setHappyThought] = useState('');
+
+ const API_URL = 'https://happy-thoughts-ux7hkzgmwa-uc.a.run.app/thoughts';
+
+ const fetchThoughts = () => {
+ setLoading(true);
+ fetch(API_URL)
+ .then((response) => response.json())
+ .then((data) => setThoughtsList(data))
+ .catch((error) => console.log(error))
+ .finally(() => setLoading(false));
+ }
+
+ useEffect(() => {
+ fetchThoughts();
+ }, []);
+
+ const handleFormSubmit = (event) => {
+ setHappyThought(event.target.value);
+ };
+
+ const newHappyThought = () => {
+ setHappyThought('');
+ setLoading(false);
+ };
+
+ const onFormSubmit = (event) => {
+ event.preventDefault();
+
+ const options = {
+ method: 'POST',
+ body: JSON.stringify({ message: happyThought }),
+ headers: {
+ 'Content-Type': 'application/json',
+ Accept: 'application/json'
+ }
+ };
+
+ fetch(API_URL, options)
+ .then((response) => response.json())
+ .then((data) => { setThoughtsList([data, ...thoughtsList]) })
+ .catch((error) => console.log(error))
+ .finally(() => setLoading(false));
+ }
+
+ useEffect(() => {
+ setThoughtsList('');
+ }, [thoughtsList]);
+
+ const handleHearts = (id) => {
+ const options = {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ }
+ };
+
+ fetch(`https://happy-thoughts-ux7hkzgmwa-uc.a.run.app/thoughts/${id}/like`, options)
+ .then((res) => res.json())
+ .then(console.log('likes'))
+ .then((error) => console.error(error))
+ .finally(() => fetchThoughts(''));
+ };
+
+ return (
+
+ Happy Thoughts!
+
+ )}
+ thoughtsList={thoughtsList}
+ handleHearts={handleHearts}
+ />
+ {/* {thoughtsList.map((thought) => (
+ handleHearts(thought._id)}
+ />
+ ))} */}
+ {loading && ( )}
+
+
+
+
+ );
+};
+
+export default HappyThoughtsFeed;
diff --git a/code/src/components/HappyThoughtsList.js b/code/src/components/HappyThoughtsList.js
new file mode 100644
index 000000000..68c833589
--- /dev/null
+++ b/code/src/components/HappyThoughtsList.js
@@ -0,0 +1,20 @@
+/* eslint-disable no-underscore-dangle */
+import React from 'react';
+import HappyThought from './HappyThought';
+
+const HappyThoughtsList = ({ thoughtList, handleHearts }) => {
+ return (
+
+ {thoughtList.map((thought) => (
+ handleHearts(thought._id)} />
+ ))}
+
+ );
+};
+
+export default HappyThoughtsList;
\ No newline at end of file
diff --git a/code/src/components/Loading.js b/code/src/components/Loading.js
new file mode 100644
index 000000000..ccc3feaef
--- /dev/null
+++ b/code/src/components/Loading.js
@@ -0,0 +1,11 @@
+import React from 'react';
+
+const Loading = () => {
+ return (
+
+ );
+};
+
+export default Loading;
\ No newline at end of file
diff --git a/code/src/NewHappyThought.js b/code/src/components/NewHappyThought.js
similarity index 76%
rename from code/src/NewHappyThought.js
rename to code/src/components/NewHappyThought.js
index 324a00f73..dae7d2af0 100644
--- a/code/src/NewHappyThought.js
+++ b/code/src/components/NewHappyThought.js
@@ -4,11 +4,11 @@
/* eslint-disable no-trailing-spaces */
import React from 'react';
-const NewHappyThought = ({ onFormSubmit, newHappyThought, onNewHappyThoughtChange }) => {
+const NewHappyThought = ({ handleFormSubmit, newHappyThought, onNewHappyThoughtChange }) => {
const isSubmitButtonDisabled = newHappyThought.length < 5 || newHappyThought.length > 140;
return (
-
+
What makes you happy right now?
onNewHappyThoughtChange(event.target.value)}
rows="4"
cols="30"
placeholder="Write your happy thought here (at least 5 characters and up to 140 characters)" />
@@ -26,7 +27,7 @@ const NewHappyThought = ({ onFormSubmit, newHappyThought, onNewHappyThoughtChang
HEART - add emoji here
- Share Happy Thought
+ ❤️ Share Happy Thought ❤️
);
diff --git a/code/src/index.css b/code/src/index.css
index ae6fadf80..4034cb50c 100644
--- a/code/src/index.css
+++ b/code/src/index.css
@@ -1,67 +1,100 @@
body {
- margin: 0;
- font-family: -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;
-}
+ margin: 0;
+ font-family: -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;
+ }
+
+ code {
+ font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
+ monospace;
+ }
+
+ .App {
+ font-family: sans-serif;
+ text-align: center;
+ margin-left: 25%;
+ margin-right: 25%;
+ }
+
+ .happy-thoughts-form-wrapper {
+ display: flex;
+ align-self: center;
+ background: yellow;
+ width: auto;
+ height: 20rem;
+ }
+
+ .happy-thoughts-wrapper {
+ display: flex;
+ align-self: center;
+ background: blue;
+ width: auto;
+ height: 20rem;
+ }
+
+ .data-wrapper {
+ display: flex;
+ flex-direction: row;
+ justify-content: space-between;
+ }
+
+ .happy-thought-card {
+
+ }
+
+ .heart-btn-pink {
+ background-color: pink;
+ border-radius: 80rem;
+ }
+
+ .heart-btn-grey {
+ background-color: lightgrey;
+ }
+
+ .card-bottom {
+
+ }
+
+ .card-bottom-left {
+
+ }
+
+ .card-bottom-right-timestamp {
+
+ }
-code {
- font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
- monospace;
-}
-
-.App {
- font-family: sans-serif;
- text-align: center;
- margin-left: 25%;
- margin-right: 25%;
-}
-
-.happy-thoughts-form-wrapper {
- display: flex;
- align-self: center;
- background: yellow;
- width: auto;
- height: 20rem;
-}
-
-.happy-thoughts-wrapper {
- display: flex;
- align-self: center;
- background: blue;
- width: auto;
- height: 20rem;
-}
-
-.data-wrapper {
- display: flex;
- flex-direction: row;
- justify-content: space-between;
-}
-
-.happy-thought-card {
-
-}
-
-.heart-btn-pink {
- background-color: pink;
- border-radius: 80rem;
-}
-
-.heart-btn-grey {
- background-color: lightgrey;
-}
-
-.card-bottom {
-
-}
-
-.card-bottom-left {
-
-}
-
-.card-bottom-right-timestamp {
-
-}
\ No newline at end of file
+ .loading-overlay {
+ position: absolute;
+ top: 0;
+ right: 0;
+ bottom: 0;
+ left: 0;
+ background: #fff;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ }
+
+ .loading-spinner {
+ width: 50px;
+ height: 50px;
+ border: 5px solid rgb(255, 173, 173);
+ border-radius: 50%;
+ border-left: 5px solid #fff;
+ animation: spinner infinite 1s;
+ }
+
+ @keyframes spinner {
+ 0% {
+ transform: rotate(0);
+ }
+ 50% {
+ transform: rotate(180deg);
+ }
+ 100% {
+ transform: rotate(360deg);
+ }
+ }
\ No newline at end of file
From bdb24bf82c8aeb96c68c84c54ed8186e5f1c081c Mon Sep 17 00:00:00 2001
From: Ylva Karlsson <121539816+YlvaKarlsson@users.noreply.github.com>
Date: Mon, 27 Mar 2023 15:35:15 +0200
Subject: [PATCH 06/12] It's working! Feels like magic...
---
code/src/App.js | 3 +-
code/src/components/HappyThought.js | 4 +--
code/src/components/HappyThoughtsFeed.js | 41 +++++++++++-------------
code/src/components/HappyThoughtsList.js | 5 +--
code/src/components/NewHappyThought.js | 26 ++++++++-------
5 files changed, 40 insertions(+), 39 deletions(-)
diff --git a/code/src/App.js b/code/src/App.js
index c7ca5282d..5d8f0856e 100644
--- a/code/src/App.js
+++ b/code/src/App.js
@@ -1,6 +1,5 @@
import React from 'react';
-import HappyThoughtsFeed from './components/HappyThoughtsFeed';
-import 'index.css';
+import HappyThoughtsFeed from 'components/HappyThoughtsFeed';
export const App = () => {
return
;
diff --git a/code/src/components/HappyThought.js b/code/src/components/HappyThought.js
index 6a9414b1b..5e8239d2e 100644
--- a/code/src/components/HappyThought.js
+++ b/code/src/components/HappyThought.js
@@ -6,7 +6,7 @@ import moment from 'moment';
// {props.text}
// const HappyThought = (props) => {
-const HappyThought = ({ thoughtId, messageText, hearts, timestamp, handleHearts }) => {
+const HappyThought = ({ thoughtId, text, hearts, timestamp, handleHearts }) => {
const heartButtonGrey = (
- {messageText}
+ {text}
{hearts !== 0 ? heartButtonPink : heartButtonGrey}
diff --git a/code/src/components/HappyThoughtsFeed.js b/code/src/components/HappyThoughtsFeed.js
index 09270e1bb..27bffc4db 100644
--- a/code/src/components/HappyThoughtsFeed.js
+++ b/code/src/components/HappyThoughtsFeed.js
@@ -10,12 +10,11 @@ import NewHappyThought from 'components/NewHappyThought';
import HappyThoughtsList from './HappyThoughtsList';
import Loading from './Loading';
import Footer from './Footer';
-import 'index.css';
const HappyThoughtsFeed = () => {
const [thoughtsList, setThoughtsList] = useState([]);
const [loading, setLoading] = useState(false);
- const [happyThought, setHappyThought] = useState('');
+ // const [newHappyThought, setNewHappyThought] = useState('');
const API_URL = 'https://happy-thoughts-ux7hkzgmwa-uc.a.run.app/thoughts';
@@ -32,21 +31,23 @@ const HappyThoughtsFeed = () => {
fetchThoughts();
}, []);
- const handleFormSubmit = (event) => {
- setHappyThought(event.target.value);
- };
+ // const onFormSubmit = (event) => {
+ // setNewHappyThought(event.target.value);
+ // };
- const newHappyThought = () => {
- setHappyThought('');
- setLoading(false);
- };
+ // const newHappyThought = () => {
+ // setNewHappyThought('');
+ // setLoading(false);
+ // };
const onFormSubmit = (event) => {
event.preventDefault();
-
+
+ const val = event.target['thought-input'].value;
+
const options = {
method: 'POST',
- body: JSON.stringify({ message: happyThought }),
+ body: JSON.stringify({ message: val }),
headers: {
'Content-Type': 'application/json',
Accept: 'application/json'
@@ -55,14 +56,11 @@ const HappyThoughtsFeed = () => {
fetch(API_URL, options)
.then((response) => response.json())
- .then((data) => { setThoughtsList([data, ...thoughtsList]) })
+ .then((data) => { setThoughtsList([data, ...thoughtsList]);
+ })
.catch((error) => console.log(error))
.finally(() => setLoading(false));
- }
-
- useEffect(() => {
- setThoughtsList('');
- }, [thoughtsList]);
+ };
const handleHearts = (id) => {
const options = {
@@ -83,11 +81,10 @@ const HappyThoughtsFeed = () => {
Happy Thoughts!
+ handleFormSubmit={onFormSubmit}
+ />
)}
+ loading={loading}
thoughtsList={thoughtsList}
handleHearts={handleHearts}
/>
@@ -100,7 +97,7 @@ const HappyThoughtsFeed = () => {
handleHearts={() => handleHearts(thought._id)}
/>
))} */}
- {loading && ( )}
+ {loading && }
diff --git a/code/src/components/HappyThoughtsList.js b/code/src/components/HappyThoughtsList.js
index 68c833589..7f0cd7e1b 100644
--- a/code/src/components/HappyThoughtsList.js
+++ b/code/src/components/HappyThoughtsList.js
@@ -2,12 +2,13 @@
import React from 'react';
import HappyThought from './HappyThought';
-const HappyThoughtsList = ({ thoughtList, handleHearts }) => {
+const HappyThoughtsList = ({ thoughtsList, handleHearts }) => {
return (
- {thoughtList.map((thought) => (
+ {thoughtsList.map((thought) => (
{
- const isSubmitButtonDisabled = newHappyThought.length < 5 || newHappyThought.length > 140;
+const NewHappyThought = ({ handleFormSubmit }) => {
+ const [newThought, setNewThought] = useState('');
+
+ const isSubmitButtonDisabled = newThought.length < 5 || newThought.length > 140;
return (
-
+
What makes you happy right now?
onNewHappyThoughtChange(event.target.value)}
+ onChange={(e) => setNewThought(e.target.value)}
rows="4"
cols="30"
placeholder="Write your happy thought here (at least 5 characters and up to 140 characters)" />
- {newHappyThought.length}/140
- {newHappyThought.length > 140 && Sorry it`'`s too long, please keep within the maximum of 140 characters! }
+ {newThought.length}/140
+ {newThought.length > 140 && Sorry it`'`s too long, please keep within the maximum of 140 characters! }
-
- HEART - add emoji here
+
❤️ Share Happy Thought ❤️
From 7bf1a8c66a4b0d8e97e0a82a0e3c3312e216686a Mon Sep 17 00:00:00 2001
From: Ylva Karlsson <121539816+YlvaKarlsson@users.noreply.github.com>
Date: Mon, 27 Mar 2023 16:11:38 +0200
Subject: [PATCH 07/12] some styling
---
code/src/components/HappyThought.js | 4 +-
code/src/components/NewHappyThought.js | 2 +-
code/src/index.css | 306 +++++++++++++++++--------
3 files changed, 218 insertions(+), 94 deletions(-)
diff --git a/code/src/components/HappyThought.js b/code/src/components/HappyThought.js
index 5e8239d2e..88a1a1998 100644
--- a/code/src/components/HappyThought.js
+++ b/code/src/components/HappyThought.js
@@ -11,7 +11,7 @@ const HappyThought = ({ thoughtId, text, hearts, timestamp, handleHearts }) => {
const heartButtonGrey = (
handleHearts(thoughtId)}>
❤️
@@ -20,7 +20,7 @@ const HappyThought = ({ thoughtId, text, hearts, timestamp, handleHearts }) => {
const heartButtonPink = (
handleHearts(thoughtId)}>
❤️
diff --git a/code/src/components/NewHappyThought.js b/code/src/components/NewHappyThought.js
index b72e3a323..949bb1cc6 100644
--- a/code/src/components/NewHappyThought.js
+++ b/code/src/components/NewHappyThought.js
@@ -28,7 +28,7 @@ const NewHappyThought = ({ handleFormSubmit }) => {
{newThought.length > 140 && Sorry it`'`s too long, please keep within the maximum of 140 characters! }
❤️ Share Happy Thought ❤️
diff --git a/code/src/index.css b/code/src/index.css
index 4034cb50c..5d6ab43e9 100644
--- a/code/src/index.css
+++ b/code/src/index.css
@@ -1,100 +1,224 @@
+:root {
+ --black: #000;
+ --white: #fff;
+ --lightgrey: #dcdcdc;
+ --grey: #808080;
+ --pink: #faaab7;
+}
+
+* {
+ font-size: 16px;
+ margin: 0;
+ padding: 0;
+ box-sizing: border-box;
+ -webkit-box-sizing: border-box;
+ -moz-box-sizing: border-box;
+}
+
body {
- margin: 0;
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
+ margin: 0;
+ font-family: -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;
- }
-
- code {
- font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
- monospace;
- }
-
- .App {
- font-family: sans-serif;
- text-align: center;
- margin-left: 25%;
- margin-right: 25%;
- }
-
- .happy-thoughts-form-wrapper {
- display: flex;
- align-self: center;
- background: yellow;
- width: auto;
- height: 20rem;
- }
-
- .happy-thoughts-wrapper {
- display: flex;
- align-self: center;
- background: blue;
- width: auto;
- height: 20rem;
- }
-
- .data-wrapper {
- display: flex;
- flex-direction: row;
- justify-content: space-between;
- }
-
- .happy-thought-card {
-
- }
-
- .heart-btn-pink {
- background-color: pink;
- border-radius: 80rem;
- }
-
- .heart-btn-grey {
- background-color: lightgrey;
- }
-
- .card-bottom {
-
- }
-
- .card-bottom-left {
-
- }
-
- .card-bottom-right-timestamp {
-
- }
+ -webkit-font-smoothing: antialiased;
+ -moz-osx-font-smoothing: grayscale;
+ background-color: #ffe0e5;
+}
+
+code {
+ font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
+ monospace;
+}
+
+.App {
+ font-family: sans-serif;
+ text-align: center;
+ margin-left: 25%;
+ margin-right: 25%;
+}
- .loading-overlay {
- position: absolute;
- top: 0;
- right: 0;
- bottom: 0;
- left: 0;
- background: #fff;
- display: flex;
- justify-content: center;
- align-items: center;
- }
+.happy-thoughts-app {
+ margin: 0 auto;
+ width: 375px;
+ display: flex;
+ flex-direction: column;
+ overflow: hidden;
+}
+
+.happy-thoughts-list {
+
+}
+
+.happy-thoughts-form-wrapper {
+ display: flex;
+ align-self: center;
+ background: yellow;
+ width: auto;
+ height: 20rem;
+}
+
+.happy-thoughts-wrapper {
+ display: flex;
+ align-self: center;
+ background: blue;
+ width: auto;
+ height: 20rem;
+}
+
+.thought-input {
+ width: 100%;
+ padding: 0.3rem;
+ margin: 0.3rem 0;
+ font-size: 0.8rem;
+ resize: vertical;
+}
+
+.thought-length span {
+ font-size: 0.8rem;
+}
+
+.data-wrapper {
+ display: flex;
+ flex-direction: row;
+ justify-content: space-between;
+}
+
+.new-happy-thought-form-wrapper,
+.happy-thought-card {
+ border: 1px solid var(--black);
+ box-shadow: 0.4rem 0.4rem var(--black);
+ margin: 1.5rem 1rem;
+}
+
+.heart-button {
+ cursor: pointer;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ width: 2rem;
+ height: 2rem;
+ border: none;
+ border-radius: 50%;
+ margin-right: 0.4rem;
+}
+
+.pink-background {
+ background-color: var(--pink);
+ /* background-color: pink; */
+}
+
+.grey-background {
+ background-color: var(--lightgrey);
+ /* background-color: lightgrey; */
+}
+
+.new-happy-thought-form-wrapper {
+ background-color: var(--lightgrey);
+ padding: 0.5rem 1rem;
+}
+
+.thought-length span {
+ font-size: 0.8rem;
+}
+
+.thought-input {
+ width: 100%;
+ padding: 0.3rem;
+ margin: 0.3rem 0;
+ font-size: 0.8rem;
+ resize: vertical;
+}
+
+.send-new-thought-button {
+ background-color: var(--pink);
+ cursor: pointer;
+ border: none;
+ border-radius: 20px;
+ padding: 0.3rem;
+ margin: 0.5rem 0;
+}
+
+.send-new-thought-button > span {
+ font-family: 'Roboto Mono', monospace;
+ font-size: 0.85em;
+}
+
+.card {
+ background-color: var(--white);
+ padding: 0.7rem;
+ display: flex;
+ flex-direction: column;
+ justify-content: space-between;
+ overflow-wrap: break-word;
+}
+
+.card-bottom {
+ display: flex;
+ justify-content: space-between;
+ align-items: baseline;
+ margin-top: 1rem;
+}
+
+.card-bottom span,
+.card-bottom p {
+ color: var(--grey);
+ font-size: 0.8rem;
+}
+
+.card-bottom-left {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+}
- .loading-spinner {
- width: 50px;
- height: 50px;
- border: 5px solid rgb(255, 173, 173);
- border-radius: 50%;
- border-left: 5px solid #fff;
- animation: spinner infinite 1s;
- }
+.card-bottom-right-timestamp {
- @keyframes spinner {
- 0% {
- transform: rotate(0);
+}
+
+.loading-overlay {
+ position: absolute;
+ top: 0;
+ right: 0;
+ bottom: 0;
+ left: 0;
+ background: #fff;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+}
+
+.loading-spinner {
+ width: 50px;
+ height: 50px;
+ border: 5px solid rgb(255, 173, 173);
+ border-radius: 50%;
+ border-left: 5px solid #fff;
+ animation: spinner infinite 1s;
+}
+
+@keyframes spinner {
+ 0% {
+ transform: rotate(0);
}
- 50% {
- transform: rotate(180deg);
+ 50% {
+ transform: rotate(180deg);
}
- 100% {
- transform: rotate(360deg);
+ 100% {
+ transform: rotate(360deg);
}
- }
\ No newline at end of file
+}
+
+ /** MEDIA QUERIES **/
+ /* TABLET and DESKTOP */
+@media screen and (min-width: 768px) {
+ .happy-page {
+ width: 600px;
+ }
+}
+
+/* DESKTOP */
+@media screen and (min-width: 992px) {
+ .card:hover {
+ background-color: var(--pink);
+ }
+}
\ No newline at end of file
From 1ce7a63cea458624299c64cb0f610f7aa459d08c Mon Sep 17 00:00:00 2001
From: Ylva Karlsson <121539816+YlvaKarlsson@users.noreply.github.com>
Date: Mon, 27 Mar 2023 16:21:40 +0200
Subject: [PATCH 08/12] Updated Readme with link to deployed site
---
README.md | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index 9ea4e26b3..de81d29b1 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,15 @@
# Happy Thoughts
-Replace this readme with your own information about your project.
-
-Start by briefly describing the assignment in a sentence or two. Keep it short and to the point.
+Week 7 project with React - the task was to fetch happy thoughts from an API and showing them in a list plus have a form for new happy thoughts where people could post their happy thoughts in and make the new thoughts to also show up in the list.
## 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?
+This week started off very good but ended in a catastrophical way for me...
+With some help from a former student I managed to solve the problem and finally got my code to work - YEY! Big shoutout to Agnes Ahlman for helping me out.
+
+I had the basic functions working but then when I wanted to add more functionality it just didn't work out and the page was completely blank/white with nothing showing up.
+I've been crying, laughing and overall struggling this week but now with a working project I'm so happy and grateful.
## 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.
+https://happy-thoughts-w7-ylva-karlsson.netlify.app/
From 1960cf44f64d401a16f01e59ac035013f1d9b0a6 Mon Sep 17 00:00:00 2001
From: Ylva Karlsson <121539816+YlvaKarlsson@users.noreply.github.com>
Date: Mon, 27 Mar 2023 16:36:07 +0200
Subject: [PATCH 09/12] added more styling
---
code/src/components/NewHappyThought.js | 14 ++++++++++++--
package-lock.json | 6 ++++++
package.json | 1 +
3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/code/src/components/NewHappyThought.js b/code/src/components/NewHappyThought.js
index 949bb1cc6..70bcb740d 100644
--- a/code/src/components/NewHappyThought.js
+++ b/code/src/components/NewHappyThought.js
@@ -3,10 +3,11 @@
/* eslint-disable padded-blocks */
/* eslint-disable no-trailing-spaces */
import React, { useState } from 'react';
+import JSConfetti from 'js-confetti';
const NewHappyThought = ({ handleFormSubmit }) => {
const [newThought, setNewThought] = useState('');
-
+ const jsConfetti = new JSConfetti();
const isSubmitButtonDisabled = newThought.length < 5 || newThought.length > 140;
return (
@@ -30,7 +31,16 @@ const NewHappyThought = ({ handleFormSubmit }) => {
+ disabled={isSubmitButtonDisabled}
+ onClick={() => {
+ (jsConfetti.addConfetti({
+ confettiRadius: 8,
+ confettiNumber: 500,
+ confettiColors: [
+ '#d44e62', '#fcfee1', '#eebed9', '#b4c8b7', '#fb91c6', '#a0bbd0'
+ ]
+ }))
+ }}>
❤️ Share Happy Thought ❤️
diff --git a/package-lock.json b/package-lock.json
index 0e0109b3f..b2ec2e61f 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -5,9 +5,15 @@
"packages": {
"": {
"dependencies": {
+ "js-confetti": "^0.11.0",
"moment": "^2.29.4"
}
},
+ "node_modules/js-confetti": {
+ "version": "0.11.0",
+ "resolved": "https://registry.npmjs.org/js-confetti/-/js-confetti-0.11.0.tgz",
+ "integrity": "sha512-Hc7I3VI4r4H0nq5q/oQK+JJwGoYRYVHK72fGk8E9Ay1dbh+aiZ9yl0yFp1K4oYeq7YFDQAndYChwqLPA3QWQuA=="
+ },
"node_modules/moment": {
"version": "2.29.4",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz",
diff --git a/package.json b/package.json
index 29a0c7b8d..8b866cc10 100644
--- a/package.json
+++ b/package.json
@@ -1,5 +1,6 @@
{
"dependencies": {
+ "js-confetti": "^0.11.0",
"moment": "^2.29.4"
}
}
From 4bdba38f57137cbeb818218c4195360cb893c676 Mon Sep 17 00:00:00 2001
From: Ylva Karlsson <121539816+YlvaKarlsson@users.noreply.github.com>
Date: Wed, 24 May 2023 16:14:35 +0200
Subject: [PATCH 10/12] Changed API to my own
---
code/src/components/Footer.js | 6 +++---
code/src/components/HappyThought.js | 2 +-
code/src/components/HappyThoughtsFeed.js | 8 +++++---
code/src/index.css | 9 +--------
4 files changed, 10 insertions(+), 15 deletions(-)
diff --git a/code/src/components/Footer.js b/code/src/components/Footer.js
index bb8b37f16..8dbbd4e9c 100644
--- a/code/src/components/Footer.js
+++ b/code/src/components/Footer.js
@@ -6,15 +6,15 @@ const Footer = () => {
diff --git a/code/src/components/HappyThought.js b/code/src/components/HappyThought.js
index 88a1a1998..0e1f62010 100644
--- a/code/src/components/HappyThought.js
+++ b/code/src/components/HappyThought.js
@@ -35,7 +35,7 @@ const HappyThought = ({ thoughtId, text, hearts, timestamp, handleHearts }) => {
x {hearts}
-
{moment(timestamp).startOf('hour').fromNow()}
+
{moment(timestamp).fromNow()}
diff --git a/code/src/components/HappyThoughtsFeed.js b/code/src/components/HappyThoughtsFeed.js
index 27bffc4db..1f88f2575 100644
--- a/code/src/components/HappyThoughtsFeed.js
+++ b/code/src/components/HappyThoughtsFeed.js
@@ -16,7 +16,8 @@ const HappyThoughtsFeed = () => {
const [loading, setLoading] = useState(false);
// const [newHappyThought, setNewHappyThought] = useState('');
- const API_URL = 'https://happy-thoughts-ux7hkzgmwa-uc.a.run.app/thoughts';
+ const API_URL = 'https://happy-thoughts-api-w15-o6447lrzoq-ew.a.run.app/thoughts'
+ // const API_URL = 'https://happy-thoughts-ux7hkzgmwa-uc.a.run.app/thoughts';
const fetchThoughts = () => {
setLoading(true);
@@ -69,8 +70,9 @@ const HappyThoughtsFeed = () => {
'Content-Type': 'application/json'
}
};
-
- fetch(`https://happy-thoughts-ux7hkzgmwa-uc.a.run.app/thoughts/${id}/like`, options)
+
+ // fetch(`https://happy-thoughts-ux7hkzgmwa-uc.a.run.app/thoughts/${id}/like`, options)
+ fetch(`https://happy-thoughts-api-w15-o6447lrzoq-ew.a.run.app/thoughts/${id}/like`, options)
.then((res) => res.json())
.then(console.log('likes'))
.then((error) => console.error(error))
diff --git a/code/src/index.css b/code/src/index.css
index 5d6ab43e9..90239ce59 100644
--- a/code/src/index.css
+++ b/code/src/index.css
@@ -45,10 +45,6 @@ code {
overflow: hidden;
}
-.happy-thoughts-list {
-
-}
-
.happy-thoughts-form-wrapper {
display: flex;
align-self: center;
@@ -88,6 +84,7 @@ code {
border: 1px solid var(--black);
box-shadow: 0.4rem 0.4rem var(--black);
margin: 1.5rem 1rem;
+ padding: 0.5rem;
}
.heart-button {
@@ -170,10 +167,6 @@ code {
justify-content: center;
align-items: center;
}
-
-.card-bottom-right-timestamp {
-
-}
.loading-overlay {
position: absolute;
From 5cc8061ad6a194b2234a3865276851f41eb18948 Mon Sep 17 00:00:00 2001
From: Ylva Karlsson <121539816+YlvaKarlsson@users.noreply.github.com>
Date: Wed, 24 May 2023 16:19:56 +0200
Subject: [PATCH 11/12] Updated readme
---
README.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/README.md b/README.md
index de81d29b1..836493020 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,8 @@
Week 7 project with React - the task was to fetch happy thoughts from an API and showing them in a list plus have a form for new happy thoughts where people could post their happy thoughts in and make the new thoughts to also show up in the list.
+W 15 - updated this project with my own API for Happy Thoughts.
+
## The problem
This week started off very good but ended in a catastrophical way for me...
From bb7c8f4d4245dfe2d14d25549986709fa6fd2b7f Mon Sep 17 00:00:00 2001
From: Ylva Karlsson <121539816+YlvaKarlsson@users.noreply.github.com>
Date: Wed, 24 May 2023 16:52:37 +0200
Subject: [PATCH 12/12] Fixed confetti
---
code/package-lock.json | 33 ++++++++++++++++++++++++++
code/package.json | 1 +
code/src/components/Confetti.js | 14 +++++++++++
code/src/components/NewHappyThought.js | 28 ++++++++++------------
4 files changed, 60 insertions(+), 16 deletions(-)
create mode 100644 code/src/components/Confetti.js
diff --git a/code/package-lock.json b/code/package-lock.json
index e361ead57..10ee2a717 100644
--- a/code/package-lock.json
+++ b/code/package-lock.json
@@ -17,6 +17,7 @@
"eslint-plugin-react-hooks": "^4.6.0",
"moment": "^2.29.4",
"react": "^18.2.0",
+ "react-confetti": "^6.1.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
@@ -14402,6 +14403,20 @@
"node": ">=14"
}
},
+ "node_modules/react-confetti": {
+ "version": "6.1.0",
+ "resolved": "https://registry.npmjs.org/react-confetti/-/react-confetti-6.1.0.tgz",
+ "integrity": "sha512-7Ypx4vz0+g8ECVxr88W9zhcQpbeujJAVqL14ZnXJ3I23mOI9/oBVTQ3dkJhUmB0D6XOtCZEM6N0Gm9PMngkORw==",
+ "dependencies": {
+ "tween-functions": "^1.2.0"
+ },
+ "engines": {
+ "node": ">=10.18"
+ },
+ "peerDependencies": {
+ "react": "^16.3.0 || ^17.0.1 || ^18.0.0"
+ }
+ },
"node_modules/react-dev-utils": {
"version": "12.0.1",
"resolved": "https://registry.npmjs.org/react-dev-utils/-/react-dev-utils-12.0.1.tgz",
@@ -16310,6 +16325,11 @@
"typescript": ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta"
}
},
+ "node_modules/tween-functions": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/tween-functions/-/tween-functions-1.2.0.tgz",
+ "integrity": "sha512-PZBtLYcCLtEcjL14Fzb1gSxPBeL7nWvGhO5ZFPGqziCcr8uvHp0NDmdjBchp6KHL+tExcg0m3NISmKxhU394dA=="
+ },
"node_modules/type-check": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz",
@@ -27887,6 +27907,14 @@
"whatwg-fetch": "^3.6.2"
}
},
+ "react-confetti": {
+ "version": "6.1.0",
+ "resolved": "https://registry.npmjs.org/react-confetti/-/react-confetti-6.1.0.tgz",
+ "integrity": "sha512-7Ypx4vz0+g8ECVxr88W9zhcQpbeujJAVqL14ZnXJ3I23mOI9/oBVTQ3dkJhUmB0D6XOtCZEM6N0Gm9PMngkORw==",
+ "requires": {
+ "tween-functions": "^1.2.0"
+ }
+ },
"react-dev-utils": {
"version": "12.0.1",
"resolved": "https://registry.npmjs.org/react-dev-utils/-/react-dev-utils-12.0.1.tgz",
@@ -29345,6 +29373,11 @@
"tslib": "^1.8.1"
}
},
+ "tween-functions": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/tween-functions/-/tween-functions-1.2.0.tgz",
+ "integrity": "sha512-PZBtLYcCLtEcjL14Fzb1gSxPBeL7nWvGhO5ZFPGqziCcr8uvHp0NDmdjBchp6KHL+tExcg0m3NISmKxhU394dA=="
+ },
"type-check": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz",
diff --git a/code/package.json b/code/package.json
index 2bda29bbd..ca46d5d94 100644
--- a/code/package.json
+++ b/code/package.json
@@ -12,6 +12,7 @@
"eslint-plugin-react-hooks": "^4.6.0",
"moment": "^2.29.4",
"react": "^18.2.0",
+ "react-confetti": "^6.1.0",
"react-dom": "^18.2.0"
},
"scripts": {
diff --git a/code/src/components/Confetti.js b/code/src/components/Confetti.js
new file mode 100644
index 000000000..2afbcf2ec
--- /dev/null
+++ b/code/src/components/Confetti.js
@@ -0,0 +1,14 @@
+// import React from 'react';
+// import Confetti from 'react-confetti';
+// import useWindowSize from 'react-use/lib/useWindowSize'
+
+// const ConfettiComponent = () => {
+// const { width, height } = useWindowSize()
+// return (
+//
+// )
+// }
+
+// export default ConfettiComponent;
\ No newline at end of file
diff --git a/code/src/components/NewHappyThought.js b/code/src/components/NewHappyThought.js
index 70bcb740d..fe899ed39 100644
--- a/code/src/components/NewHappyThought.js
+++ b/code/src/components/NewHappyThought.js
@@ -3,19 +3,22 @@
/* eslint-disable padded-blocks */
/* eslint-disable no-trailing-spaces */
import React, { useState } from 'react';
-import JSConfetti from 'js-confetti';
+import Confetti from 'react-confetti';
const NewHappyThought = ({ handleFormSubmit }) => {
const [newThought, setNewThought] = useState('');
- const jsConfetti = new JSConfetti();
+ const [showConfetti, setShowConfetti] = useState(false);
const isSubmitButtonDisabled = newThought.length < 5 || newThought.length > 140;
+ const handleButtonClick = () => {
+ setShowConfetti(true);
+ // Other code logic
+ };
+
return (
-
+
- What makes you happy right now?
+ What makes you happy right now?
{
{newThought.length}/140
- {newThought.length > 140 && Sorry it`'`s too long, please keep within the maximum of 140 characters! }
+ {newThought.length > 140 && Sorry, it`'`s too long. Please keep within the maximum of 140 characters! }
{
- (jsConfetti.addConfetti({
- confettiRadius: 8,
- confettiNumber: 500,
- confettiColors: [
- '#d44e62', '#fcfee1', '#eebed9', '#b4c8b7', '#fb91c6', '#a0bbd0'
- ]
- }))
- }}>
+ onClick={handleButtonClick}>
❤️ Share Happy Thought ❤️
+ {showConfetti && }
);
};