feat: implemend fetchMyGuilds() api

This commit is contained in:
Twig 2025-07-16 10:47:03 +02:00
parent 56ccd61107
commit ea1f032ffc
No known key found for this signature in database
2 changed files with 7 additions and 2 deletions

View file

@ -17,6 +17,10 @@ export const useApi = () => {
return await fetchWithApi(`/guilds/${guildId}`); return await fetchWithApi(`/guilds/${guildId}`);
} }
async function fetchMyGuilds(): Promise<GuildResponse[]> {
return ensureIsArray(await fetchWithApi(`/me/guilds`));
}
async function fetchChannels(guildId: string): Promise<ChannelResponse[]> { async function fetchChannels(guildId: string): Promise<ChannelResponse[]> {
return ensureIsArray(await fetchWithApi(`/guilds/${guildId}/channels`)); return ensureIsArray(await fetchWithApi(`/guilds/${guildId}/channels`));
} }
@ -85,6 +89,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 });