From 719fac6480f8bd39498f2e92c83cac0fa26fb282 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 13 Oct 2018 00:54:30 +0900 Subject: [PATCH] =?UTF-8?q?=E3=81=8A=E6=B0=97=E3=81=AB=E5=85=A5=E3=82=8A?= =?UTF-8?q?=E3=82=92=E8=A7=A3=E9=99=A4=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locales/ja-JP.yml | 1 + .../app/common/views/components/note-menu.vue | 30 +++++++++++++++---- src/models/favorite.ts | 4 ++- src/models/note.ts | 15 +++++++++- 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index d091b6323..f90f90650 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -363,6 +363,7 @@ common/views/components/note-menu.vue: detail: "詳細" copy-link: "リンクをコピー" favorite: "お気に入り" + unfavorite: "お気に入り解除" pin: "ピン留め" unpin: "ピン留め解除" delete: "削除" diff --git a/src/client/app/common/views/components/note-menu.vue b/src/client/app/common/views/components/note-menu.vue index 6030e4fd3..21713e56a 100644 --- a/src/client/app/common/views/components/note-menu.vue +++ b/src/client/app/common/views/components/note-menu.vue @@ -22,11 +22,21 @@ export default Vue.extend({ icon: '%fa:link%', text: '%i18n:@copy-link%', action: this.copyLink - }, null, { - icon: '%fa:star%', - text: '%i18n:@favorite%', - action: this.favorite - }]; + }, null]; + + if (this.note.isFavorited) { + items.push({ + icon: '%fa:star%', + text: '%i18n:@unfavorite%', + action: this.unfavorite + }); + } else { + items.push({ + icon: '%fa:star%', + text: '%i18n:@favorite%', + action: this.favorite + }); + } if (this.note.userId == this.$store.state.i.id) { if ((this.$store.state.i.pinnedNoteIds || []).includes(this.note.id)) { @@ -45,6 +55,7 @@ export default Vue.extend({ } if (this.note.userId == this.$store.state.i.id || this.$store.state.i.isAdmin) { + items.push(null); items.push({ icon: '%fa:trash-alt R%', text: '%i18n:@delete%', @@ -110,6 +121,15 @@ export default Vue.extend({ }); }, + unfavorite() { + (this as any).api('notes/favorites/delete', { + noteId: this.note.id + }).then(() => { + (this as any).os.new(Ok); + this.destroyDom(); + }); + }, + closed() { this.$nextTick(() => { this.destroyDom(); diff --git a/src/models/favorite.ts b/src/models/favorite.ts index 4824a6dba..9acaec5c5 100644 --- a/src/models/favorite.ts +++ b/src/models/favorite.ts @@ -75,7 +75,9 @@ export const pack = ( delete _favorite._id; // Populate note - _favorite.note = await packNote(_favorite.noteId, me); + _favorite.note = await packNote(_favorite.noteId, me, { + detail: true + }); // (データベースの不具合などで)投稿が見つからなかったら if (_favorite.note == null) { diff --git a/src/models/note.ts b/src/models/note.ts index a47fd098c..e6bdbe0b8 100644 --- a/src/models/note.ts +++ b/src/models/note.ts @@ -358,8 +358,8 @@ export const pack = async ( })(_note.poll); } - // Fetch my reaction if (meId) { + // Fetch my reaction _note.myReaction = (async () => { const reaction = await Reaction .findOne({ @@ -374,6 +374,19 @@ export const pack = async ( return null; })(); + + // isFavorited + _note.isFavorited = (async () => { + const favorite = await Favorite + .count({ + userId: meId, + noteId: id + }, { + limit: 1 + }); + + return favorite === 1; + })(); } }