Improvements all around :)

This commit is contained in:
oitsjustjose 2020-10-16 14:48:18 -05:00
commit 2f6e9acb4a
7 changed files with 255 additions and 262 deletions

View file

@ -13,11 +13,6 @@ export default async (req: Request, res: Response) => {
return res.status(404).send("PASTE_EXPIRED") 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({ return res.json({
paste: paste.paste, paste: paste.paste,
syntax: paste.syntax syntax: paste.syntax

View file

@ -2,42 +2,19 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <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="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" /> <meta name="theme-color" content="#17a2b8" />
<meta <meta
name="description" name="description"
content="Web site created using create-react-app" content="Utils for Devs!"
/> />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> <link rel="apple-touch-icon" href="%PUBLIC_URL%/app-icon.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="manifest" href="%PUBLIC_URL%/manifest.json" /> <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!-- <title>oitsjustjo.se - Utils for Devs!</title>
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>
</head> </head>
<body> <body>
<noscript>You need to enable JavaScript to run this app.</noscript> <noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div> <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> </body>
</html> </html>

View file

@ -1,25 +1,8 @@
{ {
"short_name": "React App", "short_name": "oitsjustjo.se",
"name": "Create React App Sample", "name": "Utils for Devs!",
"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"
}
],
"start_url": ".", "start_url": ".",
"display": "standalone", "display": "standalone",
"theme_color": "#000000", "theme_color": "#17a2b8",
"background_color": "#ffffff" "background_color": "#252525"
} }

View file

@ -2,27 +2,32 @@ import 'ace-builds';
import 'ace-builds/src-noconflict/theme-github'; import 'ace-builds/src-noconflict/theme-github';
import React from 'react'; import React from 'react';
import AceEditor from 'react-ace'; 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 }) => ( export default ({ paste, syntax }) => (
<div <div className="v-center">
className="px-5 py-5" <h4 className="text-center">{`Viewing ${reverseSearch(syntax)} File`}</h4>
style={{ width: '100vw', height: 'calc(100vh - 3.5em)' }} <Container className="shadow paste-view p-0">
> <AceEditor
<AceEditor mode={`${syntax}`}
mode={`${syntax}`} theme="github"
theme="github" name="paste_viewer"
name="paste_viewer" fontSize={18}
fontSize={18} value={paste}
value={paste} wrapEnabled
wrapEnabled readOnly
readOnly setOptions={{
setOptions={{ wrapBehavioursEnabled: true,
wrapBehavioursEnabled: true, wrap: true,
wrap: true, }}
}} tabSize="4"
tabSize="4" width="100%"
width="100%" height="100%"
height="100%" className="rounded"
/> />
</Container>
</div> </div>
); );

View file

@ -31,17 +31,39 @@ export default () => {
loading: false, loading: false,
result: null, result: null,
}); });
const [renderState, setRenderState] = useState({
paste: null,
notFound: false,
});
const query = new URLSearchParams(window.location.search); const query = new URLSearchParams(window.location.search);
const isValid = state.paste && state.syntax && state.expiresAt; 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 (query.has('id')) {
if (!render) { // 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>;
}
// Grab the paste, and set it
getTxtHandler(query.get('id')) getTxtHandler(query.get('id'))
.then((d) => setRender(d)); .then((paste) => setRenderState({ ...renderState, paste }))
return (<h1 className="v-center">Loading...</h1>); .catch(() => setRenderState({ ...renderState, notFound: true }));
// Render nice loading text :)
return <h1 className="v-center">Loading...</h1>;
} }
return (<TextRender paste={render.paste} syntax={render.syntax} />);
// Return the actual paste with the data!
return (
<TextRender
paste={renderState.paste.paste}
syntax={renderState.paste.syntax}
/>
);
} }
const submit = (evt) => { const submit = (evt) => {
@ -75,7 +97,9 @@ export default () => {
onChange={(evt) => setState({ ...state, syntax: evt.target.value })} onChange={(evt) => setState({ ...state, syntax: evt.target.value })}
> >
{Object.keys(Syntax).map((name, idx) => ( {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> </Form.Control>
</InputGroup> </InputGroup>
@ -120,24 +144,27 @@ export default () => {
onChange={(evt) => setState({ ...state, expiresAt: evt.target.value })} onChange={(evt) => setState({ ...state, expiresAt: evt.target.value })}
> >
{Object.keys(expirationOptions).map((name, idx) => ( {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> </Form.Control>
<InputGroup.Append> <InputGroup.Append>
<Button type="submit" disabled={!isValid || state.loading}>Submit</Button> <Button type="submit" disabled={!isValid || state.loading}>
Submit
</Button>
</InputGroup.Append> </InputGroup.Append>
</InputGroup> </InputGroup>
</Form.Group> </Form.Group>
</Form> </Form>
{state.result && ( {state.result && (
<h5 className="text-center"> <h5 className="text-center">
<a rel="noopener noreferrer" href={state.result} target="_blank"> <a rel="noopener noreferrer" href={state.result} target="_blank">
{state.result} {state.result}
</a> </a>
</h5> </h5>
)} )}
</Container> </Container>
</CSSTransition> </CSSTransition>

View file

@ -1,174 +1,174 @@
{ {
"PlainText": "plain_text", "PlainText": "plain_text",
"ABAP": "abap", "ABAP": "abap",
"ABC": "abc", "ABC": "abc",
"ActionScript": "actionscript", "ActionScript": "actionscript",
"ADA": "ada", "ADA": "ada",
"ALDA": "alda", "ALDA": "alda",
"Apache Config": "apache_conf", "Apache Config": "apache_conf",
"Apex": "apex", "Apex": "apex",
"AppleScript": "applescript", "AppleScript": "applescript",
"AQL": "aql", "AQL": "aql",
"ASCII-Doc": "asciidoc", "ASCII-Doc": "asciidoc",
"ASL": "asl", "ASL": "asl",
"Assembly (x86)": "assembly_x86", "Assembly (x86)": "assembly_x86",
"AutoHotKey": "autohotkey", "AutoHotKey": "autohotkey",
"BatchFile": "batchfile", "BatchFile": "batchfile",
"C9-Search": "c9search", "C9-Search": "c9search",
"C": "c_cpp", "C": "c_cpp",
"C++": "c_cpp", "C++": "c_cpp",
"Cirru": "cirru", "Cirru": "cirru",
"Clojure": "clojure", "Clojure": "clojure",
"COBOL": "cobol", "COBOL": "cobol",
"CoffeeScript": "coffee", "CoffeeScript": "coffee",
"Cold Fusion": "coldfusion", "Cold Fusion": "coldfusion",
"Crystal": "crystal", "Crystal": "crystal",
"C#": "csharp", "C#": "csharp",
"Csound (document)": "csound_document", "Csound (document)": "csound_document",
"Csound (Orchestra)": "csound_orchestra", "Csound (Orchestra)": "csound_orchestra",
"Csound (Score)": "csound_score", "Csound (Score)": "csound_score",
"CSP": "csp", "CSP": "csp",
"CSS": "css", "CSS": "css",
"Curly": "curly", "Curly": "curly",
"D": "d", "D": "d",
"Dart": "dart", "Dart": "dart",
"Diff": "diff", "Diff": "diff",
"Django": "django", "Django": "django",
"DockerFile": "dockerfile", "DockerFile": "dockerfile",
"Dot": "dot", "Dot": "dot",
"Drools": "drools", "Drools": "drools",
"Edifact": "edifact", "Edifact": "edifact",
"Eiffel": "eiffel", "Eiffel": "eiffel",
"EJS": "ejs", "EJS": "ejs",
"Elixir": "elixir", "Elixir": "elixir",
"Elm": "elm", "Elm": "elm",
"Erlang": "erlang", "Erlang": "erlang",
"Forth": "forth", "Forth": "forth",
"Fortran": "fortran", "Fortran": "fortran",
"F#": "fsharp", "F#": "fsharp",
"FSL": "fsl", "FSL": "fsl",
"FTL": "ftl", "FTL": "ftl",
"G-Code": "gcode", "G-Code": "gcode",
"Gherkin": "gherkin", "Gherkin": "gherkin",
".gitignore": "gitignore", ".gitignore": "gitignore",
"GLSL": "glsl", "GLSL": "glsl",
"Gobstones": "gobstones", "Gobstones": "gobstones",
"GoLang": "golang", "GoLang": "golang",
"GraphQL Schema": "graphqlschema", "GraphQL Schema": "graphqlschema",
"Groovy": "groovy", "Groovy": "groovy",
"HAML": "haml", "HAML": "haml",
"{{HandleBars}}": "handlebars", "{{HandleBars}}": "handlebars",
"Haskell": "haskell", "Haskell": "haskell",
"Haxe": "haxe", "Haxe": "haxe",
"Human JSON": "hjson", "Human JSON": "hjson",
"HTML": "html", "HTML": "html",
"HTML (Elixir)": "html_elixir", "HTML (Elixir)": "html_elixir",
"HTML (Rails)": "rhtml", "HTML (Rails)": "rhtml",
"HTML (Ruby)": "html_ruby", "HTML (Ruby)": "html_ruby",
".ini": "ini", ".ini": "ini",
"IO": "io", "IO": "io",
"Jack": "jack", "Jack": "jack",
"Jade": "jade", "Jade": "jade",
"Java": "java", "Java": "java",
"JavaScript": "javascript", "JavaScript": "javascript",
"JSON": "json", "JSON": "json",
"JSON5": "json5", "JSON5": "json5",
"JSONiq": "jsoniq", "JSONiq": "jsoniq",
"JSP": "jsp", "JSP": "jsp",
"JSSM": "jssm", "JSSM": "jssm",
"JSX": "jsx", "JSX": "jsx",
"Julia": "julia", "Julia": "julia",
"Kotlin": "kotlin", "Kotlin": "kotlin",
"LaTeX": "latex", "LaTeX": "latex",
".less": "less", ".less": "less",
"Liquid": "liquid", "Liquid": "liquid",
"LISP": "lisp", "LISP": "lisp",
"LiveScript": "livescript", "LiveScript": "livescript",
"LogIQL": "logiql", "LogIQL": "logiql",
"LogTalk": "logtalk", "LogTalk": "logtalk",
"LSL": "lsl", "LSL": "lsl",
"LUA": "lua", "LUA": "lua",
"LUApage": "luapage", "LUApage": "luapage",
"Lucene": "lucene", "Lucene": "lucene",
"MakeFile": "makefile", "MakeFile": "makefile",
"MarkDown": "markdown", "MarkDown": "markdown",
"Mask": "mask", "Mask": "mask",
"MatLab": "matlab", "MatLab": "matlab",
"Maze": "maze", "Maze": "maze",
"MediaWiki": "mediawiki", "MediaWiki": "mediawiki",
"Mel": "mel", "Mel": "mel",
"Mixal": "mixal", "Mixal": "mixal",
"Mushcode": "mushcode", "Mushcode": "mushcode",
"MySQL": "mysql", "MySQL": "mysql",
"NGINX": "nginx", "NGINX": "nginx",
"Nim": "nim", "Nim": "nim",
"Nix": "nix", "Nix": "nix",
"NIS": "nsis", "NIS": "nsis",
"Nunjucks": "nunjucks", "Nunjucks": "nunjucks",
"Objective-C": "objectivec", "Objective-C": "objectivec",
"OCaml": "ocaml", "OCaml": "ocaml",
"Pascal": "pascal", "Pascal": "pascal",
"Perl": "perl", "Perl": "perl",
"Perl6": "perl6", "Perl6": "perl6",
"PGSQL": "pgsql", "PGSQL": "pgsql",
"PHP": "php", "PHP": "php",
"PHP (Laravel Blade)": "php_laravel_blade", "PHP (Laravel Blade)": "php_laravel_blade",
"Pig": "pig", "Pig": "pig",
"PowerShell": "powershell", "PowerShell": "powershell",
"Praat": "praat", "Praat": "praat",
"Prisma": "prisma", "Prisma": "prisma",
"Prolog": "prolog", "Prolog": "prolog",
".properties": "properties", ".properties": "properties",
"ProtoBuf": "protobuf", "ProtoBuf": "protobuf",
"Puppet": "puppet", "Puppet": "puppet",
"Python": "python", "Python": "python",
"QML": "qml", "QML": "qml",
"R": "r", "R": "r",
"Razor": "razor", "Razor": "razor",
"RDoc": "rdoc", "RDoc": "rdoc",
"Red": "red", "Red": "red",
"Redshift": "redshift", "Redshift": "redshift",
"RST": "rst", "RST": "rst",
"Ruby": "ruby", "Ruby": "ruby",
"Rust": "rust", "Rust": "rust",
"SASS": "sass", "SASS": "sass",
"Scad": "scad", "Scad": "scad",
"Scala": "scala", "Scala": "scala",
"Scheme": "scheme", "Scheme": "scheme",
"SCSS": "scss", "SCSS": "scss",
"sh": "sh", "sh": "sh",
"Shell Script": "sh", "Shell Script": "sh",
"SJS": "sjs", "SJS": "sjs",
"Slim": "slim", "Slim": "slim",
"Smarty": "smarty", "Smarty": "smarty",
"Snippets": "snippets", "Snippets": "snippets",
"Soy Template": "soy_template", "Soy Template": "soy_template",
"Space": "space", "Space": "space",
"SparQL": "sparql", "SparQL": "sparql",
"SQL": "sql", "SQL": "sql",
"SQL Server": "sqlserver", "SQL Server": "sqlserver",
"Stylus": "stylus", "Stylus": "stylus",
"SVG": "svg", "SVG": "svg",
"Swift": "swift", "Swift": "swift",
"TCL": "tcl", "TCL": "tcl",
"Terraform": "terraform", "Terraform": "terraform",
"TeX": "tex", "TeX": "tex",
"Text": "text", "Text": "text",
"Textile": "textile", "Textile": "textile",
"TOML": "toml", "TOML": "toml",
"TSX": "tsx", "TSX": "tsx",
"Turtle": "turtle", "Turtle": "turtle",
"Twig": "twig", "Twig": "twig",
"TypeScript": "typescript", "TypeScript": "typescript",
"Vala": "vala", "Vala": "vala",
"VSCcript": "vbscript", "VSCcript": "vbscript",
"Velocity": "velocity", "Velocity": "velocity",
"Verilog": "verilog", "Verilog": "verilog",
"VHDL": "vhdl", "VHDL": "vhdl",
"VisualForce": "visualforce", "VisualForce": "visualforce",
"Wollok": "wollok", "Wollok": "wollok",
"XML": "xml", "XML": "xml",
"XQuery": "xquery", "XQuery": "xquery",
"YAML": "yaml", "YAML": "yaml",
"Zeek": "zeek" "Zeek": "zeek"
} }

View file

@ -45,3 +45,9 @@
.custom.custom-file *, input.custom-file-input { .custom.custom-file *, input.custom-file-input {
cursor: pointer; cursor: pointer;
} }
.paste-view {
height: 75vh !important;
width: 100%;
max-width: 1024px;
}