[bug] fix mainPronouns selection for home/@profile

This commit is contained in:
Andrea Vos 2022-09-29 21:51:29 +02:00
parent 65633a431e
commit 3289f8f11e

View File

@ -177,6 +177,7 @@
<script> <script>
import { head } from "../src/helpers"; import { head } from "../src/helpers";
import ClientOnly from 'vue-client-only' import ClientOnly from 'vue-client-only'
import opinions from '../src/opinions';
export default { export default {
components: { ClientOnly }, components: { ClientOnly },
@ -260,25 +261,20 @@
} }
}, },
selectMainPronouns(pronouns) { selectMainPronouns(pronouns) {
const best = { const best = {}
1: [], // yes for (let {value: pronoun, opinion} of pronouns) {
0: [], // meh const opinionValue = opinions[opinion]?.value || 0;
3: [], // close if (best[opinionValue] === undefined) {
2: [], // jokingly best[opinionValue] = [];
}
for (let pronoun in pronouns) {
if (!pronouns.hasOwnProperty(pronoun)) { continue; }
const opinion = pronouns[pronoun];
if (best[opinion] !== undefined) {
best[opinion].push(pronoun);
} }
best[opinionValue].push(pronoun);
} }
for (let opinion of [1, 0, 3, 2]) {
if (best[opinion].length) { if (!Object.keys(best).length) { return []; }
return best[opinion].slice(0, 3);
} const bestKey = Math.max(...Object.keys(best));
}
return []; return best[bestKey].slice(0, 3);
}, },
}, },
head() { head() {