style: seperate out sortUsers and sortMembers
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
ci/woodpecker/pr/build-and-publish Pipeline was successful

This commit is contained in:
Twig 2025-07-16 10:59:00 +02:00
parent 4229682d69
commit f6ede67c26
No known key found for this signature in database
4 changed files with 16 additions and 6 deletions

View file

@ -26,9 +26,7 @@
<script lang="ts" setup> <script lang="ts" setup>
const { fetchFriends } = useApi(); const { fetchFriends } = useApi();
const friends = await fetchFriends().then((response) => { const friends = sortUsers(await fetchFriends())
return response.sort((a, b) => getDisplayName(a).localeCompare(getDisplayName(b)))
})
const props = defineProps<{ const props = defineProps<{
variant: string variant: string

View file

@ -64,9 +64,7 @@ onActivated(async () => {
}); });
async function setArrayVariables() { async function setArrayVariables() {
members.value = await fetchMembers(route.params.serverId as string).then((response) => { members.value = sortMembers(await fetchMembers(route.params.serverId as string))
return response.sort((a, b) => getDisplayName(a.user, a).localeCompare(getDisplayName(b.user, b)))
});
const guildUrl = `guilds/${route.params.serverId}`; const guildUrl = `guilds/${route.params.serverId}`;
channels.value = await fetchWithApi(`${guildUrl}/channels`); channels.value = await fetchWithApi(`${guildUrl}/channels`);
console.log("channels:", channels.value); console.log("channels:", channels.value);

7
utils/sortMembers.ts Normal file
View file

@ -0,0 +1,7 @@
import type { GuildMemberResponse } from "~/types/interfaces";
export default function sortMembers(members: GuildMemberResponse[]): GuildMemberResponse[] {
return members.sort((a, b) => {
return getDisplayName(a.user, a).localeCompare(getDisplayName(b.user, b))
})
}

7
utils/sortUsers.ts Normal file
View file

@ -0,0 +1,7 @@
import type { UserResponse } from "~/types/interfaces";
export default function sortUsers(users: UserResponse[]): UserResponse[] {
return users.sort((a, b) => {
return getDisplayName(a).localeCompare(getDisplayName(b))
})
}