feat: always show account server (#119)

This commit is contained in:
三咲智子 Kevin Deng 2022-11-26 16:33:32 +08:00 committed by GitHub
parent de468fb28b
commit 1194d56d09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 10 deletions

View file

@ -0,0 +1,16 @@
<script setup lang="ts">
import type { Account } from 'masto'
const { account } = defineProps<{
account: Account
}>()
const serverName = $computed(() => getServerName(account))
</script>
<template>
<p>
<span>{{ getShortHandle(account) }}</span>
<span v-if="serverName" text="gray/95">@{{ serverName }}</span>
</p>
</template>

View file

@ -66,9 +66,7 @@ function previewAvatar() {
</button> </button>
<div flex flex-col> <div flex flex-col>
<ContentRich font-bold text-2xl break-words :content="getDisplayName(account)" :emojis="account.emojis" /> <ContentRich font-bold text-2xl break-words :content="getDisplayName(account)" :emojis="account.emojis" />
<p op50> <AccountHandle :account="account" op50 />
{{ getShortHandle(account) }}
</p>
</div> </div>
</div> </div>
<div flex gap-2 items-center> <div flex gap-2 items-center>
@ -94,13 +92,13 @@ function previewAvatar() {
</div> </div>
</div> </div>
<div flex gap-5> <div flex gap-5>
<NuxtLink :to="`/${getFullHandle(account)}/`" exact-active-class="text-primary"> <NuxtLink :to="getAccountPath(account)" exact-active-class="text-primary">
<span font-bold>{{ formattedNumber(account.statusesCount) }}</span> <span op50>Posts</span> <span font-bold>{{ formattedNumber(account.statusesCount) }}</span> <span op50>Posts</span>
</NuxtLink> </NuxtLink>
<NuxtLink :to="`/${getFullHandle(account)}/following`" exact-active-class="text-primary"> <NuxtLink :to="`${getAccountPath(account)}/following`" exact-active-class="text-primary">
<span font-bold>{{ humanReadableNumber(account.followingCount) }}</span> <span op50>Following</span> <span font-bold>{{ humanReadableNumber(account.followingCount) }}</span> <span op50>Following</span>
</NuxtLink> </NuxtLink>
<NuxtLink :to="`/${getFullHandle(account)}/followers`" exact-active-class="text-primary"> <NuxtLink :to="`${getAccountPath(account)}/followers`" exact-active-class="text-primary">
<span font-bold>{{ humanReadableNumber(account.followersCount) }}</span> <span op50>Followers</span> <span font-bold>{{ humanReadableNumber(account.followersCount) }}</span> <span op50>Followers</span>
</NuxtLink> </NuxtLink>
</div> </div>

View file

@ -20,9 +20,7 @@ const accountHandle = $(useAccountHandle(account, fullServer))
</div> </div>
<NuxtLink flex flex-col :to="link ? getAccountPath(account) : null"> <NuxtLink flex flex-col :to="link ? getAccountPath(account) : null">
<ContentRich font-bold hover:underline :content="getDisplayName(account)" :emojis="account.emojis" /> <ContentRich font-bold hover:underline :content="getDisplayName(account)" :emojis="account.emojis" />
<p op35 text-sm> <AccountHandle :account="account" text-sm op35 />
{{ accountHandle }}
</p>
<slot name="bottom" /> <slot name="bottom" />
</NuxtLink> </NuxtLink>
<slot /> <slot />

View file

@ -35,6 +35,10 @@ export const STATUS_VISIBILITIES = [
}, },
] as const ] as const
export function getServerName(account: Account) {
return account.url.match(UserLinkRE)?.[1] || currentUser.value?.server || ''
}
export function getDisplayName(account: Account) { export function getDisplayName(account: Account) {
return account.displayName || account.username return account.displayName || account.username
} }
@ -47,7 +51,7 @@ export function getFullHandle(account: Account) {
const handle = `@${account.acct}` const handle = `@${account.acct}`
if (!currentUser.value || account.acct.includes('@')) if (!currentUser.value || account.acct.includes('@'))
return handle return handle
return `${handle}@${account.url.match(UserLinkRE)?.[1] || currentUser.value.server}` return `${handle}@${getServerName(account)}`
} }
export function toShortHandle(fullHandle: string) { export function toShortHandle(fullHandle: string) {