refactor(client): use setup syntax

This commit is contained in:
syuilo 2022-09-05 18:24:46 +09:00
parent e41810f142
commit f337459c6e
1 changed files with 37 additions and 57 deletions

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, } else {
top: 0, const query = props.q.startsWith('@') ?
left: 0, Acct.parse(props.q.substr(1)) :
zIndex: os.claimZIndex('middle'), { userId: props.q };
};
},
mounted() { os.api('users/show', query).then(res => {
if (typeof this.q === 'object') { if (!props.showing) return;
this.user = this.q; user = res;
this.fetched = true; });
} else { }
const query = this.q.startsWith('@') ?
Acct.parse(this.q.substr(1)) :
{ userId: this.q };
os.api('users/show', query).then(user => { const rect = props.source.getBoundingClientRect();
if (!this.showing) return; const x = ((rect.left + (props.source.offsetWidth / 2)) - (300 / 2)) + window.pageXOffset;
this.user = user; const y = rect.top + props.source.offsetHeight + window.pageYOffset;
this.fetched = true;
});
}
const rect = this.source.getBoundingClientRect(); top = y;
const x = ((rect.left + (this.source.offsetWidth / 2)) - (300 / 2)) + window.pageXOffset; left = x;
const y = rect.top + this.source.offsetHeight + window.pageYOffset;
this.top = y;
this.left = x;
},
methods: {
userPage,
},
}); });
</script> </script>