refactor: move getDisplayAvatar into profile composable
This commit is contained in:
parent
8dbab14c2e
commit
10bf54b6fd
3 changed files with 33 additions and 26 deletions
|
@ -6,7 +6,7 @@
|
||||||
<DefaultIcon v-else
|
<DefaultIcon v-else
|
||||||
class="display-avatar"
|
class="display-avatar"
|
||||||
:name="displayName"
|
:name="displayName"
|
||||||
:seed="user.uuid"
|
:seed="getUserUuid(props.profile)"
|
||||||
:alt="displayName" />
|
:alt="displayName" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -14,25 +14,14 @@
|
||||||
import { NuxtImg } from '#components';
|
import { NuxtImg } from '#components';
|
||||||
import type { GuildMemberResponse, UserResponse } from '~/types/interfaces';
|
import type { GuildMemberResponse, UserResponse } from '~/types/interfaces';
|
||||||
|
|
||||||
const { getDisplayName } = useProfile()
|
const { getDisplayName, getAvatarUrl, getUserUuid } = useProfile()
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
profile: UserResponse | GuildMemberResponse,
|
profile: UserResponse | GuildMemberResponse,
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const displayName = getDisplayName(props.profile)
|
const displayName = getDisplayName(props.profile)
|
||||||
let user: UserResponse
|
const displayAvatar = getAvatarUrl(props.profile)
|
||||||
let displayAvatar: string | null
|
|
||||||
|
|
||||||
if ("username" in props.profile) {
|
|
||||||
// assume it's a UserResponse
|
|
||||||
displayAvatar = props.profile.avatar
|
|
||||||
user = props.profile
|
|
||||||
} else {
|
|
||||||
// assume it's a GuildMemberResponse
|
|
||||||
displayAvatar = props.profile.user.avatar
|
|
||||||
user = props.profile.user
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ import type { GuildMemberResponse, ModalProps, UserResponse } from '~/types/inte
|
||||||
import VerticalSpacer from '../UserInterface/VerticalSpacer.vue';
|
import VerticalSpacer from '../UserInterface/VerticalSpacer.vue';
|
||||||
import Button from '../UserInterface/Button.vue';
|
import Button from '../UserInterface/Button.vue';
|
||||||
|
|
||||||
const { getDisplayName, getUsername, getPronouns, getAboutMe, getRegistrationDate, getGuildJoinDate, getFriendsSince, getUuid } = useProfile()
|
const { getDisplayName, getUsername, getPronouns, getAboutMe, getRegistrationDate, getGuildJoinDate, getFriendsSince, getUserUuid } = useProfile()
|
||||||
const { addFriend, fetchMe } = useApi();
|
const { addFriend, fetchMe } = useApi();
|
||||||
|
|
||||||
const props = defineProps<ModalProps & {
|
const props = defineProps<ModalProps & {
|
||||||
|
@ -81,7 +81,7 @@ const registrationDate = getRegistrationDate(props.profile)
|
||||||
const joinDate = getGuildJoinDate(props.profile)
|
const joinDate = getGuildJoinDate(props.profile)
|
||||||
const friendsSince = await getFriendsSince(props.profile)
|
const friendsSince = await getFriendsSince(props.profile)
|
||||||
|
|
||||||
const uuid = getUuid(props.profile)
|
const uuid = getUserUuid(props.profile)
|
||||||
|
|
||||||
|
|
||||||
function toDateString(date: Date): string {
|
function toDateString(date: Date): string {
|
||||||
|
|
|
@ -24,6 +24,14 @@ export const useProfile = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAvatarUrl(profile: UserResponse | GuildMemberResponse): string | null {
|
||||||
|
if ("username" in profile) {
|
||||||
|
return profile.avatar
|
||||||
|
} else {
|
||||||
|
return profile.user.avatar
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function getFriendsSince(profile: UserResponse | GuildMemberResponse): Promise<Date | null> {
|
async function getFriendsSince(profile: UserResponse | GuildMemberResponse): Promise<Date | null> {
|
||||||
let user_uuid: string;
|
let user_uuid: string;
|
||||||
|
|
||||||
|
@ -42,9 +50,9 @@ export const useProfile = () => {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGuildJoinDate (profile: UserResponse | GuildMemberResponse): Date | null {
|
function getGuildJoinDate(profile: UserResponse | GuildMemberResponse): Date | undefined {
|
||||||
if ("username" in profile) {
|
if ("username" in profile) {
|
||||||
return null
|
return undefined
|
||||||
} else {
|
} else {
|
||||||
return uuidToDate(profile.uuid)
|
return uuidToDate(profile.uuid)
|
||||||
}
|
}
|
||||||
|
@ -58,7 +66,7 @@ export const useProfile = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRegistrationDate (profile: UserResponse | GuildMemberResponse): Date | null {
|
function getRegistrationDate(profile: UserResponse | GuildMemberResponse): Date {
|
||||||
if ("username" in profile) {
|
if ("username" in profile) {
|
||||||
return uuidToDate(profile.uuid)
|
return uuidToDate(profile.uuid)
|
||||||
} else {
|
} else {
|
||||||
|
@ -74,7 +82,7 @@ export const useProfile = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUuid (profile: UserResponse | GuildMemberResponse): string | null {
|
function getUserUuid(profile: UserResponse | GuildMemberResponse): string {
|
||||||
if ("username" in profile) {
|
if ("username" in profile) {
|
||||||
return profile.uuid
|
return profile.uuid
|
||||||
} else {
|
} else {
|
||||||
|
@ -82,14 +90,24 @@ export const useProfile = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getUser(profile: UserResponse | GuildMemberResponse): UserResponse {
|
||||||
|
if ("username" in profile) {
|
||||||
|
return profile
|
||||||
|
} else {
|
||||||
|
return profile.user
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getAboutMe,
|
getAboutMe,
|
||||||
getDisplayName,
|
getDisplayName,
|
||||||
|
getAvatarUrl,
|
||||||
getFriendsSince,
|
getFriendsSince,
|
||||||
getGuildJoinDate,
|
getGuildJoinDate,
|
||||||
getRegistrationDate,
|
getRegistrationDate,
|
||||||
getPronouns,
|
getPronouns,
|
||||||
getUsername,
|
getUsername,
|
||||||
getUuid
|
getUserUuid,
|
||||||
|
getUser
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue