Commit c31ed3b3 authored by gijs's avatar gijs

The cleaner frontend

parent fa9b1383
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `npm start`
Runs the app in the development mode.<br>
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.<br>
You will also see any lint errors in the console.
### `npm test`
Launches the test runner in the interactive watch mode.<br>
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `npm run build`
Builds the app for production to the `build` folder.<br>
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.<br>
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `npm run eject`
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
### Code Splitting
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
### Analyzing the Bundle Size
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
### Making a Progressive Web App
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
### Advanced Configuration
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
### Deployment
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
### `npm run build` fails to minify
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
{
"name": "cleaning-interface",
"version": "0.1.0",
"private": true,
"dependencies": {
"connected-react-router": "^6.2.1",
"history": "^4.7.2",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-redux": "^6.0.0",
"react-router-dom": "^4.3.1",
"react-scripts": "2.1.3",
"redux": "^4.0.1",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta name="theme-color" content="#000000" />
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<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>The Cleaner</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>
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
npm install --save redux react-redux react-router-dom connected-react-router redux-thunk history redux-logger
.App {
text-align: center;
}
.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 40vmin;
}
.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);
}
}
.sentence--classlist {
display: grid;
grid-template-columns: 25% 25% 25% 25%;
grid-auto-rows: 150px;
}
.sentence--classlist--class {
padding: 1em;
margin: .5em;
background: white;
color: block;
display: flex;
text-align: center;
align-items: center;
justify-content: space-around;
border: 2px solid transparent;
border-radius: 5px 5px;
font-size: 120%;
}
.sentence--classlist--class:hover {
border: 2px solid black;
}
.sentence--classlist--class:active {
border: 2px solid orange;
box-shadow: inset 0px 0px 2px rgba(0,0,0,.5);
}
.sentence--classlist--class[data-selected="true"] {
border: 2px solid blue;
}
.sentence {
font-size: 200%;
line-height: 1.75;
font-family: serif;
padding: 1em 3em;
overflow-y: auto;
display: flex;
flex-direction: column;
justify-content: center;
}
.sentence--window {
color: rgb(75%,75%,75%);
}
#annotator {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: auto;
display: flex;
flex-direction: column;
}
.sentence--actions button {
margin: 0 1em;
font-size: 120%;
}
.sentence--actions {
flex: 0 0;
padding: 1em 0;
border-top: 1px solid black;
border-bottom: 1px solid black;
}
.sentence {
flex: 1;
}
.sentence--classlist {
flex: 0 0;
}
.interface--hint {
padding: 1em 0 0 0;
font-size: 120%;
}
.document {
font-size: 125%;
font-family: serif;
}
.document--line {
position: relative;
text-align: left;
border-bottom: 1px dotted currentColor;
}
.document--line[data-clean="false"] {
color: grey;
background-color: #efefef;
}
.document--line .document--line--actions {
display: none;
position: absolute;
top: -.3em;
left: 0;
}
.document--line:hover .document--line--actions {
display: block;
}
textarea {
font: inherit;
width: 50ch;
position: absolute;
top: calc(-.25em + 2px);
left: -1px;
right: 0;
height: calc(100%);
max-width: 100%;
padding: 0;
}
.document--line--editor--buttons {
position: absolute;
left: 0;
top: -.3em;
white-space: nowrap;
}
button {
margin: .2em .5em;
}
.document--line {
display: flex;
padding: .25em 0;
min-height: 1.5em;
}
.document--line--left,
.document--line--right {
position: relative;
flex: 1 0;
}
.document--line--middle {
position: relative;
flex: 0 0 40ch;
}
p {
margin: 0;
}
.document--actions {
position: sticky;
z-index: 2;
top: 0;
padding-top: .5em;
padding-bottom: 2em;
text-align: right;
}
.document--title {
position: fixed;
top: 0;
right: 0;
left: 0;
z-index: 1;
text-align: left;
padding-top: .8em;
padding-left: .5em;
padding-bottom: 2em;
background: linear-gradient(to bottom, white, white 50%, rgba(255,255,255, 0) 100%);
}
#application--message {
position: fixed;
z-index: 3;
padding-bottom: 2em;
padding-top: .8em;
top: 0;
left: 0;
right: 0;
font-size: 125%;
background: linear-gradient(to bottom, rgba(255, 255, 0, .8), rgba(255, 255, 0, .8) 50%, rgba(255, 255, 0, 0) 100%);
}
#application--message button {
border: 1px solid black;
border-radius: 6px 6px;
margin-left: .5em;
background: none;
font: inherit;
}
\ No newline at end of file
import React, { Component } from 'react';
import { BrowserRouter as Router, Route } from 'react-router-dom';
import Cleaner from './containers/Cleaner';
import './App.css';
class App extends Component {
render() {
return (
<div className="App">
<Router>
<Route exact path="/" component={ Cleaner } />
</Router>
</div>
);
}
}
export default App;
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
export const MESSAGE_CLOSE = 'MESSAGE_CLOSE';
export const SESSION_START = "SESSION_START";
export const PRINT = "PRINT";
export const messageClose = () => ({ type: MESSAGE_CLOSE });
export const sessionStart = () => ({ type: SESSION_START });
export const print = () => ({ type: PRINT });
\ No newline at end of file
import {
documentGet as apiDocumentGet,
documentPost as apiDocumentPost
} from '../services/api';
export const DOCUMENT_LOAD = "DOCUMENT_LOAD";
export const DOCUMENT_LOAD_FAIL = "DOCUMENT_LOAD_FAIL";
export const DOCUMENT_LOAD_SUCCESS = "DOCUMENT_LOAD_SUCCESS";
export const DOCUMENT_STORE = "DOCUMENT_STORE";
export const DOCUMENT_STORE_FAIL = "DOCUMENT_STORE_FAIL";
export const DOCUMENT_STORE_SUCCESS = "DOCUMENT_STORE_SUCCESS";
export const documentLoad = () => (dispatch, _) => {
dispatch({ type: DOCUMENT_LOAD });
apiDocumentGet()
.then((data) => {console.log(data); dispatch(documentLoadSuccess(data)) })
.catch(() => dispatch(documentLoadFail()))
}
export const documentLoadFail = () => ({ type: DOCUMENT_LOAD_FAIL });
export const documentLoadSuccess = ({ document, lines }) => ({
type: DOCUMENT_LOAD_SUCCESS,
document, lines
});
export const documentStore = () => (dispatch, getState) => {
const { document, lines } = getState();
dispatch({ type: DOCUMENT_STORE });
apiDocumentPost(document, lines.lines)
.then(() => dispatch(documentStoreSuccess()))
.catch(() => dispatch(documentStoreFail()))
};
export const documentStoreFail = () => ({
type: DOCUMENT_STORE_FAIL,
});
export const documentStoreSuccess = () => ({
type: DOCUMENT_STORE_SUCCESS,
});
\ No newline at end of file
export const ACTION_NAME = 'ACTION_NAME';
export const GREETING_CHANGE = 'GREETING_CHANGE';
export const actionName = () => ({
type: ACTION_NAME
});
export const greetingChange = (greeting) => ({
type: GREETING_CHANGE,
greeting // short for: greeting: greeting
})
\ No newline at end of file
import api, {
linePost as apiLinePost
} from '../services/api';
// lineeditstart
export const LINE_EDIT_START = "LINE_EDIT_START";
export const LINE_EDIT_DONE = "LINE_EDIT_DONE";
export const LINE_STORE = "LINE_STORE";
export const LINE_EDIT_CANCEL = "LINE_EDIT_CANCEL";
export const LINE_STORE_FAIL = "LINE_STORE_FAIL";
export const LINE_STORE_SUCCESS = "LINE_STORE_SUCCESS";
export const LINE_MARK_CLEAN = "LINE_MARK_CLEAN";
export const LINE_MARK_DIRTY = "LINE_MARK_DIRTY";
export const LINE_EDIT_SENTENCE = "LINE_EDIT_SENTENCE";
export const lineEditStart = (lineIdx) => ({ type: LINE_EDIT_START, lineIdx });
export const lineEditCancel = () => ({ type: LINE_EDIT_CANCEL });
export const lineEditDone = () => ({ type: LINE_EDIT_DONE });
export const lineEditSentence = (activeLineText) => ({ type: LINE_EDIT_SENTENCE, activeLineText });
export const lineStore = () => (dispatch, getState) => {
const { lines, application } = getState();
const { document, line, sentence, clean } = lines[application.activeLine];
dispatch({ type: LINE_STORE });
apiLinePost(document, line, sentence, clean)
.then(() => dispatch(lineStoreSuccess()))
.catch(() => dispatch(lineStoreFail()))
}
export const lineStoreFail = () => ({ type: LINE_STORE_FAIL });
export const lineStoreSuccess = () => ({ type: LINE_STORE_SUCCESS });
export const lineMarkClean = (lineIdx) => ({ type: LINE_MARK_CLEAN, lineIdx });
export const lineMarkDirty = (lineIdx) => ({ type: LINE_MARK_DIRTY, lineIdx });
\ No newline at end of file
import React, { Component } from 'react';
import Document from './Document';
// import SentenceActions from './SentenceActions';
// import SentenceClassList from './SentenceClassList';
import { t } from '../utils'
export const Cleaner = class extends Component {
componentDidMount = () => {
this.props.documentLoad();
}
render = () => {
const {
document,
activeLineIdx,
activeLineText,
lines,
message,
hasUnsavedChanges,
documentLoading,
documentStoring,
documentLoad,
documentStore,
lineEditCancel,
lineEditDone,
lineEditSentence,
lineEditStart,
lineMarkClean,
lineMarkDirty,
messageClose
} = this.props;
return <section id="cleaner">
{ (message) ? <section id="application--message">{ message } <button onClick={ messageClose }>{ t('close') }</button></section> : '' }
<Document
document={ document }
activeLineIdx={ activeLineIdx }
activeLineText={ activeLineText }
lines={ lines }
hasUnsavedChanges={ hasUnsavedChanges }
documentLoading={ documentLoading }
documentStoring={ documentStoring }
documentLoad={ documentLoad }
documentStore={ documentStore }
lineEditCancel={ lineEditCancel }
lineEditDone={ lineEditDone }
lineEditSentence={ lineEditSentence }
lineEditStart={ lineEditStart }
lineMarkClean={ lineMarkClean }
lineMarkDirty={ lineMarkDirty }
/>
{/* <Sentence sentence={ sentence } before={ before } after={ after }/> */}
{/* <SentenceActions
sentenceLoading={ sentenceLoading }
sentenceClassSelected={ selectedClass }
sentenceLoad={ sentenceLoad }
sentencePost={ sentencePost }
sentenceMarkDirty={ sentenceMarkDirty } />
<section className="interface--hint">{ t('select_class_explanation') }</section>
<SentenceClassList
classesLoading={ classesLoading }
sentenceClasses={ sentenceClasses }
sentenceClassSelected={ selectedClass }
sentenceClassSelect={ sentenceClassSelect } /> */}
</section>
}
}
export default Cleaner;
\ No newline at end of file
import React from 'react';
import { t } from '../utils';
export const LineEditor = ({ activeLineText, lineEditDone, lineEditCancel, lineEditSentence }) => (
<section class="document--line document--line--editor">
<section class="document--line--left">
</section>
<section class="document--line--middle">
<p>{ activeLineText }</p>
<textarea onChange={(e) => lineEditSentence(e.target.value)} value={activeLineText} autoFocus />
</section>
<section class="document--line--right">
<section class="document--line--editor--buttons">
<button onClick={ lineEditDone }>{ t('sentence_edit_save') }</button>
<button onClick={ lineEditCancel }>{ t('sentence_edit_cancel') }</button>
</section>
</section>
</section>
)
export const Line = ({ sentence, clean, clean_annotation, lineMarkClean, lineMarkDirty, lineEditStart }) => (
<section class="document--line" data-clean={ (clean) ? true : false }>
<section class="document--line--left">
</section>
<section class="document--line--middle">
<p>{ sentence }</p>
</section>
<section class="document--line--right">
<section class="document--line--actions">
{ (clean) ? <button onClick={ lineMarkDirty }>{ t('line_mark_dirty') }</button> : <button onClick={ lineMarkClean }>{ t('line_mark_clean') }</button> }
<button onClick={ lineEditStart }>{ t('line_edit') }</button>
</section>
</section>
</section>
)
export const Document = ({
document,
activeLineIdx,
activeLineText,
lines,
hasUnsavedChanges,
documentLoading,
documentStoring,
documentLoad,
documentStore,
lineEditCancel,
lineEditDone,
lineEditSentence,
lineEditStart,
lineMarkClean,
lineMarkDirty,
print
}) => (
<section class="document">
<section class="document--actions">
<button onClick={ documentLoad } disabled={ documentLoading }>{ t('load_document') }</button>
<button onClick={ documentStore } disabled={ (!hasUnsavedChanges) || documentStoring }>{ t('store_document') }</button>
<button onClick={ print } disabled>{ t('print') }</button>
</section>
<section class="document--title">
<header>{ t('cleaning') }: { document }</header>
</section>
{ lines.map((line, lineIdx) => {
if (lineIdx === activeLineIdx) {
return <LineEditor
activeLineText={ activeLineText }
lineEditDone={ lineEditDone }
lineEditCancel={ lineEditCancel }
lineEditSentence={ li