From 04079bca0867080facf1a92f557e914b501b553b Mon Sep 17 00:00:00 2001 From: Jonash189 Date: Wed, 23 Oct 2024 12:23:35 +0200 Subject: [PATCH 1/7] Creating first component HappyToughts were i will store everyting. --- src/App.jsx | 5 ++++- src/components/HappyThoughts.jsx | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/components/HappyThoughts.jsx diff --git a/src/App.jsx b/src/App.jsx index 1091d431..176283ed 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,3 +1,6 @@ +import React from "react"; + + export const App = () => { - return
Find me in src/app.jsx!
; + return
hejhej
; }; diff --git a/src/components/HappyThoughts.jsx b/src/components/HappyThoughts.jsx new file mode 100644 index 00000000..6ce947c7 --- /dev/null +++ b/src/components/HappyThoughts.jsx @@ -0,0 +1,8 @@ + +import React from "react"; + +export const HappyThoughts = () => { + const [thoughts, setThoughts] = useState([]) + const [newthoughts, setNewThoughts] = useState("") + +} \ No newline at end of file From 9765b2c639e3f697540a3e9729f80d48d80abc43 Mon Sep 17 00:00:00 2001 From: Jonash189 Date: Wed, 23 Oct 2024 15:21:24 +0200 Subject: [PATCH 2/7] Creating ThoughtForm component. --- src/App.jsx | 16 +++++++++---- src/components/HappyThoughts.jsx | 24 +++++++++++++++---- src/components/ThoughtForm.jsx | 40 ++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 src/components/ThoughtForm.jsx diff --git a/src/App.jsx b/src/App.jsx index 176283ed..3199cbde 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,6 +1,12 @@ -import React from "react"; +import React from 'react'; +import { HappyThoughts } from './components/HappyThoughts'; +import { ThoughtForm } from './components/ThoughtForm'; - -export const App = () => { - return
hejhej
; -}; +const App = () => { + return ( +
+

Välkommen till Happy Thoughts!

+ < HappyThoughts /> +
+ ); +}; \ No newline at end of file diff --git a/src/components/HappyThoughts.jsx b/src/components/HappyThoughts.jsx index 6ce947c7..f5ed6c33 100644 --- a/src/components/HappyThoughts.jsx +++ b/src/components/HappyThoughts.jsx @@ -1,8 +1,24 @@ -import React from "react"; +import React, { useState, useEffect } from "react"; export const HappyThoughts = () => { - const [thoughts, setThoughts] = useState([]) - const [newthoughts, setNewThoughts] = useState("") + const [thoughts, setThoughts] = useState([]); -} \ No newline at end of file + useEffect(() => { + fetch('https://project-happy-thoughts-api-j0eg.onrender.com/thoughts') + .then(res => res.json()) + .then(data => { + console.log(data); // Logga den faktiska datan + }) + .catch(error => { + console.error('Fel vid hämtning av tankar:', error); // Logga eventuella fel + }); + }, []); // Se till att denna rad är korrekt + + return ( +
+

Happy Thoughts

+ {/* Här kan du rendera tankarna om du vill */} +
+ ); +}; \ No newline at end of file diff --git a/src/components/ThoughtForm.jsx b/src/components/ThoughtForm.jsx new file mode 100644 index 00000000..9c432379 --- /dev/null +++ b/src/components/ThoughtForm.jsx @@ -0,0 +1,40 @@ +import React from "react"; +import { ThoughtForm } from './components/ThoughtForm'; + +export const HappyThoughtForm = () => { + onFormSubmit, + newThought, + oneNewThoughtChange, + +}) => { + + const disableSubmit = newThought.length < 6 || newThought.length > 140; + + return ( + +
+