2019-02-07 02:05:49 +09:00
|
|
|
<template>
|
2020-02-22 06:43:46 +09:00
|
|
|
<button
|
|
|
|
class="hkzvhatu _button"
|
2020-07-27 23:25:37 +09:00
|
|
|
:class="{ reacted: note.myReaction == reaction, canToggle }"
|
2019-02-07 02:05:49 +09:00
|
|
|
@click="toggleReaction(reaction)"
|
|
|
|
v-if="count > 0"
|
2020-10-17 20:12:00 +09:00
|
|
|
@touchstart.passive="onMouseover"
|
2019-08-31 03:04:36 +09:00
|
|
|
@mouseover="onMouseover"
|
|
|
|
@mouseleave="onMouseleave"
|
2020-06-03 13:30:17 +09:00
|
|
|
@touchend="onMouseleave"
|
2019-08-31 03:04:36 +09:00
|
|
|
ref="reaction"
|
2020-06-21 22:34:28 +09:00
|
|
|
v-particle="canToggle"
|
2019-02-07 02:05:49 +09:00
|
|
|
>
|
2020-10-17 20:12:00 +09:00
|
|
|
<XReactionIcon :reaction="reaction" :custom-emojis="note.emojis"/>
|
2019-02-07 02:05:49 +09:00
|
|
|
<span>{{ count }}</span>
|
2020-02-22 06:43:46 +09:00
|
|
|
</button>
|
2019-02-07 02:05:49 +09:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 20:12:00 +09:00
|
|
|
import { defineComponent, ref } from 'vue';
|
2021-03-23 17:30:14 +09:00
|
|
|
import XDetails from '@client/components/reactions-viewer.details.vue';
|
|
|
|
import XReactionIcon from '@client/components/reaction-icon.vue';
|
|
|
|
import * as os from '@client/os';
|
2019-02-07 02:05:49 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
export default defineComponent({
|
2020-01-30 04:37:25 +09:00
|
|
|
components: {
|
|
|
|
XReactionIcon
|
|
|
|
},
|
2019-02-07 02:05:49 +09:00
|
|
|
props: {
|
|
|
|
reaction: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
count: {
|
|
|
|
type: Number,
|
|
|
|
required: true,
|
|
|
|
},
|
2019-08-29 05:11:26 +09:00
|
|
|
isInitial: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
|
|
|
},
|
2019-02-07 02:05:49 +09:00
|
|
|
note: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
2019-08-31 03:04:36 +09:00
|
|
|
data() {
|
|
|
|
return {
|
2020-10-17 20:12:00 +09:00
|
|
|
close: null,
|
2019-09-02 07:01:33 +09:00
|
|
|
detailsTimeoutId: null,
|
|
|
|
isHovering: false
|
2019-08-31 03:04:36 +09:00
|
|
|
};
|
|
|
|
},
|
2019-02-07 02:05:49 +09:00
|
|
|
computed: {
|
2020-04-16 00:47:17 +09:00
|
|
|
canToggle(): boolean {
|
2020-12-19 10:55:52 +09:00
|
|
|
return !this.reaction.match(/@\w/) && this.$i;
|
2020-04-16 00:47:17 +09:00
|
|
|
},
|
2019-02-07 02:05:49 +09:00
|
|
|
},
|
|
|
|
watch: {
|
2019-08-29 05:20:27 +09:00
|
|
|
count(newCount, oldCount) {
|
|
|
|
if (oldCount < newCount) this.anime();
|
2020-10-17 20:12:00 +09:00
|
|
|
if (this.close != null) this.openDetails();
|
2019-02-07 02:05:49 +09:00
|
|
|
},
|
|
|
|
},
|
2020-06-21 22:34:28 +09:00
|
|
|
mounted() {
|
|
|
|
if (!this.isInitial) this.anime();
|
|
|
|
},
|
2019-02-07 02:05:49 +09:00
|
|
|
methods: {
|
|
|
|
toggleReaction() {
|
|
|
|
if (!this.canToggle) return;
|
|
|
|
|
2020-07-27 23:25:37 +09:00
|
|
|
const oldReaction = this.note.myReaction;
|
2019-02-07 02:05:49 +09:00
|
|
|
if (oldReaction) {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.api('notes/reactions/delete', {
|
2019-02-07 02:05:49 +09:00
|
|
|
noteId: this.note.id
|
|
|
|
}).then(() => {
|
|
|
|
if (oldReaction !== this.reaction) {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.api('notes/reactions/create', {
|
2019-02-07 02:05:49 +09:00
|
|
|
noteId: this.note.id,
|
|
|
|
reaction: this.reaction
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.api('notes/reactions/create', {
|
2019-02-07 02:05:49 +09:00
|
|
|
noteId: this.note.id,
|
|
|
|
reaction: this.reaction
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2019-08-31 03:04:36 +09:00
|
|
|
onMouseover() {
|
2020-06-03 13:30:17 +09:00
|
|
|
if (this.isHovering) return;
|
2019-09-02 07:01:33 +09:00
|
|
|
this.isHovering = true;
|
2019-08-31 03:04:36 +09:00
|
|
|
this.detailsTimeoutId = setTimeout(this.openDetails, 300);
|
|
|
|
},
|
|
|
|
onMouseleave() {
|
2020-06-03 13:30:17 +09:00
|
|
|
if (!this.isHovering) return;
|
2019-09-02 07:01:33 +09:00
|
|
|
this.isHovering = false;
|
2019-08-31 03:04:36 +09:00
|
|
|
clearTimeout(this.detailsTimeoutId);
|
|
|
|
this.closeDetails();
|
|
|
|
},
|
|
|
|
openDetails() {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.api('notes/reactions', {
|
2019-09-03 07:15:53 +09:00
|
|
|
noteId: this.note.id,
|
2019-09-03 07:25:02 +09:00
|
|
|
type: this.reaction,
|
|
|
|
limit: 11
|
2019-08-31 03:04:36 +09:00
|
|
|
}).then((reactions: any[]) => {
|
2019-09-03 07:25:02 +09:00
|
|
|
const users = reactions
|
2019-08-31 03:04:36 +09:00
|
|
|
.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime())
|
2019-09-03 05:50:01 +09:00
|
|
|
.map(x => x.user);
|
2019-08-31 03:04:36 +09:00
|
|
|
|
|
|
|
this.closeDetails();
|
2019-09-02 07:01:33 +09:00
|
|
|
if (!this.isHovering) return;
|
2020-10-17 20:12:00 +09:00
|
|
|
|
|
|
|
const showing = ref(true);
|
|
|
|
os.popup(XDetails, {
|
|
|
|
showing,
|
2019-08-31 03:04:36 +09:00
|
|
|
reaction: this.reaction,
|
2020-10-17 20:12:00 +09:00
|
|
|
emojis: this.note.emojis,
|
2019-08-31 03:04:36 +09:00
|
|
|
users,
|
2019-09-03 07:25:02 +09:00
|
|
|
count: this.count,
|
2019-08-31 03:04:36 +09:00
|
|
|
source: this.$refs.reaction
|
2020-10-17 20:12:00 +09:00
|
|
|
}, {}, 'closed');
|
|
|
|
|
|
|
|
this.close = () => {
|
|
|
|
showing.value = false;
|
|
|
|
};
|
2019-08-31 03:04:36 +09:00
|
|
|
});
|
|
|
|
},
|
|
|
|
closeDetails() {
|
2020-10-17 20:12:00 +09:00
|
|
|
if (this.close != null) {
|
|
|
|
this.close();
|
|
|
|
this.close = null;
|
2019-08-31 03:04:36 +09:00
|
|
|
}
|
|
|
|
},
|
2019-02-07 02:05:49 +09:00
|
|
|
anime() {
|
|
|
|
if (document.hidden) return;
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
// TODO
|
2019-02-07 02:05:49 +09:00
|
|
|
},
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
<style lang="scss" scoped>
|
2020-02-22 06:43:46 +09:00
|
|
|
.hkzvhatu {
|
2020-01-30 04:37:25 +09:00
|
|
|
display: inline-block;
|
|
|
|
height: 32px;
|
|
|
|
margin: 2px;
|
|
|
|
padding: 0 6px;
|
|
|
|
border-radius: 4px;
|
2019-09-03 06:20:04 +09:00
|
|
|
|
2020-04-16 00:47:17 +09:00
|
|
|
&.canToggle {
|
|
|
|
background: rgba(0, 0, 0, 0.05);
|
2019-02-07 02:05:49 +09:00
|
|
|
|
2020-04-16 00:47:17 +09:00
|
|
|
&:hover {
|
|
|
|
background: rgba(0, 0, 0, 0.1);
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
}
|
2019-02-07 02:05:49 +09:00
|
|
|
|
2020-04-16 00:47:17 +09:00
|
|
|
&:not(.canToggle) {
|
|
|
|
cursor: default;
|
|
|
|
}
|
2019-02-07 02:05:49 +09:00
|
|
|
|
2020-04-16 00:47:17 +09:00
|
|
|
&.reacted {
|
|
|
|
background: var(--accent);
|
|
|
|
|
2020-04-17 20:30:12 +09:00
|
|
|
&:hover {
|
|
|
|
background: var(--accent);
|
|
|
|
}
|
|
|
|
|
2020-04-16 00:47:17 +09:00
|
|
|
> span {
|
2021-08-09 18:55:39 +09:00
|
|
|
color: var(--fgOnAccent);
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
}
|
2019-02-07 02:05:49 +09:00
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
> span {
|
|
|
|
font-size: 0.9em;
|
|
|
|
line-height: 32px;
|
|
|
|
}
|
|
|
|
}
|
2019-02-07 02:05:49 +09:00
|
|
|
</style>
|