refactor: renote-button to composition api

This commit is contained in:
Norm 2022-08-19 22:56:25 -04:00 committed by Gitea
parent 7621e5461f
commit 1521bc881c

View file

@ -13,8 +13,9 @@
</button> </button>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { computed, defineComponent, ref } from 'vue'; import { computed, ref } from 'vue';
import { Note } from 'misskey-js/built/entities';
import XDetails from '@/components/users-tooltip.vue'; import XDetails from '@/components/users-tooltip.vue';
import { pleaseLogin } from '@/scripts/please-login'; import { pleaseLogin } from '@/scripts/please-login';
import * as os from '@/os'; import * as os from '@/os';
@ -22,22 +23,14 @@ import { $i } from '@/account';
import { useTooltip } from '@/scripts/use-tooltip'; import { useTooltip } from '@/scripts/use-tooltip';
import { i18n } from '@/i18n'; import { i18n } from '@/i18n';
export default defineComponent({ const props = defineProps<{
props: { count: number;
count: { note: Note;
type: Number, }>();
required: true,
},
note: {
type: Object,
required: true,
},
},
setup(props) {
const buttonRef = ref<HTMLElement>(); const buttonRef = ref<HTMLElement>();
const canRenote = computed(() => ['public', 'home'].includes(props.note.visibility) || props.note.userId === $i.id); const canRenote = computed(() => ['public', 'home'].includes(props.note.visibility) || props.note.userId === $i?.id);
useTooltip(buttonRef, async (showing) => { useTooltip(buttonRef, async (showing) => {
const renotes = await os.api('notes/renotes', { const renotes = await os.api('notes/renotes', {
@ -57,7 +50,7 @@ export default defineComponent({
}, {}, 'closed'); }, {}, 'closed');
}); });
const renote = (viaKeyboard = false) => { function renote(viaKeyboard = false): void {
pleaseLogin(); pleaseLogin();
os.popupMenu([{ os.popupMenu([{
text: i18n.ts.renote, text: i18n.ts.renote,
@ -79,15 +72,7 @@ export default defineComponent({
}], buttonRef.value, { }], buttonRef.value, {
viaKeyboard, viaKeyboard,
}); });
}; }
return {
buttonRef,
canRenote,
renote,
};
},
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>