From d36b129369ccb67dcba27b2cd3544fdf270abef7 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 3 Sep 2019 07:25:02 +0900 Subject: [PATCH] Improve reaction tooltip --- .../views/components/reactions-viewer.details.vue | 6 +++++- .../views/components/reactions-viewer.reaction.vue | 6 ++++-- src/server/api/endpoints/notes/reactions.ts | 12 +++++++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/client/app/common/views/components/reactions-viewer.details.vue b/src/client/app/common/views/components/reactions-viewer.details.vue index efe7eb39b..35c648278 100644 --- a/src/client/app/common/views/components/reactions-viewer.details.vue +++ b/src/client/app/common/views/components/reactions-viewer.details.vue @@ -12,7 +12,7 @@ {{ users.slice(0, 10).join(', ') }} - {{ users.length - 10 }} + {{ count - 10 }} @@ -34,6 +34,10 @@ export default Vue.extend({ type: Array, required: true, }, + count: { + type: Number, + required: true, + }, source: { required: true, } diff --git a/src/client/app/common/views/components/reactions-viewer.reaction.vue b/src/client/app/common/views/components/reactions-viewer.reaction.vue index c06430e5e..dade012c2 100644 --- a/src/client/app/common/views/components/reactions-viewer.reaction.vue +++ b/src/client/app/common/views/components/reactions-viewer.reaction.vue @@ -102,9 +102,10 @@ export default Vue.extend({ if (this.$root.isMobile) return; this.$root.api('notes/reactions', { noteId: this.note.id, - limit: 30 + type: this.reaction, + limit: 11 }).then((reactions: any[]) => { - const users = reactions.filter(x => x.type === this.reaction) + const users = reactions .sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime()) .map(x => x.user); @@ -113,6 +114,7 @@ export default Vue.extend({ this.details = this.$root.new(XDetails, { reaction: this.reaction, users, + count: this.count, source: this.$refs.reaction }); }); diff --git a/src/server/api/endpoints/notes/reactions.ts b/src/server/api/endpoints/notes/reactions.ts index 7bea24d31..742489c0c 100644 --- a/src/server/api/endpoints/notes/reactions.ts +++ b/src/server/api/endpoints/notes/reactions.ts @@ -4,6 +4,8 @@ import define from '../../define'; import { getNote } from '../../common/getters'; import { ApiError } from '../../error'; import { NoteReactions } from '../../../../models'; +import { DeepPartial } from 'typeorm'; +import { NoteReaction } from '../../../../models/entities/note-reaction'; export const meta = { desc: { @@ -24,6 +26,10 @@ export const meta = { } }, + type: { + validator: $.optional.nullable.str, + }, + limit: { validator: $.optional.num.range(1, 100), default: 10 @@ -70,7 +76,11 @@ export default define(meta, async (ps, user) => { const query = { noteId: note.id - }; + } as DeepPartial; + + if (ps.type) { + query.reaction = ps.type; + } const reactions = await NoteReactions.find({ where: query,