hippofish/packages/client/src/components/MkRenoteButton.vue

118 lines
2.6 KiB
Vue
Raw Normal View History

<template>
2022-07-24 08:45:16 +02:00
<button
v-if="canRenote"
2021-11-19 11:36:12 +01:00
ref="buttonRef"
class="eddddedb _button canRenote"
2022-11-25 12:46:10 +01:00
v-tooltip.noDelay.bottom="i18n.ts.renote"
2022-10-26 03:45:24 +02:00
@click="renote(false, $event)"
>
2022-11-07 03:49:47 +01:00
<i class="ph-repeat-bold ph-lg"></i>
2021-11-19 11:36:12 +01:00
<p v-if="count > 0" class="count">{{ count }}</p>
</button>
2021-11-12 15:54:02 +01:00
<button v-else class="eddddedb _button">
2022-11-07 03:49:47 +01:00
<i class="ph-prohibit-bold ph-lg"></i>
</button>
</template>
2022-07-24 08:45:16 +02:00
<script lang="ts" setup>
import { computed, ref } from 'vue';
import * as misskey from 'misskey-js';
2022-10-25 20:23:59 +02:00
import Ripple from '@/components/MkRipple.vue';
import XDetails from '@/components/MkUsersTooltip.vue';
import { pleaseLogin } from '@/scripts/please-login';
import * as os from '@/os';
import { $i } from '@/account';
import { useTooltip } from '@/scripts/use-tooltip';
import { i18n } from '@/i18n';
2022-09-28 18:22:03 +02:00
import { defaultStore } from "@/store";
2022-07-24 08:45:16 +02:00
const props = defineProps<{
note: misskey.entities.Note;
count: number;
}>();
2022-07-24 08:45:16 +02:00
const buttonRef = ref<HTMLElement>();
2022-07-24 08:45:16 +02:00
const canRenote = computed(() => ['public', 'home'].includes(props.note.visibility) || props.note.userId === $i.id);
2022-07-24 08:45:16 +02:00
useTooltip(buttonRef, async (showing) => {
const renotes = await os.api('notes/renotes', {
noteId: props.note.id,
limit: 11,
});
2022-07-24 08:45:16 +02:00
const users = renotes.map(x => x.user);
2022-07-24 08:45:16 +02:00
if (users.length < 1) return;
2022-07-24 08:45:16 +02:00
os.popup(XDetails, {
showing,
users,
count: props.count,
targetElement: buttonRef.value,
}, {}, 'closed');
});
2022-10-26 03:45:24 +02:00
const renote = (viaKeyboard = false, ev?: MouseEvent) => {
2022-07-24 08:45:16 +02:00
pleaseLogin();
2022-09-28 18:22:03 +02:00
if (defaultStore.state.seperateRenoteQuote) {
os.api('notes/create', {
renoteId: props.note.id,
visibility: props.note.visibility,
});
2022-10-25 20:23:59 +02:00
const el = ev && (ev.currentTarget ?? ev.target) as HTMLElement | null | undefined;
if (el) {
const rect = el.getBoundingClientRect();
const x = rect.left + (el.offsetWidth / 2);
const y = rect.top + (el.offsetHeight / 2);
os.popup(Ripple, { x, y }, {}, 'end');
}
2022-09-28 18:22:03 +02:00
} else {
os.popupMenu([{
text: i18n.ts.renote,
2022-11-07 03:49:47 +01:00
icon: 'ph-repeat-bold ph-lg',
2022-09-28 18:22:03 +02:00
action: () => {
os.api('notes/create', {
renoteId: props.note.id,
visibility: props.note.visibility,
});
},
}, {
text: i18n.ts.quote,
2022-11-07 03:49:47 +01:00
icon: 'ph-quotes-bold ph-lg',
2022-09-28 18:22:03 +02:00
action: () => {
os.post({
renote: props.note,
});
},
}], buttonRef.value, {
viaKeyboard,
});
}
2022-07-24 08:45:16 +02:00
};
</script>
<style lang="scss" scoped>
.eddddedb {
display: inline-block;
height: 32px;
margin: 2px;
padding: 0 6px;
border-radius: 4px;
&:not(.canRenote) {
cursor: default;
}
&.renoted {
background: var(--accent);
}
> .count {
display: inline;
margin-left: 8px;
opacity: 0.7;
}
}
</style>