Skip to content

Commit 3a2ad8c

Browse files
New Project Checkpoint.
1 parent 7c82dbd commit 3a2ad8c

File tree

16 files changed

+106
-302
lines changed

16 files changed

+106
-302
lines changed

README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
# React + Vite
1+
# MERN Live Frontend
22

3-
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4-
5-
Currently, two official plugins are available:
6-
7-
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8-
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
3+
This is the frontend for the MERN Live project. We will keep replacing it with the latest project that we build. The code of older project will be kept in MERNLive repo for reference.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "6-todo-ui-bootstrap",
2+
"name": "mern-live-frontend",
33
"private": true,
44
"version": "0.0.0",
55
"type": "module",

src/App.jsx

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
import AddTodo from "./components/AddTodo";
2-
import AppName from "./components/AppName";
3-
import LoadItems from "./components/LoadItems";
4-
import TodoItems from "./components/TodoItems";
5-
import { TodoItemsProvider } from "./store/TodoItemsContext";
1+
import ExampleComponent from "./components/ExampleComponent";
2+
import { ExampleProvider } from "./store/ExampleContext";
63

74
function App() {
85
return (
9-
<TodoItemsProvider>
10-
<div className="min-h-screen bg-gray-50">
11-
<div className="container mx-auto px-4">
12-
<AppName />
13-
<AddTodo />
14-
<LoadItems />
15-
<TodoItems />
6+
<ExampleProvider>
7+
<div className="min-h-screen bg-gray-100">
8+
<div className="py-8">
9+
<h1 className="text-3xl font-bold text-center text-gray-800 mb-8">Example App</h1>
10+
<ExampleComponent />
1611
</div>
1712
</div>
18-
</TodoItemsProvider>
13+
</ExampleProvider>
1914
);
2015
}
2116

src/assets/react.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/components/AddTodo.jsx

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/components/AppName.jsx

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/components/Button.jsx

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { ExampleContext } from "../store/ExampleContext";
2+
import { exampleServerToClientModel } from "../utils/ModelUtil";
3+
import { useRef, useContext } from "react";
4+
5+
const ExampleComponent = () => {
6+
const { addExampleItem } = useContext(ExampleContext);
7+
const exampleTextInput = useRef();
8+
9+
const addHandler = () => {
10+
fetch("http://localhost:3000/examples", {
11+
method: "POST",
12+
headers: {
13+
"Content-Type": "application/json",
14+
},
15+
body: JSON.stringify({
16+
text: exampleTextInput.current.value,
17+
}),
18+
})
19+
.then((res) => res.json())
20+
.then((serverItem) => {
21+
const { id, text } = exampleServerToClientModel(serverItem);
22+
addExampleItem(id, text);
23+
});
24+
};
25+
26+
return (
27+
<div className="max-w-3xl mx-auto px-4 mb-8">
28+
<div className="flex flex-col sm:flex-row gap-4">
29+
<input
30+
type="text"
31+
className="flex-1 px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
32+
ref={exampleTextInput}
33+
placeholder="Enter text..."
34+
/>
35+
<button
36+
onClick={addHandler}
37+
className="bg-blue-500 hover:bg-blue-600 text-white font-semibold py-2 px-6 rounded-lg transition duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-opacity-50"
38+
>
39+
Add
40+
</button>
41+
</div>
42+
</div>
43+
);
44+
};
45+
46+
export default ExampleComponent;

src/components/LoadItems.jsx

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)