Skip to content

Commit f110781

Browse files
author
plazadevina
committed
git commit -m "Code-lab-web"
1 parent 11b0d2b commit f110781

File tree

3 files changed

+40
-75
lines changed

3 files changed

+40
-75
lines changed

frontend/src/App.jsx

Lines changed: 39 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,42 @@
1-
import { Header } from "./components/Header";
2-
import { ThoughtForm } from "./components/ThoughtForm";
3-
import { ThoughtList } from "./components/ThoughtList"; // Removed duplicate declaration of App
4-
import { useState } from "react";
5-
import { useEffect } from "react";
6-
import "./components/App.css";
7-
import "./components/Card.css";
8-
import "./components/index.css";
9-
10-
import "./App.css";
11-
12-
// Removed duplicate declaration of App
13-
14-
export const App = () => {
15-
const [count, setCount] = useState(0);
16-
17-
useEffect(() => {
18-
const handleScroll = () => {
19-
console.log("scrolled!");
1+
import React, { useEffect, useState } from "react";
2+
import "./index.css";
3+
4+
function Header() {
5+
useEffect(() => {
6+
console.log('mount')
7+
}, [])
8+
return (
9+
<header className="App-header">
10+
<h1>Message App Happy Thoughts</h1>
11+
</header>
12+
)
13+
}
14+
15+
export default function App() {
16+
const [text, setText] = useState("");
17+
const [error, setError] = useState("");
18+
const handleChange = (e) => {
19+
if (e.target.value.length > 140) {
20+
setError("character limit exceeded");
21+
} else {
22+
setText(e.target.value);
23+
setError(null);
24+
}
2025
};
2126

22-
window.addEventListener("scroll", handleScroll);
23-
return () => {
24-
window.removeEventListener("scroll", handleScroll);
25-
};
26-
}, []);
27-
28-
useEffect(() => {
29-
const controller = new AbortController();
30-
31-
fetch("https://happy-thoughts-ux7hkzgmwa-uc.a.run.app/thoughts", {
32-
signal: controller.signal,
33-
})
34-
.then((response) => response.json())
35-
.then((data) => console.log(data));
36-
37-
const intervalId = setInterval(() => {
38-
fetch("https://happy-thoughts-ux7hkzgmwa-uc.a.run.app/thoughts", {
39-
signal: controller.signal,
40-
})
41-
.then((response) => response.json())
42-
.then((data) => console.log(data));
43-
44-
console.log("This runs every second");
45-
}, 1000);
46-
47-
return () => {
48-
clearInterval(intervalId);
49-
controller.abort();
50-
};
51-
}, []);
52-
53-
return (
54-
<>
55-
<Header />
56-
<main>
57-
<ThoughtForm />
58-
<ThoughtList />
59-
<div>
60-
<button onClick={() => setCount(count + 1)}>Increase count</button>
61-
<button onClick={() => setCount(count - 1)}>Decrease count</button>
62-
<button onClick={() => setCount(0)} disabled={count === 0}>
63-
Reset
64-
</button>
65-
<button onClick={() => setCount(count * 2)}>Multiply</button>
66-
67-
<p>Count: {count}</p>
68-
{count > 140 && <p>You hit 140!</p>}
27+
return (
28+
<div className="App">
29+
<Header />
30+
<div className="input-container">
31+
<input
32+
className="input"
33+
type="text"
34+
placeholder=" enter something ..."
35+
onChange={handleChange}
36+
value={text}
37+
/>
38+
<span className="error">{error && error}</span>
39+
</div>
6940
</div>
70-
</main>
71-
</>
72-
);
73-
};
41+
);
42+
}

frontend/src/installhook.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
(() => {
2-
// Some minified code that seems to be causing issues.
3-
// For now, let's just have an empty file.
4-
})();

frontend/src/main.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { StrictMode } from "react";
22
import { createRoot } from "react-dom/client";
3-
import App from "./App.js";
3+
import App from "./App.jsx";
44
import "./index.css";
55

66
createRoot(document.getElementById("root")).render(

0 commit comments

Comments
 (0)