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

Commit

Permalink
Merge pull request #158 from MichaelKohler/feature/review_fixes
Browse files Browse the repository at this point in the history
Feature/review fixes
  • Loading branch information
MichaelKohler committed Jan 31, 2019
2 parents 1a5dd0f + 8633636 commit e87fb3f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
20 changes: 13 additions & 7 deletions shared/db/collections/sentences-meta.js
Expand Up @@ -144,7 +144,18 @@ export default class SentencesMeta {
filters['has_approved'] = false;
const collection = await this.getCollection(language);
const result = await collection.listRecords({ filters, sort: 'createdAt' });
return result.data;
const sentences = result.data;
// This works as all modern browsers use a stable sorting algorithm
// if not, we're still fine..
// We always want to show sentences with more valid votes first
const additionallySortedByApprovalVotes = sentences.sort((a, b) => {
const aVoteLength = a.valid.length;
const bVoteLength = b.valid.length;

return bVoteLength - aVoteLength;
});

return additionallySortedByApprovalVotes;
}

async getValidatedSentences(language) {
Expand Down Expand Up @@ -243,13 +254,8 @@ export default class SentencesMeta {
}

async vote(language, validated, invalidated) {
const list = [...validated, ...invalidated].map(sentence => sentence.id);
const collection = await this.getCollection(language);
const result = await collection.listRecords({
filters: {
in_id: list
},
});
const result = await collection.listRecords();

const records = result.data;
const existing = records.reduce((accum, record) => {
Expand Down
16 changes: 15 additions & 1 deletion web/src/components/review-form.jsx
Expand Up @@ -40,6 +40,10 @@ export default class ReviewForm extends React.Component {
let validated = [];
let invalidated = [];

this.setState({
pendingSentences: true,
});

// Extract sentence that have been voted on.
const unreviewed = this.state.sentences.filter((sentenceInfo) => {
if (sentenceInfo.reviewApproval) {
Expand All @@ -60,6 +64,10 @@ export default class ReviewForm extends React.Component {
invalidated,
unreviewed,
});

this.setState({
pendingSentences: false,
});
}

setPage(page) {
Expand Down Expand Up @@ -120,7 +128,13 @@ export default class ReviewForm extends React.Component {
</section>
)) }

<button type="submit">Finish Review</button>
{ this.state.pendingSentences && (
<p>
<strong>Reviews are being uploaded. This can take several minutes depending on the number of sentences added.
Please don't close this website.</strong>
</p>
)}
<button type="submit" disabled={this.state.pendingSentences}>Finish Review</button>
</form>
);
}
Expand Down

0 comments on commit e87fb3f

Please sign in to comment.