mongoosedbcc 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/comp/README.md +70 -0
- package/comp/bin/cli.js +38 -0
- package/comp/package-lock.json +16503 -0
- package/comp/package.json +45 -0
- package/comp/public/favicon.ico +0 -0
- package/comp/public/index.html +43 -0
- package/comp/public/logo192.png +0 -0
- package/comp/public/logo512.png +0 -0
- package/comp/public/manifest.json +25 -0
- package/comp/public/robots.txt +3 -0
- package/comp/src/App.css +251 -0
- package/comp/src/App.js +30 -0
- package/comp/src/index.css +13 -0
- package/comp/src/index.js +13 -0
- package/comp/src/pages/BookForm.js +115 -0
- package/comp/src/pages/BookList.js +77 -0
- package/comp/src/server.js +43 -0
- package/library-frontend/src/App.js +14 -10
- package/package.json +1 -1
|
@@ -4,15 +4,18 @@ export default function App() {
|
|
|
4
4
|
const [books, setBooks] = useState([]);
|
|
5
5
|
const [title, setTitle] = useState('');
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const load = async () => {
|
|
8
|
+
const res = await fetch('/api/books');
|
|
9
|
+
setBooks(await res.json());
|
|
10
|
+
};
|
|
11
|
+
|
|
8
12
|
useEffect(() => {
|
|
9
|
-
|
|
10
|
-
.then(res => res.json())
|
|
11
|
-
.then(setBooks);
|
|
13
|
+
load();
|
|
12
14
|
}, []);
|
|
13
15
|
|
|
14
|
-
// add
|
|
15
16
|
const add = async () => {
|
|
17
|
+
if (!title) return;
|
|
18
|
+
|
|
16
19
|
await fetch('/api/books', {
|
|
17
20
|
method: 'POST',
|
|
18
21
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -20,21 +23,22 @@ export default function App() {
|
|
|
20
23
|
});
|
|
21
24
|
|
|
22
25
|
setTitle('');
|
|
23
|
-
|
|
24
|
-
setBooks(await res.json());
|
|
26
|
+
load(); // simpler refresh
|
|
25
27
|
};
|
|
26
28
|
|
|
27
|
-
// delete
|
|
28
29
|
const del = async (id) => {
|
|
29
30
|
await fetch('/api/books/' + id, { method: 'DELETE' });
|
|
30
|
-
|
|
31
|
+
load(); // simpler than filter
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
return (
|
|
34
35
|
<div>
|
|
35
36
|
<h2>Library</h2>
|
|
36
37
|
|
|
37
|
-
<input
|
|
38
|
+
<input
|
|
39
|
+
value={title}
|
|
40
|
+
onChange={e => setTitle(e.target.value)}
|
|
41
|
+
/>
|
|
38
42
|
<button onClick={add}>Add</button>
|
|
39
43
|
|
|
40
44
|
<ul>
|