Skip to content

Commit 9454610

Browse files
committed
First public commit of basic API editor
1 parent 77d8f0d commit 9454610

22 files changed

+642
-1
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
node_modules/

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# product_edit
2-
Simple API editor
2+
Simple API editor to use with [https://github.com/jenschr/product_api](https://github.com/jenschr/product_api)

package.json

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "api-edit",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"@testing-library/jest-dom": "^5.16.5",
7+
"@testing-library/react": "^13.4.0",
8+
"@testing-library/user-event": "^13.5.0",
9+
"apexcharts": "^3.39.0",
10+
"react": "^18.2.0",
11+
"react-apexcharts": "^1.4.0",
12+
"react-dom": "^18.2.0",
13+
"react-icons": "^4.8.0",
14+
"react-scripts": "5.0.1",
15+
"web-vitals": "^2.1.4",
16+
"wouter": "^2.10.0"
17+
},
18+
"scripts": {
19+
"start": "react-scripts start",
20+
"build": "react-scripts build",
21+
"test": "react-scripts test",
22+
"eject": "react-scripts eject"
23+
},
24+
"eslintConfig": {
25+
"extends": [
26+
"react-app",
27+
"react-app/jest"
28+
]
29+
},
30+
"browserslist": {
31+
"production": [
32+
">0.2%",
33+
"not dead",
34+
"not op_mini all"
35+
],
36+
"development": [
37+
"last 1 chrome version",
38+
"last 1 firefox version",
39+
"last 1 safari version"
40+
]
41+
}
42+
}

public/favicon.ico

3.78 KB
Binary file not shown.

public/index.html

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!DOCTYPE html>
2+
<html lang="en" data-theme="light">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<meta name="theme-color" content="#000000" />
8+
<meta
9+
name="description"
10+
content="Web site created using create-react-app"
11+
/>
12+
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
13+
<link
14+
rel="stylesheet"
15+
href="https://unpkg.com/@picocss/pico@1.*/css/pico.min.css"
16+
/>
17+
<!--
18+
manifest.json provides metadata used when your web app is installed on a
19+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
20+
-->
21+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
22+
<!--
23+
Notice the use of %PUBLIC_URL% in the tags above.
24+
It will be replaced with the URL of the `public` folder during the build.
25+
Only files inside the `public` folder can be referenced from the HTML.
26+
27+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
28+
work correctly both with client-side routing and a non-root public URL.
29+
Learn how to configure a non-root public URL by running `npm run build`.
30+
-->
31+
<title>React App</title>
32+
</head>
33+
<body>
34+
<noscript>You need to enable JavaScript to run this app.</noscript>
35+
<div id="root"></div>
36+
<!--
37+
This HTML file is a template.
38+
If you open it directly in the browser, you will see an empty page.
39+
40+
You can add webfonts, meta tags, or analytics to this file.
41+
The build step will place the bundled scripts into the <body> tag.
42+
43+
To begin the development, run `npm start` or `yarn start`.
44+
To create a production bundle, use `npm run build` or `yarn build`.
45+
-->
46+
</body>
47+
</html>

public/logo192.png

5.22 KB
Loading

public/logo512.png

9.44 KB
Loading

public/manifest.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"short_name": "React App",
3+
"name": "Create React App Sample",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "64x64 32x32 24x24 16x16",
8+
"type": "image/x-icon"
9+
},
10+
{
11+
"src": "logo192.png",
12+
"type": "image/png",
13+
"sizes": "192x192"
14+
},
15+
{
16+
"src": "logo512.png",
17+
"type": "image/png",
18+
"sizes": "512x512"
19+
}
20+
],
21+
"start_url": ".",
22+
"display": "standalone",
23+
"theme_color": "#000000",
24+
"background_color": "#ffffff"
25+
}

public/robots.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# https://www.robotstxt.org/robotstxt.html
2+
User-agent: *
3+
Disallow:

src/App.css

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
.App {
2+
text-align: center;
3+
}
4+
5+
.App-logo {
6+
height: 40vmin;
7+
pointer-events: none;
8+
}
9+
10+
@media (prefers-reduced-motion: no-preference) {
11+
.App-logo {
12+
animation: App-logo-spin infinite 20s linear;
13+
}
14+
}
15+
16+
.App-header {
17+
background-color: #282c34;
18+
min-height: 100vh;
19+
display: flex;
20+
flex-direction: column;
21+
align-items: center;
22+
justify-content: center;
23+
font-size: calc(10px + 2vmin);
24+
color: white;
25+
}
26+
27+
.App-link {
28+
color: #61dafb;
29+
}
30+
31+
@keyframes App-logo-spin {
32+
from {
33+
transform: rotate(0deg);
34+
}
35+
to {
36+
transform: rotate(360deg);
37+
}
38+
}
39+
40+
.delete {
41+
background-color: #cc0000;
42+
border-color: #cc0000;
43+
}

