refactor(client): use composition api

This commit is contained in:
syuilo 2022-06-24 10:34:36 +09:00
parent 12374bd6a3
commit 4a5d5fe20c
1 changed files with 18 additions and 36 deletions

View File

@ -1,12 +1,12 @@
<template> <template>
<MkA v-if="url.startsWith('/')" v-user-preview="canonical" :class="[$style.root, { isMe }]" :to="url" :style="{ background: bg }"> <MkA v-if="url.startsWith('/')" v-user-preview="canonical" :class="[$style.root, { isMe }]" :to="url" :style="{ background: bgCss }">
<img :class="$style.icon" :src="`/avatar/@${username}@${host}`" alt=""> <img :class="$style.icon" :src="`/avatar/@${username}@${host}`" alt="">
<span class="main"> <span class="main">
<span class="username">@{{ username }}</span> <span class="username">@{{ username }}</span>
<span v-if="(host != localHost) || $store.state.showFullAcct" :class="$style.mainHost">@{{ toUnicode(host) }}</span> <span v-if="(host != localHost) || $store.state.showFullAcct" :class="$style.mainHost">@{{ toUnicode(host) }}</span>
</span> </span>
</MkA> </MkA>
<a v-else :class="$style.root" :href="url" target="_blank" rel="noopener" :style="{ background: bg }"> <a v-else :class="$style.root" :href="url" target="_blank" rel="noopener" :style="{ background: bgCss }">
<span class="main"> <span class="main">
<span class="username">@{{ username }}</span> <span class="username">@{{ username }}</span>
<span :class="$style.mainHost">@{{ toUnicode(host) }}</span> <span :class="$style.mainHost">@{{ toUnicode(host) }}</span>
@ -14,49 +14,31 @@
</a> </a>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineComponent, useCssModule } from 'vue';
import tinycolor from 'tinycolor2';
import { toUnicode } from 'punycode'; import { toUnicode } from 'punycode';
import { useCssModule } from 'vue';
import tinycolor from 'tinycolor2';
import { host as localHost } from '@/config'; import { host as localHost } from '@/config';
import { $i } from '@/account'; import { $i } from '@/account';
export default defineComponent({ const props = defineProps<{
props: { username: string;
username: { host: string;
type: String, }>();
required: true
},
host: {
type: String,
required: true
}
},
setup(props) { const canonical = props.host === localHost ? `@${props.username}` : `@${props.username}@${toUnicode(props.host)}`;
const canonical = props.host === localHost ? `@${props.username}` : `@${props.username}@${toUnicode(props.host)}`;
const url = `/${canonical}`; const url = `/${canonical}`;
const isMe = $i && ( const isMe = $i && (
`@${props.username}@${toUnicode(props.host)}` === `@${$i.username}@${toUnicode(localHost)}`.toLowerCase() `@${props.username}@${toUnicode(props.host)}` === `@${$i.username}@${toUnicode(localHost)}`.toLowerCase()
); );
const bg = tinycolor(getComputedStyle(document.documentElement).getPropertyValue(isMe ? '--mentionMe' : '--mention')); const bg = tinycolor(getComputedStyle(document.documentElement).getPropertyValue(isMe ? '--mentionMe' : '--mention'));
bg.setAlpha(0.1); bg.setAlpha(0.1);
const bgCss = bg.toRgbString();
useCssModule(); useCssModule();
return {
localHost,
isMe,
url,
canonical,
toUnicode,
bg: bg.toRgbString(),
};
},
});
</script> </script>
<style lang="scss" module> <style lang="scss" module>