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