src/App.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import "./App.css";
2+
import { Route } from "wouter";
3+
import Header from "./components/Header";
4+
import Home from "./pages/Home";
5+
import ProductList from "./pages/ProductList";
6+
import ProductEdit from "./pages/ProductEdit";
7+
import CategoryEdit from "./pages/CategoryEdit";
8+
9+
const PORT = process.env.PORT || 3001;
10+
11+
function App() {
12+
return (
13+
<div className="App">
14+
<Header />
15+
<Route path="/" component={Home} />
16+
<Route path="/productlist" component={ProductList} />
17+
<Route path="/productedit/:id" component={ProductEdit} />
18+
<Route path="/productedit" component={ProductEdit} />
19+
<Route path="/categoryedit" component={CategoryEdit} />
20+
</div>
21+
);
22+
}
23+
24+
export default App;

src/App.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { render, screen } from '@testing-library/react';
2+
import App from './App';
3+
4+
test('renders learn react link', () => {
5+
render(<App />);
6+
const linkElement = screen.getByText(/learn react/i);
7+
expect(linkElement).toBeInTheDocument();
8+
});

src/components/Header.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from "react";
2+
import { Link, useLocation } from "wouter";
3+
4+
function Header(props) {
5+
const [location] = useLocation();
6+
return (
7+
<header className="container-fluid">
8+
<nav>
9+
<ul>
10+
<li>
11+
<strong>API Backend</strong>
12+
</li>
13+
</ul>
14+
<ul>
15+
<li>
16+
<Link className={location === "/" ? "contrast" : ""} href="/">
17+
Home
18+
</Link>
19+
</li>
20+
<li>
21+
<Link
22+
className={location === "/productlist" ? "contrast" : ""}
23+
href="/productlist"
24+
>
25+
Products
26+
</Link>
27+
</li>
28+
<li>
29+
<Link
30+
className={location === "/categoryedit" ? "contrast" : ""}
31+
href="/categoryedit"
32+
>
33+
Categories
34+
</Link>
35+
</li>
36+
</ul>
37+
</nav>
38+
</header>
39+
);
40+
}
41+
42+
export default Header;

src/index.css

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
body {
2+
margin: 0;
3+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4+
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5+
sans-serif;
6+
-webkit-font-smoothing: antialiased;
7+
-moz-osx-font-smoothing: grayscale;
8+
}
9+
10+
code {
11+
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12+
monospace;
13+
}

src/index.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom/client';
3+
import './index.css';
4+
import App from './App';
5+
import reportWebVitals from './reportWebVitals';
6+
7+
const root = ReactDOM.createRoot(document.getElementById('root'));
8+
root.render(
9+
<React.StrictMode>
10+
<App />
11+
</React.StrictMode>
12+
);
13+
14+
// If you want to start measuring performance in your app, pass a function
15+
// to log results (for example: reportWebVitals(console.log))
16+
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
17+
reportWebVitals();

src/logo.svg

+1
Loading

src/pages/CategoryEdit.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React from "react";
2+
3+
export default function CategoryEdit() {
4+
return (
5+
<article id="article">
6+
<h2>Categories</h2>
7+
<section id="tables">
8+
<figure>
9+
<table role="grid">
10+
<thead>
11+
<tr>
12+
<th scope="col">#</th>
13+
<th scope="col">Name</th>
14+
<th scope="col">Category</th>
15+
<th scope="col">ID</th>
16+
</tr>
17+
</thead>
18+
<tbody>
19+
<tr>
20+
<th scope="row">1</th>
21+
<td>Cell</td>
22+
<td>Cell</td>
23+
<td>Cell</td>
24+
</tr>
25+
<tr>
26+
<th scope="row">2</th>
27+
<td>Cell</td>
28+
<td>Cell</td>
29+
<td>Cell</td>
30+
</tr>
31+
<tr>
32+
<th scope="row">3</th>
33+
<td>Cell</td>
34+
<td>Cell</td>
35+
<td>Cell</td>
36+
</tr>
37+
</tbody>
38+
</table>
39+
</figure>
40+
</section>
41+
<footer>
42+
<small>(CC) Høyskolen Kristiania 2023</small>
43+
</footer>
44+
</article>
45+
);
46+
}

src/pages/Home.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React, { useState } from "react";
2+
import { useLocation } from "wouter";
3+
import Chart from "react-apexcharts";
4+
5+
export default function Home() {
6+
const [location, setLocation] = useLocation();
7+
const [data, setData] = useState({
8+
// Charts documentation: https://www.npmjs.com/package/react-apexcharts
9+
options: {
10+
chart: {
11+
id: "fruit-production",
12+
},
13+
xaxis: {
14+
categories: [2023, 2024, 2025, 2026, 2027, 2028, 2029, 2030, 2031],
15+
},
16+
},
17+
series: [
18+
{
19+
name: "Pinapple trees",
20+
data: [5, 12, 15, 18, 14, 16, 25, 28, 31],
21+
},
22+
{
23+
name: "Banana trees",
24+
data: [20, 40, 35, 50, 47, 60, 70, 91, 105],
25+
},
26+
],
27+
});
28+
29+
return (
30+
<article id="article">
31+
<Chart
32+
options={data.options}
33+
series={data.series}
34+
type="bar"
35+
height={450}
36+
/>
37+
<p>
38+
The current page is: {location}
39+
<br />
40+
<button onClick={() => setLocation("/productedit")}>
41+
Click to add a product
42+
</button>
43+
</p>
44+
<footer>
45+
<small>(CC) Høyskolen Kristiania 2023</small>
46+
</footer>
47+
</article>
48+
);
49+
}

0 commit comments

Comments
 (0)