Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Commit

Permalink
Use separate components for SubmitForm, ReviewLink and ConfirmForm
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKohler committed Jan 9, 2019
1 parent ebbf468 commit 5acfb3a
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 103 deletions.
87 changes: 87 additions & 0 deletions web/src/components/confirm-form.jsx
@@ -0,0 +1,87 @@
import React from 'react';

import ReviewLink from './review-link';

export default class ConfirmForm extends React.Component {
constructor(props) {
super(props);

this.onSubmit = this.props.onSubmit.bind(this);
this.onReview = this.props.onReview.bind(this);
this.onCancel = this.props.onCancel.bind(this);
}

render() {
const {
submitted,
existing,
invalidated,
filtered,
validated,
unreviewed,
readyCount,
} = this.props;

return (
<form onSubmit={this.onSubmit}>
<h2>Confirm New Sentences</h2>
<p>
{`${submitted.length} sentences found.`}
</p>

{(existing && existing.length > 0) && (
<p>
{`${existing.length} sentences were previously submitted.`}
</p>
)}

{invalidated.length + filtered.length > 0 && (
<p style={{color: 'red'}}>
{
`${filtered.length} sentences were not matching the requirements.` +
(invalidated.length > 0 ?
` (${invalidated.length} more rejected by you) ` : '')
}
</p>
)}

{validated.length + invalidated.length > 0 && (
<p>
{`-- ${validated.length + invalidated.length}`} {}
sentences are already reviewed. Great job!
</p>
)}

<p><b>{`${readyCount} sentences ready for submission!`}</b></p>

{unreviewed.length > 0 && (
<p>
{`-- ${unreviewed.length} of these sentences are unreviewed. If you want, you can also review your sentences now before submitting them.`}&nbsp;
<ReviewLink onReview={this.onReview}
sentences={unreviewed} />
</p>
)}

<p>
By submitting these sentences you grant a {}
<a href="https://en.wikipedia.org/wiki/Public_domain" target="_blank">Public Domain License</a> {}
for self-written sentences, or declare that sentences from a third-party are under Public Domain License
and can be used.
</p>
<section id="confirm-buttons">
<button type="submit" disabled={readyCount === 0}>Confirm</button>
<button onClick={this.onCancel}>Cancel</button>
</section>

{invalidated.length + filtered.length > 0 && (
<section>
<h2>Filtered sentences due to requirements failing:</h2>
<p>Please check the <a href="https://common-voice.github.io/sentence-collector/#/how-to">guidelines</a>.</p>

{filtered.map(sentence => <p key={sentence}>{sentence}</p>)}
</section>
)}
</form>
);
}
}
99 changes: 3 additions & 96 deletions web/src/components/pages/add.jsx
@@ -1,8 +1,10 @@
import React from 'react';

import WebDB from '../../web-db';
import LanguageSelector from '../language-selector';
import SubmitForm from '../submit-form';
import ConfirmForm from '../confirm-form';
import ReviewForm from '../review-form';

import '../../../css/add.css';

import * as validation from '../../validation';
Expand Down Expand Up @@ -241,98 +243,3 @@ export default class Add extends React.Component {
}
}
}

const ReviewLink = (props) => {
return props.sentences.length > 0 && (
<a href="#" onClick={evt => {
evt.preventDefault();
props.onReview && props.onReview();
}}>Review</a>
);
};

