From fd3e3280a2590be9ca074a172c535990a5035649 Mon Sep 17 00:00:00 2001 From: Mitchell Riedstra Date: Mon, 26 Dec 2022 00:11:58 -0500 Subject: Add a proxy option for static assets. Fix the paste view handlers. --- paste-ui/src/App.css | 38 ++++++++++++++++++++++ paste-ui/src/App.js | 20 ++++++++++++ paste-ui/src/App.test.js | 8 +++++ paste-ui/src/api.js | 0 paste-ui/src/index.css | 13 ++++++++ paste-ui/src/index.js | 17 ++++++++++ paste-ui/src/list.js | 46 ++++++++++++++++++++++++++ paste-ui/src/reportWebVitals.js | 13 ++++++++ paste-ui/src/setupTests.js | 5 +++ paste-ui/src/stateExample.js | 32 +++++++++++++++++++ paste-ui/src/style.css | 71 +++++++++++++++++++++++++++++++++++++++++ paste-ui/src/view.js | 54 +++++++++++++++++++++++++++++++ 12 files changed, 317 insertions(+) create mode 100644 paste-ui/src/App.css create mode 100644 paste-ui/src/App.js create mode 100644 paste-ui/src/App.test.js create mode 100644 paste-ui/src/api.js create mode 100644 paste-ui/src/index.css create mode 100644 paste-ui/src/index.js create mode 100644 paste-ui/src/list.js create mode 100644 paste-ui/src/reportWebVitals.js create mode 100644 paste-ui/src/setupTests.js create mode 100644 paste-ui/src/stateExample.js create mode 100644 paste-ui/src/style.css create mode 100644 paste-ui/src/view.js (limited to 'paste-ui/src') diff --git a/paste-ui/src/App.css b/paste-ui/src/App.css new file mode 100644 index 0000000..74b5e05 --- /dev/null +++ b/paste-ui/src/App.css @@ -0,0 +1,38 @@ +.App { + text-align: center; +} + +.App-logo { + height: 40vmin; + pointer-events: none; +} + +@media (prefers-reduced-motion: no-preference) { + .App-logo { + animation: App-logo-spin infinite 20s linear; + } +} + +.App-header { + background-color: #282c34; + min-height: 100vh; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + font-size: calc(10px + 2vmin); + color: white; +} + +.App-link { + color: #61dafb; +} + +@keyframes App-logo-spin { + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } +} diff --git a/paste-ui/src/App.js b/paste-ui/src/App.js new file mode 100644 index 0000000..215de9c --- /dev/null +++ b/paste-ui/src/App.js @@ -0,0 +1,20 @@ +import './style.css'; + +import List from './list'; +import View from './view'; + +import MovingDot from './stateExample'; + + +function App() { + let asdf = "aasdf"; + return ( +
+ + + +
+ ); +} + +export default App; diff --git a/paste-ui/src/App.test.js b/paste-ui/src/App.test.js new file mode 100644 index 0000000..1f03afe --- /dev/null +++ b/paste-ui/src/App.test.js @@ -0,0 +1,8 @@ +import { render, screen } from '@testing-library/react'; +import App from './App'; + +test('renders learn react link', () => { + render(); + const linkElement = screen.getByText(/learn react/i); + expect(linkElement).toBeInTheDocument(); +}); diff --git a/paste-ui/src/api.js b/paste-ui/src/api.js new file mode 100644 index 0000000..e69de29 diff --git a/paste-ui/src/index.css b/paste-ui/src/index.css new file mode 100644 index 0000000..ec2585e --- /dev/null +++ b/paste-ui/src/index.css @@ -0,0 +1,13 @@ +body { + margin: 0; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', + 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', + sans-serif; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +code { + font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', + monospace; +} diff --git a/paste-ui/src/index.js b/paste-ui/src/index.js new file mode 100644 index 0000000..d563c0f --- /dev/null +++ b/paste-ui/src/index.js @@ -0,0 +1,17 @@ +import React from 'react'; +import ReactDOM from 'react-dom/client'; +import './index.css'; +import App from './App'; +import reportWebVitals from './reportWebVitals'; + +const root = ReactDOM.createRoot(document.getElementById('root')); +root.render( + + + +); + +// If you want to start measuring performance in your app, pass a function +// to log results (for example: reportWebVitals(console.log)) +// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals +reportWebVitals(); diff --git a/paste-ui/src/list.js b/paste-ui/src/list.js new file mode 100644 index 0000000..9371367 --- /dev/null +++ b/paste-ui/src/list.js @@ -0,0 +1,46 @@ +import { useState } from "react"; +import { useEffect } from "react"; + + +export default function List() { + const [error, setError] = useState(null); + const [isLoaded, setIsLoaded] = useState(false); + const [items, setItems] = useState([]); + + // Note: the empty deps array [] means + // this useEffect will run once + // similar to componentDidMount() + useEffect(() => { + fetch("http://localhost:6130/api/v1/list") + .then(res => res.json()) + .then( + (result) => { + setIsLoaded(true); + setItems(result); + }, + // Note: it's important to handle errors here + // instead of a catch() block so that we don't swallow + // exceptions from actual bugs in components. + (error) => { + setIsLoaded(true); + setError(error); + } + ) + }, []) + + if (error) { + return
Error: {error.message}
; + } else if (!isLoaded) { + return
Loading...
; + } else { + return ( + + ); + } +} \ No newline at end of file diff --git a/paste-ui/src/reportWebVitals.js b/paste-ui/src/reportWebVitals.js new file mode 100644 index 0000000..5253d3a --- /dev/null +++ b/paste-ui/src/reportWebVitals.js @@ -0,0 +1,13 @@ +const reportWebVitals = onPerfEntry => { + if (onPerfEntry && onPerfEntry instanceof Function) { + import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { + getCLS(onPerfEntry); + getFID(onPerfEntry); + getFCP(onPerfEntry); + getLCP(onPerfEntry); + getTTFB(onPerfEntry); + }); + } +}; + +export default reportWebVitals; diff --git a/paste-ui/src/setupTests.js b/paste-ui/src/setupTests.js new file mode 100644 index 0000000..8f2609b --- /dev/null +++ b/paste-ui/src/setupTests.js @@ -0,0 +1,5 @@ +// jest-dom adds custom jest matchers for asserting on DOM nodes. +// allows you to do things like: +// expect(element).toHaveTextContent(/react/i) +// learn more: https://github.com/testing-library/jest-dom +import '@testing-library/jest-dom'; diff --git a/paste-ui/src/stateExample.js b/paste-ui/src/stateExample.js new file mode 100644 index 0000000..91fee18 --- /dev/null +++ b/paste-ui/src/stateExample.js @@ -0,0 +1,32 @@ +import { useState } from 'react'; +export default function MovingDot() { + const [position, setPosition] = useState({ + x: 0, + y: 0 + }); + return ( +
{ + setPosition({ + x: e.clientX, + y: e.clientY + }); + }} + style={{ + position: 'relative', + width: '100vw', + height: '100vh', + }}> +
+
+ ); +} \ No newline at end of file diff --git a/paste-ui/src/style.css b/paste-ui/src/style.css new file mode 100644 index 0000000..472b18c --- /dev/null +++ b/paste-ui/src/style.css @@ -0,0 +1,71 @@ +nav { + border-bottom: 3px solid #000; + padding-bottom: 10px; +} +a { + text-decoration: none; + color: #268bd2; +} +a:visited { + color: #d22653; +} +a:hover { + text-decoration: underline; +} + +code { + color: #9672d5; + /* background-color: #ff000020; */ + /* padding: 2px; */ + font-size: .8em; + font-family: "Roboto Mono", "Monaco", "Lucida Console", "DejaVu Sans Mono", "monospace"; +} + +pre code { + color: #000; + background-color: #FFFFEA; + display: block; + padding: 10px; + border: 1px solid; + line-height: 1.1; + overflow: auto; +} + + +blockquote { + border-left: 4px solid #aaa; + padding-left: 1em; +} + +/* + * The following was shamelessly ripped from: + * http://bettermotherfuckingwebsite.com/ + * And subsequently modified to suit my needs + */ + +body { + margin: 40px auto; + max-width: 80%; + line-height: 1.6; + font-size: 1em; + color: #444; + padding: 0 10px; + /* Added because some browsers don't default to white */ + background-color: #fff; +} + +img { + width: 100%; + height: auto; +} + +h1,h2,h3 { + line-height: 1.2 +} + +@media screen and (min-width: 960px) { + body { + max-width: 768px; + } +} + diff --git a/paste-ui/src/view.js b/paste-ui/src/view.js new file mode 100644 index 0000000..e3bf0df --- /dev/null +++ b/paste-ui/src/view.js @@ -0,0 +1,54 @@ +import { useState } from "react"; +import { useEffect } from "react"; + + +export default function View(props) { + const [error, setError] = useState(null); + const [isLoaded, setIsLoaded] = useState(false); + const [item, setItems] = useState([]); + + // Note: the empty deps array [] means + // this useEffect will run once + // similar to componentDidMount() + useEffect(() => { + fetch("http://localhost:6130/api/v1/view/" + props.id) + .then(res => res.json()) + .then( + (result) => { + setIsLoaded(true); + setItems(result); + }, + // Note: it's important to handle errors here + // instead of a catch() block so that we don't swallow + // exceptions from actual bugs in components. + (error) => { + setIsLoaded(true); + setError(error); + } + ) + }, []) + + if (error) { + return
Error: {error.message}
; + } else if (!isLoaded) { + return
Loading...
; + } else { + if ('Code' in item && item.Code != 200) { + return ( +

+ Error: {item.Code} {item.Msg} +

+ ); + } + return ( +
+

ID: {props.id}

+
+                
+                    {item.Content}
+                
+            
+
+ ); + } +} \ No newline at end of file -- cgit v1.2.3