Compare commits

...

12 commits

Author SHA1 Message Date
232aec13a5 Merge pull request 'Sort members list' (#45) from sort-members-list into main
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
Reviewed-on: #45
Reviewed-by: SauceyRed <saucey@saucey.red>
2025-07-18 05:34:43 +00:00
771c0699a7
Merge remote-tracking branch 'origin/main' into sort-members-list
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
ci/woodpecker/pr/build-and-publish Pipeline was successful
ci/woodpecker/pull_request_closed/build-and-publish Pipeline was successful
2025-07-18 07:34:13 +02:00
8ffe3aa738
feat: rename validation util file to validateUsername
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
ci/woodpecker/pr/build-and-publish Pipeline was successful
2025-07-18 03:49:29 +02:00
8d53b2765f
fix: hashPassword calls not working due to util file not matching function call name 2025-07-18 03:49:20 +02:00
0c4d42f3c1
style: remove function names from implicit util functions
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
ci/woodpecker/pr/build-and-publish Pipeline was successful
2025-07-16 11:27:35 +02:00
f2fcdbf733
Merge branch 'update-friend-landing-page' into sort-members-list 2025-07-16 11:26:16 +02:00
f6ede67c26
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
2025-07-16 10:59:00 +02:00
4229682d69
feat: sort member's list alphabetically
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
ci/woodpecker/pr/build-and-publish Pipeline was successful
2025-07-16 10:48:02 +02:00
cbe50dd028
fix: clean code to account for guaranteed array returns 2025-07-16 10:47:50 +02:00
100d5e80eb
style: remove unused import 2025-07-16 10:47:13 +02:00
ea1f032ffc
feat: implemend fetchMyGuilds() api 2025-07-16 10:47:03 +02:00
56ccd61107
style: ensure all api requests that return an array to return an empty array instead of undefined 2025-07-16 10:44:23 +02:00
12 changed files with 45 additions and 27 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

@ -21,8 +21,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { UserResponse } from '~/types/interfaces'; import type { UserResponse } from '~/types/interfaces';
const { fetchMembers } = useApi();
const props = defineProps<{ const props = defineProps<{
user: UserResponse user: UserResponse
}>(); }>();

View file

@ -1,24 +1,36 @@
import type { ChannelResponse, GuildMemberResponse, GuildResponse, MessageResponse, StatsResponse, UserResponse } from "~/types/interfaces"; import type { ChannelResponse, GuildMemberResponse, GuildResponse, MessageResponse, StatsResponse, UserResponse } from "~/types/interfaces";
function ensureIsArray(list: any) {
if (Array.isArray(list)) {
return list
} else {
return []
}
}
export const useApi = () => { export const useApi = () => {
async function fetchGuilds(): Promise<GuildResponse[] | undefined> { async function fetchGuilds(): Promise<GuildResponse[]> {
return await fetchWithApi(`/guilds`); return ensureIsArray(await fetchWithApi(`/guilds`));
} }
async function fetchGuild(guildId: string): Promise<GuildResponse | undefined> { async function fetchGuild(guildId: string): Promise<GuildResponse | undefined> {
return await fetchWithApi(`/guilds/${guildId}`); return await fetchWithApi(`/guilds/${guildId}`);
} }
async function fetchChannels(guildId: string): Promise<ChannelResponse[] | undefined> { async function fetchMyGuilds(): Promise<GuildResponse[]> {
return await fetchWithApi(`/guilds/${guildId}/channels`); return ensureIsArray(await fetchWithApi(`/me/guilds`));
}
async function fetchChannels(guildId: string): Promise<ChannelResponse[]> {
return ensureIsArray(await fetchWithApi(`/guilds/${guildId}/channels`));
} }
async function fetchChannel(channelId: string): Promise<ChannelResponse | undefined> { async function fetchChannel(channelId: string): Promise<ChannelResponse | undefined> {
return await fetchWithApi(`/channels/${channelId}`) return await fetchWithApi(`/channels/${channelId}`)
} }
async function fetchMembers(guildId: string): Promise<GuildMemberResponse[] | undefined> { async function fetchMembers(guildId: string): Promise<GuildMemberResponse[]> {
return await fetchWithApi(`/guilds/${guildId}/members`); return ensureIsArray(await fetchWithApi(`/guilds/${guildId}/members`));
} }
async function fetchMember(guildId: string, memberId: string): Promise<GuildMemberResponse | undefined> { async function fetchMember(guildId: string, memberId: string): Promise<GuildMemberResponse | undefined> {
@ -34,12 +46,7 @@ export const useApi = () => {
} }
async function fetchFriends(): Promise<UserResponse[]> { async function fetchFriends(): Promise<UserResponse[]> {
const response = await fetchWithApi('/me/friends') return ensureIsArray(await fetchWithApi('/me/friends'));
if (Array.isArray(response)) {
return response
} else {
return []
}
} }
async function addFriend(username: string): Promise<void> { async function addFriend(username: string): Promise<void> {
@ -90,6 +97,7 @@ export const useApi = () => {
return { return {
fetchGuilds, fetchGuilds,
fetchGuild, fetchGuild,
fetchMyGuilds,
fetchChannels, fetchChannels,
fetchChannel, fetchChannel,
fetchMembers, fetchMembers,

View file

@ -95,7 +95,7 @@ const options = [
if (invite.length == 6) { if (invite.length == 6) {
try { try {
const joinedGuild = await api.joinGuild(invite); const joinedGuild = await api.joinGuild(invite);
guilds?.push(joinedGuild); guilds.push(joinedGuild);
return await navigateTo(`/servers/${joinedGuild.uuid}`); return await navigateTo(`/servers/${joinedGuild.uuid}`);
} catch (error) { } catch (error) {
alert(`Couldn't use invite: ${error}`); alert(`Couldn't use invite: ${error}`);
@ -151,7 +151,7 @@ const options = [
} }
]; ];
const guilds: GuildResponse[] | undefined = await fetchWithApi("/me/guilds"); const guilds = await api.fetchMyGuilds();
function createDropdown() { function createDropdown() {
const dropdown = h(GuildDropdown, { options }); const dropdown = h(GuildDropdown, { options });

View file

@ -5,10 +5,10 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
const guildId = to.params.serverId as string; const guildId = to.params.serverId as string;
const channels: ChannelResponse[] | undefined = await fetchChannels(guildId); const channels: ChannelResponse[] = await fetchChannels(guildId);
console.log("channels:", channels); console.log("channels:", channels);
if (channels && channels.length > 0) { if (channels.length > 0) {
console.log("wah"); console.log("wah");
return await navigateTo(`/servers/${guildId}/channels/${channels[0].uuid}`, { replace: true }); return await navigateTo(`/servers/${guildId}/channels/${channels[0].uuid}`, { replace: true });
} }

View file

@ -64,7 +64,7 @@ onActivated(async () => {
}); });
async function setArrayVariables() { async function setArrayVariables() {
members.value = await fetchMembers(route.params.serverId as string); members.value = sortMembers(await fetchMembers(route.params.serverId as string))
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);

View file

@ -1,6 +1,6 @@
import type { GuildMemberResponse, UserResponse } from "~/types/interfaces"; import type { GuildMemberResponse, UserResponse } from "~/types/interfaces";
export function getDisplayName(user: UserResponse, member?: GuildMemberResponse): string { export default (user: UserResponse, member?: GuildMemberResponse): string => {
if (member?.nickname) return member.nickname if (member?.nickname) return member.nickname
if (user.display_name) return user.display_name if (user.display_name) return user.display_name
return user.username return user.username

View file

@ -1,4 +1,4 @@
export async function hashPassword(password: string) { export default async (password: string) => {
const encodedPass = new TextEncoder().encode(password); const encodedPass = new TextEncoder().encode(password);
const hashBuffer = await crypto.subtle.digest("SHA-384", encodedPass); const hashBuffer = await crypto.subtle.digest("SHA-384", encodedPass);
const hashArray = Array.from(new Uint8Array(hashBuffer)); const hashArray = Array.from(new Uint8Array(hashBuffer));

7
utils/sortMembers.ts Normal file
View file

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

View file

@ -0,0 +1,3 @@
export default (username: string) => {
return /^[\w.-]+$/.test(username);
}

View file

@ -1,3 +0,0 @@
export function validateUsername(username: string) {
return /^[\w.-]+$/.test(username);
}