const ConfirmForm = (props) => (
<form onSubmit={props.onSubmit}>
<h2>Confirm New Sentences</h2>
<p>
{`${props.submitted.length} sentences found.`}
</p>
{(props.existing && props.existing.length > 0) && (
<p>
{`${props.existing.length} sentences were previously submitted.`}
</p>
)}
{props.invalidated.length + props.filtered.length > 0 && (
<p style={{color: 'red'}}>
{
`${props.filtered.length} sentences were not matching the requirements.` +
(props.invalidated.length > 0 ?
` (${props.invalidated.length} more rejected by you) ` : '')
}
</p>
)}
{props.validated.length + props.invalidated.length > 0 && (
<p>
{`-- ${props.validated.length + props.invalidated.length}`}&nbsp;
sentences are already reviewed. Great job!
</p>
)}
<p><b>{`${props.readyCount} sentences ready for submission!`}</b></p>
{props.unreviewed.length > 0 && (
<p>
{`-- ${props.unreviewed.length} of these sentences are unreviewed. If you want, you can also review your sentences now before submitting them.`}&nbsp;
<ReviewLink onReview={props.onReview}
sentences={props.unreviewed} />
</p>
)}
<p>
By submitting these sentences you grant a {}
<a href="https://en.wikipedia.org/wiki/Public_domain" target="_blank">Public Domain License</a> {}
for self-written sentences, or declare that sentences from a third-party are under Public Domain License
and can be used.
</p>
<section id="confirm-buttons">
<button type="submit" disabled={props.readyCount === 0}>Confirm</button>
<button onClick={props.onCancel}>Cancel</button>
</section>

{props.invalidated.length + props.filtered.length > 0 && (
<section>
<h2>Filtered sentences due to requirements failing:</h2>
<p>Please check the <a href="https://common-voice.github.io/sentence-collector/#/how-to">guidelines</a>.</p>
{props.filtered.map(sentence => <p key={sentence}>{sentence}</p>)}
</section>
)}
</form>
);


const SubmitForm = (props) => (
<form id="add-form" onSubmit={props.onSubmit}>
<h2>Add Sentences</h2>
<p>Please add your sentences by typing or copy & pasting them below. <strong>Please make sure to add one sentence per line.</strong></p>
<section id="form-message">
{props.message}
</section>
<section id="form-error">
{props.error}
</section>
<section>
<label className="language-selector-label" htmlFor="language-selector">
Select Language
</label>
<LanguageSelector name="language-selector" only={props.languages}/>
</section>
<section>
<label htmlFor="sentences-input">Enter sentences (one per line)</label>
<textarea id="sentences-input" />
</section>
<section>
<label htmlFor="source-input">Where did you get these sentences from?</label>
<input id="source-input" type="text" />
</section>
<section>
<button>Submit</button>
</section>
</form>
);
14 changes: 7 additions & 7 deletions web/src/components/review-form.jsx
Expand Up @@ -129,13 +129,13 @@ export default class ReviewForm extends React.Component {
const Pager = (props) => (
<section className="pager-container">{
[
[0, '1'],
[props.page - 1, '<'],
[props.page, props.page + 1],
[props.page + 1, '>'],
[props.lastPage, props.lastPage + 1],
].map(([ page, text ]) => (
<span>{
['idx1', 0, '1'],
['idx2', props.page - 1, '<'],
['idx3', props.page, props.page + 1],
['idx4', props.page + 1, '>'],
['idx5', props.lastPage, props.lastPage + 1],
].map(([ idx, page, text ]) => (
<span key={idx}>{
(page >= 0 && page <= props.lastPage) ? (
<button className={ props.page === page ? 'active pager' : 'pager' }
onClick={evt => {
Expand Down
12 changes: 12 additions & 0 deletions web/src/components/review-link.jsx
@@ -0,0 +1,12 @@
import React from 'react';

const ReviewLink = (props) => {
return props.sentences.length > 0 && (
<a href="#" onClick={evt => {
evt.preventDefault();
props.onReview && props.onReview();
}}>Review</a>
);
};

export default ReviewLink;
52 changes: 52 additions & 0 deletions web/src/components/submit-form.jsx
@@ -0,0 +1,52 @@
import React from 'react';

import LanguageSelector from './language-selector';

export default class SubmitForm extends React.Component {
constructor(props) {
super(props);

this.onSubmit = this.props.onSubmit.bind(this);
}

render() {
const {
message,
error,
languages,
} = this.props;

return (
<form id="add-form" onSubmit={this.onSubmit}>
<h2>Add Sentences</h2>
<p>Please add your sentences by typing or copy & pasting them below. <strong>Please make sure to add one sentence per line.</strong></p>

<section id="form-message">
{message}
</section>
<section id="form-error">
{error}
</section>

<section>
<label className="language-selector-label" htmlFor="language-selector">
Select Language
</label>
<LanguageSelector name="language-selector" only={languages}/>
</section>
<section>
<label htmlFor="sentences-input">Enter sentences (one per line)</label>
<textarea id="sentences-input" />
</section>
<section>
<label htmlFor="source-input">Where did you get these sentences from?</label>
<input id="source-input" type="text" />
</section>

<section>
<button>Submit</button>
</section>
</form>
);
}
}

0 comments on commit 5acfb3a

Please sign in to comment.