diff options
-rw-r--r-- | src/js/helpers/arrayHelper.js | 28 | ||||
-rw-r--r-- | src/js/store/modules/poll.js | 10 |
2 files changed, 35 insertions, 3 deletions
diff --git a/src/js/helpers/arrayHelper.js b/src/js/helpers/arrayHelper.js new file mode 100644 index 00000000..938ce40e --- /dev/null +++ b/src/js/helpers/arrayHelper.js @@ -0,0 +1,28 @@ +/* + * @copyright Copyright (c) 2019 Rene Gieling <github@dartcafe.de> + * + * @author Rene Gieling <github@dartcafe.de> + * @author Julius Härtl <jus@bitgrid.net> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +const uniqueArrayOfObjects = function(array) { + return [...new Set(array.map((obj) => JSON.stringify(obj)))].map((string) => JSON.parse(string)) +} + +export { uniqueArrayOfObjects } diff --git a/src/js/store/modules/poll.js b/src/js/store/modules/poll.js index b7d620a2..69ceaccf 100644 --- a/src/js/store/modules/poll.js +++ b/src/js/store/modules/poll.js @@ -25,6 +25,7 @@ import axios from '@nextcloud/axios' import moment from '@nextcloud/moment' import { generateUrl } from '@nextcloud/router' import acl from './subModules/acl.js' +import { uniqueArrayOfObjects } from '../../helpers/arrayHelper.js' const defaultPoll = () => { return { @@ -105,15 +106,18 @@ const getters = { voted: false, }) } - return participants + + return uniqueArrayOfObjects(participants) + }, participantsVoted: (state, getters, rootState) => { - return rootState.votes.list.map(item => ({ + return uniqueArrayOfObjects(rootState.votes.list.map(item => ({ userId: item.userId, displayName: item.displayName, isNoUser: item.isNoUser, - })) + }))) + }, } |