Improvements all around :)
This commit is contained in:
parent
9a9956304a
commit
2f6e9acb4a
7 changed files with 255 additions and 262 deletions
|
|
@ -13,11 +13,6 @@ export default async (req: Request, res: Response) => {
|
|||
return res.status(404).send("PASTE_EXPIRED")
|
||||
}
|
||||
|
||||
if (req.query && paste.syntax === null) {
|
||||
paste.syntax = Object.keys(req.query)[0]
|
||||
await paste.save()
|
||||
}
|
||||
|
||||
return res.json({
|
||||
paste: paste.paste,
|
||||
syntax: paste.syntax
|
||||
|
|
|
|||
|
|
@ -2,42 +2,19 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<link rel="icon" href="%PUBLIC_URL%/app-icon.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta name="theme-color" content="#17a2b8" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Web site created using create-react-app"
|
||||
content="Utils for Devs!"
|
||||
/>
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||
-->
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/app-icon.png" />
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
Only files inside the `public` folder can be referenced from the HTML.
|
||||
|
||||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>React App</title>
|
||||
<title>oitsjustjo.se - Utils for Devs!</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
If you open it directly in the browser, you will see an empty page.
|
||||
|
||||
You can add webfonts, meta tags, or analytics to this file.
|
||||
The build step will place the bundled scripts into the <body> tag.
|
||||
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -1,25 +1,8 @@
|
|||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "logo192.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo512.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"short_name": "oitsjustjo.se",
|
||||
"name": "Utils for Devs!",
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
"theme_color": "#17a2b8",
|
||||
"background_color": "#252525"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,15 @@ import 'ace-builds';
|
|||
import 'ace-builds/src-noconflict/theme-github';
|
||||
import React from 'react';
|
||||
import AceEditor from 'react-ace';
|
||||
import { Container } from 'react-bootstrap';
|
||||
import Syntax from './paste/Syntax.json';
|
||||
|
||||
const reverseSearch = (syntax) => Object.keys(Syntax).filter((x) => Syntax[x] === syntax);
|
||||
|
||||
export default ({ paste, syntax }) => (
|
||||
<div
|
||||
className="px-5 py-5"
|
||||
style={{ width: '100vw', height: 'calc(100vh - 3.5em)' }}
|
||||
>
|
||||
<div className="v-center">
|
||||
<h4 className="text-center">{`Viewing ${reverseSearch(syntax)} File`}</h4>
|
||||
<Container className="shadow paste-view p-0">
|
||||
<AceEditor
|
||||
mode={`${syntax}`}
|
||||
theme="github"
|
||||
|
|
@ -23,6 +26,8 @@ export default ({ paste, syntax }) => (
|
|||
tabSize="4"
|
||||
width="100%"
|
||||
height="100%"
|
||||
className="rounded"
|
||||
/>
|
||||
</Container>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -31,17 +31,39 @@ export default () => {
|
|||
loading: false,
|
||||
result: null,
|
||||
});
|
||||
const [renderState, setRenderState] = useState({
|
||||
paste: null,
|
||||
notFound: false,
|
||||
});
|
||||
|
||||
const query = new URLSearchParams(window.location.search);
|
||||
const isValid = state.paste && state.syntax && state.expiresAt;
|
||||
const [render, setRender] = useState(null);
|
||||
|
||||
// Check if the user is _viewing_ a paste
|
||||
if (query.has('id')) {
|
||||
if (!render) {
|
||||
getTxtHandler(query.get('id'))
|
||||
.then((d) => setRender(d));
|
||||
return (<h1 className="v-center">Loading...</h1>);
|
||||
// If the paste isn't loaded:
|
||||
if (!renderState.paste) {
|
||||
// If the paste attempted to load but wasn't found
|
||||
if (renderState.notFound) {
|
||||
return <h2 className="v-center">Paste Not Found</h2>;
|
||||
}
|
||||
return (<TextRender paste={render.paste} syntax={render.syntax} />);
|
||||
|
||||
// Grab the paste, and set it
|
||||
getTxtHandler(query.get('id'))
|
||||
.then((paste) => setRenderState({ ...renderState, paste }))
|
||||
.catch(() => setRenderState({ ...renderState, notFound: true }));
|
||||
|
||||
// Render nice loading text :)
|
||||
return <h1 className="v-center">Loading...</h1>;
|
||||
}
|
||||
|
||||
// Return the actual paste with the data!
|
||||
return (
|
||||
<TextRender
|
||||
paste={renderState.paste.paste}
|
||||
syntax={renderState.paste.syntax}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const submit = (evt) => {
|
||||
|
|
@ -75,7 +97,9 @@ export default () => {
|
|||
onChange={(evt) => setState({ ...state, syntax: evt.target.value })}
|
||||
>
|
||||
{Object.keys(Syntax).map((name, idx) => (
|
||||
<option selected={idx === 0} value={Syntax[name]}>{name}</option>
|
||||
<option selected={idx === 0} value={Syntax[name]}>
|
||||
{name}
|
||||
</option>
|
||||
))}
|
||||
</Form.Control>
|
||||
</InputGroup>
|
||||
|
|
@ -120,15 +144,18 @@ export default () => {
|
|||
onChange={(evt) => setState({ ...state, expiresAt: evt.target.value })}
|
||||
>
|
||||
{Object.keys(expirationOptions).map((name, idx) => (
|
||||
<option selected={idx === 0} value={expirationOptions[name]}>{name}</option>
|
||||
<option selected={idx === 0} value={expirationOptions[name]}>
|
||||
{name}
|
||||
</option>
|
||||
))}
|
||||
</Form.Control>
|
||||
|
||||
<InputGroup.Append>
|
||||
<Button type="submit" disabled={!isValid || state.loading}>Submit</Button>
|
||||
<Button type="submit" disabled={!isValid || state.loading}>
|
||||
Submit
|
||||
</Button>
|
||||
</InputGroup.Append>
|
||||
</InputGroup>
|
||||
|
||||
</Form.Group>
|
||||
</Form>
|
||||
|
||||
|
|
|
|||
|
|
@ -45,3 +45,9 @@
|
|||
.custom.custom-file *, input.custom-file-input {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.paste-view {
|
||||
height: 75vh !important;
|
||||
width: 100%;
|
||||
max-width: 1024px;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue