move live-result sort to service
This commit is contained in:
parent
deac142296
commit
9e483a181e
@ -5,6 +5,7 @@ import { defineMessages, injectIntl } from 'react-intl';
|
||||
import { Session } from 'meteor/session';
|
||||
import Button from '/imports/ui/components/button/component';
|
||||
import { styles } from './styles';
|
||||
import Service from './service';
|
||||
|
||||
const intlMessages = defineMessages({
|
||||
usersTitle: {
|
||||
@ -44,30 +45,6 @@ class LiveResult extends Component {
|
||||
? [...users, ...responses.map(u => u.userId)]
|
||||
: [...users];
|
||||
|
||||
const sortByResponse = (a, b) => {
|
||||
if (a.answer.toLowerCase() > b.answer.toLowerCase()) {
|
||||
return -1;
|
||||
} else if (a.answer.toLowerCase() < b.answer.toLowerCase()) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
const sortByName = (a, b) => {
|
||||
if (a.name.toLowerCase() < b.name.toLowerCase()) {
|
||||
return -1;
|
||||
} else if (a.name.toLowerCase() > b.name.toLowerCase()) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
const sortUsers = (a, b) => {
|
||||
let sort = sortByResponse(a, b);
|
||||
if (sort === 0) sort = sortByName(a, b);
|
||||
return sort;
|
||||
};
|
||||
|
||||
userAnswers = userAnswers.map(id => getUser(id))
|
||||
.filter(user => user.connectionStatus === 'online')
|
||||
.map((user) => {
|
||||
@ -83,7 +60,7 @@ class LiveResult extends Component {
|
||||
answer,
|
||||
};
|
||||
})
|
||||
.sort(sortUsers)
|
||||
.sort(Service.sortUsers)
|
||||
.reduce((acc, user) => [
|
||||
...acc,
|
||||
<div className={styles.item} key={_.uniqueId('stats-')}>{user.name}</div>,
|
||||
|
@ -0,0 +1,27 @@
|
||||
const sortUsers = (a, b) => {
|
||||
const sortByResponse = (a, b) => {
|
||||
if (a.answer.toLowerCase() > b.answer.toLowerCase()) {
|
||||
return -1;
|
||||
} else if (a.answer.toLowerCase() < b.answer.toLowerCase()) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
const sortByName = (a, b) => {
|
||||
if (a.name.toLowerCase() < b.name.toLowerCase()) {
|
||||
return -1;
|
||||
} else if (a.name.toLowerCase() > b.name.toLowerCase()) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
let sort = sortByResponse(a, b);
|
||||
if (sort === 0) sort = sortByName(a, b);
|
||||
return sort;
|
||||
};
|
||||
|
||||
export default {
|
||||
sortUsers,
|
||||
};
|
Loading…
Reference in New Issue
Block a user