refactor(client): use setup syntax

This commit is contained in:
syuilo 2022-09-05 18:24:46 +09:00
parent e41810f142
commit f337459c6e

View file

@ -1,7 +1,7 @@
<template> <template>
<transition :name="$store.state.animation ? 'popup' : ''" appear @after-leave="$emit('closed')"> <transition :name="$store.state.animation ? 'popup' : ''" appear @after-leave="emit('closed')">
<div v-if="showing" class="fxxzrfni _popup _shadow" :style="{ zIndex, top: top + 'px', left: left + 'px' }" @mouseover="() => { $emit('mouseover'); }" @mouseleave="() => { $emit('mouseleave'); }"> <div v-if="showing" class="fxxzrfni _popup _shadow" :style="{ zIndex, top: top + 'px', left: left + 'px' }" @mouseover="() => { emit('mouseover'); }" @mouseleave="() => { emit('mouseleave'); }">
<div v-if="fetched" class="info"> <div v-if="user != null" class="info">
<div class="banner" :style="user.bannerUrl ? `background-image: url(${user.bannerUrl})` : ''"> <div class="banner" :style="user.bannerUrl ? `background-image: url(${user.bannerUrl})` : ''">
<span v-if="$i && $i.id != user.id && user.isFollowed" class="followed">{{ $ts.followsYou }}</span> <span v-if="$i && $i.id != user.id && user.isFollowed" class="followed">{{ $ts.followsYou }}</span>
</div> </div>
@ -33,71 +33,51 @@
</transition> </transition>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineComponent } from 'vue'; import { onMounted } from 'vue';
import * as Acct from 'misskey-js/built/acct'; import * as Acct from 'misskey-js/built/acct';
import * as misskey from 'misskey-js';
import MkFollowButton from '@/components/MkFollowButton.vue'; import MkFollowButton from '@/components/MkFollowButton.vue';
import { userPage } from '@/filters/user'; import { userPage } from '@/filters/user';
import * as os from '@/os'; import * as os from '@/os';
export default defineComponent({ const props = defineProps<{
components: { showing: boolean;
MkFollowButton, q: string;
}, source: HTMLElement;
}>();
props: { const emit = defineEmits<{
showing: { (ev: 'closed'): void;
type: Boolean, (ev: 'mouseover'): void;
required: true, (ev: 'mouseleave'): void;
}, }>();
q: {
type: String,
required: true,
},
source: {
required: true,
},
},
emits: ['closed', 'mouseover', 'mouseleave'], const zIndex = os.claimZIndex('middle');
let user = $ref<misskey.entities.UserDetailed | null>(null);
let top = $ref(0);
let left = $ref(0);
data() { onMounted(() => {
return { if (typeof props.q === 'object') {
user: null, user = props.q;
fetched: false,
top: 0,
left: 0,
zIndex: os.claimZIndex('middle'),
};
},
mounted() {
if (typeof this.q === 'object') {
this.user = this.q;
this.fetched = true;
} else { } else {
const query = this.q.startsWith('@') ? const query = props.q.startsWith('@') ?
Acct.parse(this.q.substr(1)) : Acct.parse(props.q.substr(1)) :
{ userId: this.q }; { userId: props.q };
os.api('users/show', query).then(user => { os.api('users/show', query).then(res => {
if (!this.showing) return; if (!props.showing) return;
this.user = user; user = res;
this.fetched = true;
}); });
} }
const rect = this.source.getBoundingClientRect(); const rect = props.source.getBoundingClientRect();
const x = ((rect.left + (this.source.offsetWidth / 2)) - (300 / 2)) + window.pageXOffset; const x = ((rect.left + (props.source.offsetWidth / 2)) - (300 / 2)) + window.pageXOffset;
const y = rect.top + this.source.offsetHeight + window.pageYOffset; const y = rect.top + props.source.offsetHeight + window.pageYOffset;
this.top = y; top = y;
this.left = x; left = x;
},
methods: {
userPage,
},
}); });
</script> </script>