Add a very basic POC React client
This commit is contained in:
parent
7e0a95317c
commit
b71a8d2a59
23
intake-client/.gitignore
vendored
Normal file
23
intake-client/.gitignore
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
16709
intake-client/package-lock.json
generated
Normal file
16709
intake-client/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
28
intake-client/package.json
Normal file
28
intake-client/package.json
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "intake-client",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-scripts": "^5.0.1"
|
||||
},
|
||||
"devDependencies": {},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build"
|
||||
},
|
||||
"proxy": "http://localhost:5000",
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
}
|
||||
}
|
69
intake-client/public/index.html
Normal file
69
intake-client/public/index.html
Normal file
@ -0,0 +1,69 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwgAADsIBFShKgAAAABh0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMS41ZEdYUgAAAGFJREFUOE+lkFEKwDAIxXrzXXB3ckMm9EnAV/YRCxFCcUXEL3Jc77NDjpDA/VGL3RFWYEICfeGC8oQc9IPuCAnQDcoRVmBCAn3hgvKEHPSD7ggJ0A3KEVZgQgJ94YLSJ9YDUzNGDXGZ/JEAAAAASUVORK5CYII=">
|
||||
<style>
|
||||
main {
|
||||
max-width: 700px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
article {
|
||||
border: 1px solid black; border-radius: 6px;
|
||||
padding: 5px;
|
||||
margin-bottom: 20px;
|
||||
word-break: break-word;
|
||||
}
|
||||
.item-title {
|
||||
font-size: 1.4em;
|
||||
}
|
||||
.item-button {
|
||||
font-size: 1em;
|
||||
float:right;
|
||||
margin-left: 2px;
|
||||
}
|
||||
.item-link {
|
||||
text-decoration: none;
|
||||
float:right;
|
||||
font-size: 1em;
|
||||
padding: 2px 7px;
|
||||
border: 1px solid;
|
||||
border-radius: 2px;
|
||||
}
|
||||
.item-info {
|
||||
color: rgba(0, 0, 0, 0.7);
|
||||
}
|
||||
article img {
|
||||
max-width: 100%;
|
||||
}
|
||||
button, summary {
|
||||
cursor: pointer;
|
||||
}
|
||||
summary {
|
||||
display: block;
|
||||
}
|
||||
summary:focus {
|
||||
outline: 1px dotted gray;
|
||||
}
|
||||
.strikethru span, .strikethru p {
|
||||
text-decoration: line-through;
|
||||
}
|
||||
.fade span, .fade p {
|
||||
color: rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
pre {
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
table.feed-control td {
|
||||
font-family: monospace; padding: 5px 10px;
|
||||
}
|
||||
article.center {
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div id="root"></div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
114
intake-client/src/index.js
Normal file
114
intake-client/src/index.js
Normal file
@ -0,0 +1,114 @@
|
||||
import { StrictMode, useState, useEffect } from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
|
||||
function Item({ item }) {
|
||||
var classNames = !item.hidden ? "" : item.active ? "fade" : "strikethru fade";
|
||||
|
||||
return (
|
||||
<article className={classNames} id={`${item.source}-${item.id}`}>
|
||||
<button className="item-button" title="Deactivate">✕</button>
|
||||
<button className="item-button" title="Punt to tomorrow">↷</button>
|
||||
{item.link && <a className="item-link" href="#" target="_blank">⇗</a>}
|
||||
{/* The item title is a clickable <details> if there is body content */}
|
||||
{item.title || item.action ? (
|
||||
<details open>
|
||||
<summary><span className="item-title">{item.title || item.id}</span></summary>
|
||||
{item.body && (
|
||||
<p dangerouslySetInnerHTML={{ __html: item.body }}></p>
|
||||
)}
|
||||
{item.actions && item.actions.map((action) => {
|
||||
return (
|
||||
<p key={`${item.source}-${item.id}-action-${action}`}>
|
||||
<button>
|
||||
{action}
|
||||
</button>
|
||||
</p>
|
||||
);
|
||||
})}
|
||||
</details>
|
||||
) : (
|
||||
<>
|
||||
<span className="item-title">{item.title || item.id}</span>
|
||||
<br/>
|
||||
</>
|
||||
)}
|
||||
{/* Author/time footer */}
|
||||
{(item.author || item.time) && (
|
||||
<>
|
||||
<span className="item-info">{item.author} {item.time}</span><br/>
|
||||
</>
|
||||
)}
|
||||
{/* Source/id/created footer */}
|
||||
{(item.source || item.id || item.created) && (
|
||||
<span className="item-info" title="Tags: TODO">
|
||||
{item.source} {item.id} {item.created}
|
||||
{item.ttl && "T"} {item.ttd && "D"} {item.tts && "S"}
|
||||
</span>
|
||||
)}
|
||||
</article>
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function App() {
|
||||
const [items, setItems] = useState([]);
|
||||
|
||||
// Initial load
|
||||
useEffect(() => {
|
||||
fetch("http://localhost:5000/api/v1/items")
|
||||
.then(response => response.json()).then(newItems => setItems(newItems.items))
|
||||
.catch(error => console.log(error));
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<main>
|
||||
<article className="center">
|
||||
<span className="item-title">
|
||||
<a href="{{url_for('root')}}">Home</a> [
|
||||
<a href="{{ set_query(hidden='false', page=None, count=None) }}">Active</a>
|
||||
|
|
||||
<a href="{{ set_query(hidden='true', page=None, count=None) }}">All</a>
|
||||
]
|
||||
{/* {% if item_count > items|length -%} */}
|
||||
{/* [<a {% if page_num is greaterthan(0) -%} href="{{ set_query(page=page_num - 1) }}" {%- endif %}>Prev</a> */}
|
||||
{/* | */}
|
||||
{/* <a {% if ((page_num + 1) * page_count) is lessthan(item_count) -%} href="{{ set_query(page=page_num + 1) }}" {%- endif %}>Next</a>] */}
|
||||
{/* {%- endif %} */}
|
||||
</span>
|
||||
</article>
|
||||
|
||||
|
||||
{items.map((item) => {
|
||||
return <Item item={item} key={item.id}/>;
|
||||
})}
|
||||
|
||||
{/* {% if item_count > items|length %} */}
|
||||
<article className="center">
|
||||
<span className="item-title">
|
||||
{/* <a {% if page_num is greaterthan(0) -%} href="{{ set_query(page=page_num - 1) }}" {%- endif %}>Prev</a> */}
|
||||
|
|
||||
{/* <a {% if ((page_num + 1) * page_count) is lessthan(item_count) -%} href="{{ set_query(page=page_num + 1) }}" {%- endif %}>Next</a> */}
|
||||
</span>
|
||||
</article>
|
||||
{/* {% endif %} */}
|
||||
|
||||
<article className="center">
|
||||
<button >Deactivate All</button>
|
||||
</article>
|
||||
|
||||
{items.length == 0 && (
|
||||
<article className="center">
|
||||
<span className="item-title">Feed is empty</span>
|
||||
</article>
|
||||
)}
|
||||
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
const root = ReactDOM.createRoot(document.getElementById('root'));
|
||||
root.render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>
|
||||
);
|
Loading…
Reference in New Issue
Block a user