Skip to content

Commit

Permalink
This works but is slow to render large updates
Browse files Browse the repository at this point in the history
  • Loading branch information
robertecurtin committed Jan 11, 2024
1 parent 129708c commit 6f05f0a
Show file tree
Hide file tree
Showing 9 changed files with 104,428 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package-lock=false
engine-strict=true
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
21.5.0
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"name": "neat-stuff",
"name": "regex-gui",
"version": "1.0.0",
"dependencies": {
"bootstrap": "5.2.3",
"gh-pages": "5.0.0",
"open-graph": "^0.2.6",
"prop-types": "^15.7.2",
"bootstrap": "5.3.2",
"gh-pages": "6.1.1",
"open-graph": "0.2.6",
"prop-types": "15.8.1",
"react": "18.2.0",
"react-bootstrap": "2.7.2",
"react-bootstrap": "2.9.2",
"react-dom": "18.2.0",
"react-scripts": "5.0.1"
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"description": "Links to cool stuff",
"description": "Simple gui for running a regex against a word list",
"main": "index.js",
"scripts": {
"predeploy": "npm run build",
Expand All @@ -24,8 +25,8 @@
"fix": "eslint 'src/**.js' 'src/**/*.js' --fix"
},
"devDependencies": {
"eslint": "^7.32.0",
"eslint-plugin-react": "^7.25.1"
"eslint": "8.56.0",
"eslint-plugin-react": "7.33.2"
},
"author": "Robert Curtin",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, { Component } from 'react';
import Links from './Links';
import Intro from './Intro';
import RegexWidget from './RegexWidget';
import 'bootstrap/dist/css/bootstrap.min.css';

class App extends Component {
render () {
return <div className='App'>
<Intro />
<Links />
<RegexWidget />
</div>;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Intro.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function Intro() {
<Row>
{PadRemainingSpace}
<Col>
Stuff Robert thought was neat!
<a href='https://www.debuggex.com/cheatsheet/regex/javascript'>Javascript regex cheat sheet</a>
</Col>
{PadRemainingSpace}
</Row>
Expand Down
50 changes: 50 additions & 0 deletions src/RegexWidget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react';
import { ListGroup, ListGroupItem, Accordion, Button, Form } from 'react-bootstrap';
import dictionary from './dictionary.json';

function RegexWidget(props) {
const [result, setResult] = React.useState([]);
const [regex, setRegex] = React.useState("Enter regex");
const [useFixedLength, setUseFixedLength] = React.useState(false);

const handleSubmit = async (event) => {
const regexp = new RegExp(useFixedLength ? '^' + regex + '$' : regex, 'ig');
event.preventDefault();
event.stopPropagation();
setResult(dictionary.filter(a => regexp.test(a)));
};

const handleRegexChanged = (e) => {
console.log(e);
setRegex(e.target.value);
};

const handleFixedLengthCheckboxChange = (e) => {
console.log(e);
setUseFixedLength(e.target.value);
};

return <div className='RegexWidget'>
<Form>
<Form.Group className="mb-3" controlId="formBasicEmail">
<Form.Check label="Fixed length" onChange={handleFixedLengthCheckboxChange} />
<Form.Control type="email" placeholder="Enter regex" onChange={handleRegexChanged} />
</Form.Group>

<Button variant="primary" type="submit" onClick={handleSubmit}>
Submit
</Button>
</Form>
<ListGroup>

{
result.map((a) => {
return <ListGroup.Item key={a}>{a}</ListGroup.Item>;
})
}
</ListGroup>
</div>;
}

export default RegexWidget;

Loading

0 comments on commit 6f05f0a

Please sign in to comment.