From 74b72527eedecb680222e975995a06606ded9699 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 3 Feb 2021 12:28:32 +1100 Subject: [PATCH] Added some example front-ends in react --- front-ends/react/news-editor.jsx | 110 ++++++++++++++++++++++++++++ front-ends/react/news-feed.jsx | 42 +++++++++++ front-ends/react/news-publisher.jsx | 70 ++++++++++++++++++ 3 files changed, 222 insertions(+) create mode 100644 front-ends/react/news-editor.jsx create mode 100644 front-ends/react/news-feed.jsx create mode 100644 front-ends/react/news-publisher.jsx diff --git a/front-ends/react/news-editor.jsx b/front-ends/react/news-editor.jsx new file mode 100644 index 0000000..2bd699d --- /dev/null +++ b/front-ends/react/news-editor.jsx @@ -0,0 +1,110 @@ +import React, { useState } from 'react'; +import Select from 'react-dropdown-select'; + +//DOCS: props.uri is the address of a live news-server +//DOCS: props.newsKey is the key of the live news-server +const NewsEditor = props => { + let titleElement, authorElement, bodyElement; + const [articles, setArticles] = useState(null); + const [index, setIndex] = useState(null); + + if (!articles) { + fetch(`${props.uri}/titles?limit=999`, { method: 'GET' }) + .then(a => { + if (!a.ok) { + throw `Network error ${a.status}: ${a.statusText} ${a.url}`; + } + return a.json(); + }) + .then(a => setArticles(a)) + .catch(e => console.error(e)) + ; + } + + return ( +
+

News Editor

+
+ + titleElement = e } /> +
+ +
+ + authorElement = e } /> +
+ +
+ +