2019-02-06 10:05:49 -07:00
|
|
|
<template>
|
2020-02-21 14:43:46 -07:00
|
|
|
<button
|
|
|
|
class="hkzvhatu _button"
|
2020-07-27 08:25:37 -06:00
|
|
|
:class="{ reacted: note.myReaction == reaction, canToggle }"
|
2021-11-12 07:53:10 -07:00
|
|
|
@click="toggleReaction()"
|
2019-02-06 10:05:49 -07:00
|
|
|
v-if="count > 0"
|
2020-10-17 05:12:00 -06:00
|
|
|
@touchstart.passive="onMouseover"
|
2019-08-30 12:04:36 -06:00
|
|
|
@mouseover="onMouseover"
|
|
|
|
@mouseleave="onMouseleave"
|
2020-06-02 22:30:17 -06:00
|
|
|
@touchend="onMouseleave"
|
2021-11-12 07:53:10 -07:00
|
|
|
ref="buttonRef"
|
2020-06-21 07:34:28 -06:00
|
|
|
v-particle="canToggle"
|
2019-02-06 10:05:49 -07:00
|
|
|
>
|
2020-10-17 05:12:00 -06:00
|
|
|
<XReactionIcon :reaction="reaction" :custom-emojis="note.emojis"/>
|
2019-02-06 10:05:49 -07:00
|
|
|
<span>{{ count }}</span>
|
2020-02-21 14:43:46 -07:00
|
|
|
</button>
|
2019-02-06 10:05:49 -07:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-11-12 07:53:10 -07:00
|
|
|
import { computed, defineComponent, onMounted, ref, watch } from 'vue';
|
2021-11-11 10:02:25 -07:00
|
|
|
import XDetails from '@/components/reactions-viewer.details.vue';
|
|
|
|
import XReactionIcon from '@/components/reaction-icon.vue';
|
|
|
|
import * as os from '@/os';
|
2021-11-12 07:53:10 -07:00
|
|
|
import { useTooltip } from '@/scripts/use-tooltip';
|
|
|
|
import { $i } from '@/account';
|
2019-02-06 10:05:49 -07:00
|
|
|
|
2020-10-17 05:12:00 -06:00
|
|
|
export default defineComponent({
|
2020-01-29 12:37:25 -07:00
|
|
|
components: {
|
|
|
|
XReactionIcon
|
|
|
|
},
|
2021-11-12 07:53:10 -07:00
|
|
|
|
2019-02-06 10:05:49 -07:00
|
|
|
props: {
|
|
|
|
reaction: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
count: {
|
|
|
|
type: Number,
|
|
|
|
required: true,
|
|
|
|
},
|
2019-08-28 14:11:26 -06:00
|
|
|
isInitial: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
|
|
|
},
|
2019-02-06 10:05:49 -07:00
|
|
|
note: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2021-11-12 07:53:10 -07:00
|
|
|
setup(props) {
|
|
|
|
const buttonRef = ref<HTMLElement>();
|
|
|
|
|
|
|
|
const canToggle = computed(() => !props.reaction.match(/@\w/) && $i);
|
|
|
|
|
|
|
|
const toggleReaction = () => {
|
|
|
|
if (!canToggle.value) return;
|
|
|
|
|
|
|
|
const oldReaction = props.note.myReaction;
|
2019-02-06 10:05:49 -07:00
|
|
|
if (oldReaction) {
|
2020-10-17 05:12:00 -06:00
|
|
|
os.api('notes/reactions/delete', {
|
2021-11-12 07:53:10 -07:00
|
|
|
noteId: props.note.id
|
2019-02-06 10:05:49 -07:00
|
|
|
}).then(() => {
|
2021-11-12 07:53:10 -07:00
|
|
|
if (oldReaction !== props.reaction) {
|
2020-10-17 05:12:00 -06:00
|
|
|
os.api('notes/reactions/create', {
|
2021-11-12 07:53:10 -07:00
|
|
|
noteId: props.note.id,
|
|
|
|
reaction: props.reaction
|
2019-02-06 10:05:49 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2020-10-17 05:12:00 -06:00
|
|
|
os.api('notes/reactions/create', {
|
2021-11-12 07:53:10 -07:00
|
|
|
noteId: props.note.id,
|
|
|
|
reaction: props.reaction
|
2019-02-06 10:05:49 -07:00
|
|
|
});
|
|
|
|
}
|
2021-11-12 07:53:10 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
const anime = () => {
|
|
|
|
if (document.hidden) return;
|
|
|
|
|
|
|
|
// TODO: 新しくリアクションが付いたことが視覚的に分かりやすいアニメーション
|
|
|
|
};
|
|
|
|
|
|
|
|
watch(() => props.count, (newCount, oldCount) => {
|
|
|
|
if (oldCount < newCount) anime();
|
|
|
|
});
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
if (!props.isInitial) anime();
|
|
|
|
});
|
|
|
|
|
|
|
|
const { onMouseover, onMouseleave } = useTooltip(async (showing) => {
|
|
|
|
const reactions = await os.api('notes/reactions', {
|
|
|
|
noteId: props.note.id,
|
|
|
|
type: props.reaction,
|
2019-09-02 16:25:02 -06:00
|
|
|
limit: 11
|
2019-08-30 12:04:36 -06:00
|
|
|
});
|
2019-02-06 10:05:49 -07:00
|
|
|
|
2021-11-12 07:53:10 -07:00
|
|
|
const users = reactions
|
|
|
|
.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime())
|
|
|
|
.map(x => x.user);
|
|
|
|
|
|
|
|
os.popup(XDetails, {
|
|
|
|
showing,
|
|
|
|
reaction: props.reaction,
|
|
|
|
emojis: props.note.emojis,
|
|
|
|
users,
|
|
|
|
count: props.count,
|
|
|
|
source: buttonRef.value
|
|
|
|
}, {}, 'closed');
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
buttonRef,
|
|
|
|
canToggle,
|
|
|
|
toggleReaction,
|
|
|
|
onMouseover,
|
|
|
|
onMouseleave,
|
|
|
|
};
|
|
|
|
},
|
2019-02-06 10:05:49 -07:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2020-01-29 12:37:25 -07:00
|
|
|
<style lang="scss" scoped>
|
2020-02-21 14:43:46 -07:00
|
|
|
.hkzvhatu {
|
2020-01-29 12:37:25 -07:00
|
|
|
display: inline-block;
|
|
|
|
height: 32px;
|
|
|
|
margin: 2px;
|
|
|
|
padding: 0 6px;
|
|
|
|
border-radius: 4px;
|
2019-09-02 15:20:04 -06:00
|
|
|
|
2020-04-15 09:47:17 -06:00
|
|
|
&.canToggle {
|
|
|
|
background: rgba(0, 0, 0, 0.05);
|
2019-02-06 10:05:49 -07:00
|
|
|
|
2020-04-15 09:47:17 -06:00
|
|
|
&:hover {
|
|
|
|
background: rgba(0, 0, 0, 0.1);
|
2020-01-29 12:37:25 -07:00
|
|
|
}
|
|
|
|
}
|
2019-02-06 10:05:49 -07:00
|
|
|
|
2020-04-15 09:47:17 -06:00
|
|
|
&:not(.canToggle) {
|
|
|
|
cursor: default;
|
|
|
|
}
|
2019-02-06 10:05:49 -07:00
|
|
|
|
2020-04-15 09:47:17 -06:00
|
|
|
&.reacted {
|
|
|
|
background: var(--accent);
|
|
|
|
|
2020-04-17 05:30:12 -06:00
|
|
|
&:hover {
|
|
|
|
background: var(--accent);
|
|
|
|
}
|
|
|
|
|
2020-04-15 09:47:17 -06:00
|
|
|
> span {
|
2021-08-09 03:55:39 -06:00
|
|
|
color: var(--fgOnAccent);
|
2020-01-29 12:37:25 -07:00
|
|
|
}
|
|
|
|
}
|
2019-02-06 10:05:49 -07:00
|
|
|
|
2020-01-29 12:37:25 -07:00
|
|
|
> span {
|
|
|
|
font-size: 0.9em;
|
|
|
|
line-height: 32px;
|
2021-10-23 22:54:31 -06:00
|
|
|
margin: 0 0 0 4px;
|
2020-01-29 12:37:25 -07:00
|
|
|
}
|
|
|
|
}
|
2019-02-06 10:05:49 -07:00
|
|
|
</style>
|