Add sum function (#2653)
This commit is contained in:
parent
c6ff6939a5
commit
7959196dc7
6 changed files with 14 additions and 13 deletions
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
|
import { sum } from '../../../../../prelude/array';
|
||||||
export default Vue.extend({
|
export default Vue.extend({
|
||||||
props: ['note'],
|
props: ['note'],
|
||||||
data() {
|
data() {
|
||||||
|
@ -33,7 +34,7 @@ export default Vue.extend({
|
||||||
return this.note.poll;
|
return this.note.poll;
|
||||||
},
|
},
|
||||||
total(): number {
|
total(): number {
|
||||||
return this.poll.choices.reduce((a, b) => a + b.votes, 0);
|
return sum(this.poll.choices.map(x => x.votes));
|
||||||
},
|
},
|
||||||
isVoted(): boolean {
|
isVoted(): boolean {
|
||||||
return this.poll.choices.some(c => c.isVoted);
|
return this.poll.choices.some(c => c.isVoted);
|
||||||
|
|
|
@ -86,6 +86,7 @@ import MkRenoteFormWindow from './renote-form-window.vue';
|
||||||
import MkNoteMenu from '../../../common/views/components/note-menu.vue';
|
import MkNoteMenu from '../../../common/views/components/note-menu.vue';
|
||||||
import MkReactionPicker from '../../../common/views/components/reaction-picker.vue';
|
import MkReactionPicker from '../../../common/views/components/reaction-picker.vue';
|
||||||
import XSub from './notes.note.sub.vue';
|
import XSub from './notes.note.sub.vue';
|
||||||
|
import { sum } from '../../../../../prelude/array';
|
||||||
|
|
||||||
export default Vue.extend({
|
export default Vue.extend({
|
||||||
components: {
|
components: {
|
||||||
|
@ -122,9 +123,7 @@ export default Vue.extend({
|
||||||
},
|
},
|
||||||
reactionsCount(): number {
|
reactionsCount(): number {
|
||||||
return this.p.reactionCounts
|
return this.p.reactionCounts
|
||||||
? Object.keys(this.p.reactionCounts)
|
? sum(Object.values(this.p.reactionCounts))
|
||||||
.map(key => this.p.reactionCounts[key])
|
|
||||||
.reduce((a, b) => a + b)
|
|
||||||
: 0;
|
: 0;
|
||||||
},
|
},
|
||||||
title(): string {
|
title(): string {
|
||||||
|
|
|
@ -78,6 +78,7 @@ import MkRenoteFormWindow from './renote-form-window.vue';
|
||||||
import MkNoteMenu from '../../../common/views/components/note-menu.vue';
|
import MkNoteMenu from '../../../common/views/components/note-menu.vue';
|
||||||
import MkReactionPicker from '../../../common/views/components/reaction-picker.vue';
|
import MkReactionPicker from '../../../common/views/components/reaction-picker.vue';
|
||||||
import XSub from './notes.note.sub.vue';
|
import XSub from './notes.note.sub.vue';
|
||||||
|
import { sum } from '../../../../../prelude/array';
|
||||||
|
|
||||||
function focus(el, fn) {
|
function focus(el, fn) {
|
||||||
const target = fn(el);
|
const target = fn(el);
|
||||||
|
@ -120,9 +121,7 @@ export default Vue.extend({
|
||||||
|
|
||||||
reactionsCount(): number {
|
reactionsCount(): number {
|
||||||
return this.p.reactionCounts
|
return this.p.reactionCounts
|
||||||
? Object.keys(this.p.reactionCounts)
|
? sum(Object.values(this.p.reactionCounts))
|
||||||
.map(key => this.p.reactionCounts[key])
|
|
||||||
.reduce((a, b) => a + b)
|
|
||||||
: 0;
|
: 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -85,6 +85,7 @@ import parse from '../../../../../mfm/parse';
|
||||||
import MkNoteMenu from '../../../common/views/components/note-menu.vue';
|
import MkNoteMenu from '../../../common/views/components/note-menu.vue';
|
||||||
import MkReactionPicker from '../../../common/views/components/reaction-picker.vue';
|
import MkReactionPicker from '../../../common/views/components/reaction-picker.vue';
|
||||||
import XSub from './note.sub.vue';
|
import XSub from './note.sub.vue';
|
||||||
|
import { sum } from '../../../../../prelude/array';
|
||||||
|
|
||||||
export default Vue.extend({
|
export default Vue.extend({
|
||||||
components: {
|
components: {
|
||||||
|
@ -123,9 +124,7 @@ export default Vue.extend({
|
||||||
|
|
||||||
reactionsCount(): number {
|
reactionsCount(): number {
|
||||||
return this.p.reactionCounts
|
return this.p.reactionCounts
|
||||||
? Object.keys(this.p.reactionCounts)
|
? sum(Object.values(this.p.reactionCounts))
|
||||||
.map(key => this.p.reactionCounts[key])
|
|
||||||
.reduce((a, b) => a + b)
|
|
||||||
: 0;
|
: 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,7 @@ import parse from '../../../../../mfm/parse';
|
||||||
import MkNoteMenu from '../../../common/views/components/note-menu.vue';
|
import MkNoteMenu from '../../../common/views/components/note-menu.vue';
|
||||||
import MkReactionPicker from '../../../common/views/components/reaction-picker.vue';
|
import MkReactionPicker from '../../../common/views/components/reaction-picker.vue';
|
||||||
import XSub from './note.sub.vue';
|
import XSub from './note.sub.vue';
|
||||||
|
import { sum } from '../../../../../prelude/array';
|
||||||
|
|
||||||
export default Vue.extend({
|
export default Vue.extend({
|
||||||
components: {
|
components: {
|
||||||
|
@ -100,9 +101,7 @@ export default Vue.extend({
|
||||||
|
|
||||||
reactionsCount(): number {
|
reactionsCount(): number {
|
||||||
return this.p.reactionCounts
|
return this.p.reactionCounts
|
||||||
? Object.keys(this.p.reactionCounts)
|
? sum(Object.values(this.p.reactionCounts))
|
||||||
.map(key => this.p.reactionCounts[key])
|
|
||||||
.reduce((a, b) => a + b)
|
|
||||||
: 0;
|
: 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -21,3 +21,7 @@ export function erase<T>(x: T, xs: T[]): T[] {
|
||||||
export function unique<T>(xs: T[]): T[] {
|
export function unique<T>(xs: T[]): T[] {
|
||||||
return [...new Set(xs)];
|
return [...new Set(xs)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function sum(xs: number[]): number {
|
||||||
|
return xs.reduce((a, b) => a + b, 0);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue