feat: sort friends alphabetically
This commit is contained in:
parent
0f583f085e
commit
ace66980bf
3 changed files with 17 additions and 3 deletions
|
@ -26,7 +26,9 @@
|
|||
<script lang="ts" setup>
|
||||
const { fetchFriends } = useApi();
|
||||
|
||||
const friends = await fetchFriends()
|
||||
const friends = await fetchFriends().then((response) => {
|
||||
return response.sort((a, b) => getDisplayName(a).localeCompare(getDisplayName(b)))
|
||||
})
|
||||
|
||||
const props = defineProps<{
|
||||
variant: string
|
||||
|
|
|
@ -33,8 +33,13 @@ export const useApi = () => {
|
|||
return await fetchWithApi(`/users/${userId}`);
|
||||
}
|
||||
|
||||
async function fetchFriends(): Promise<UserResponse[] | undefined> {
|
||||
return await fetchWithApi('/me/friends')
|
||||
async function fetchFriends(): Promise<UserResponse[]> {
|
||||
const response = await fetchWithApi('/me/friends')
|
||||
if (Array.isArray(response)) {
|
||||
return response
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
async function addFriend(username: string): Promise<void> {
|
||||
|
|
7
utils/getDisplayName.ts
Normal file
7
utils/getDisplayName.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import type { GuildMemberResponse, UserResponse } from "~/types/interfaces";
|
||||
|
||||
export function getDisplayName(user: UserResponse, member: GuildMemberResponse | undefined = undefined): string {
|
||||
if (member?.nickname) return member.nickname
|
||||
if (user.display_name) return user.display_name
|
||||
return user.username
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue