From b3022dc34cdb839e04e4836903e9e006d8a7e10a Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 31 Mar 2026 20:26:49 +0100 Subject: [PATCH] fix: handle modals on mobile + include server avatars --- app/components/StyledDialog.vue | 2 +- app/pages/dashboard/[guildId].vue | 17 ++++++++++++----- app/pages/dashboard/index.vue | 30 ++++++++++++++++++++++++------ server/api/_cron/sync.ts | 17 +++++++++++++++++ server/api/guilds/register.post.ts | 4 ++-- server/utils/discord.ts | 15 +++++++++++++++ uno.config.ts | 2 +- 7 files changed, 72 insertions(+), 15 deletions(-) diff --git a/app/components/StyledDialog.vue b/app/components/StyledDialog.vue index 9b2ecab..179cb6a 100644 --- a/app/components/StyledDialog.vue +++ b/app/components/StyledDialog.vue @@ -25,7 +25,7 @@ const open = defineModel('open', { default: false }) - +
diff --git a/app/pages/dashboard/[guildId].vue b/app/pages/dashboard/[guildId].vue index 0f4d149..a764974 100644 --- a/app/pages/dashboard/[guildId].vue +++ b/app/pages/dashboard/[guildId].vue @@ -57,11 +57,6 @@ async function saveTimezone() { const atprotoHandle = ref('') const atprotoDialogOpen = ref(false) -function connectAtproto() { - if (!atprotoHandle.value) return - navigateTo(`/auth/bluesky?handle=${encodeURIComponent(atprotoHandle.value)}&guild=${route.params.guildId}`, { external: true }) -} - // Resolve atproto profile for connected DID const atprotoProfile = ref<{ handle?: string, displayName?: string, avatar?: string } | null>(null) watch(() => guild.value?.atprotoDid, async (did) => { @@ -80,6 +75,18 @@ watch(() => guild.value?.atprotoDid, async (did) => { } }, { immediate: true }) +// Prefill handle from previously connected profile +watch(() => atprotoProfile.value?.handle, (handle) => { + if (handle && !atprotoHandle.value) { + atprotoHandle.value = handle + } +}, { immediate: true }) + +function connectAtproto() { + if (!atprotoHandle.value) return + navigateTo(`/auth/bluesky?handle=${encodeURIComponent(atprotoHandle.value)}&guild=${route.params.guildId}`, { external: true }) +} + const removing = ref(false) const removeError = ref('') const confirmRemoveOpen = ref(false) diff --git a/app/pages/dashboard/index.vue b/app/pages/dashboard/index.vue index 38dbb15..317a576 100644 --- a/app/pages/dashboard/index.vue +++ b/app/pages/dashboard/index.vue @@ -40,14 +40,14 @@ const withoutBot = computed(() => const registering = ref(null) const registerError = ref('') -async function registerGuild(guildId: string, guildName: string) { +async function registerGuild(guildId: string, guildName: string, guildIcon: string | null) { registering.value = guildId registerError.value = '' try { const result = await $fetch('/api/guilds/register', { method: 'POST', - body: { guildId, guildName }, + body: { guildId, guildName, guildIcon }, }) await navigateTo(`/dashboard/${result.id}`) } @@ -97,11 +97,29 @@ async function registerGuild(guildId: string, guildName: string) {
- + class="card p-4 flex items-center gap-3" + > + +
+ + +
+
@@ -194,7 +212,7 @@ async function registerGuild(guildId: string, guildName: string) { size="sm" :loading="registering === guild.id" :disabled="registering === guild.id" - @click="registerGuild(guild.id, guild.name)" + @click="registerGuild(guild.id, guild.name, guild.icon)" > enable diff --git a/server/api/_cron/sync.ts b/server/api/_cron/sync.ts index f11d98e..4b79246 100644 --- a/server/api/_cron/sync.ts +++ b/server/api/_cron/sync.ts @@ -27,6 +27,23 @@ async function syncGuildEvents(h3Event: Parameters const guild = await getGuild(guildId) if (!guild) return 0 + // Refresh guild name and icon from Discord + const guildInfo = await fetchGuildInfo(guildId) + if (guildInfo) { + let updated = false + if (guildInfo.name !== guild.name) { + guild.name = guildInfo.name + updated = true + } + if (guildInfo.icon !== guild.icon) { + guild.icon = guildInfo.icon + updated = true + } + if (updated) { + await setGuild(guild) + } + } + if (guild.atprotoDid) { try { await getAtprotoAgent(h3Event, guild.atprotoDid) diff --git a/server/api/guilds/register.post.ts b/server/api/guilds/register.post.ts index 66a6907..ec993f0 100644 --- a/server/api/guilds/register.post.ts +++ b/server/api/guilds/register.post.ts @@ -4,7 +4,7 @@ export default defineEventHandler(async (event) => { throw createError({ statusCode: 403, message: 'Discord login required' }) } - const body = await readBody<{ guildId: string, guildName?: string }>(event) + const body = await readBody<{ guildId: string, guildName?: string, guildIcon?: string | null }>(event) if (!body.guildId) { throw createError({ statusCode: 400, message: 'Missing guildId' }) } @@ -22,7 +22,7 @@ export default defineEventHandler(async (event) => { const guild: StoredGuild = { id: body.guildId, name: body.guildName || `Guild ${body.guildId}`, - icon: null, + icon: body.guildIcon ?? null, addedBy: user.discordId, atprotoDid: null, timezone: 'UTC', diff --git a/server/utils/discord.ts b/server/utils/discord.ts index 4c4c468..357c012 100644 --- a/server/utils/discord.ts +++ b/server/utils/discord.ts @@ -44,6 +44,21 @@ export async function fetchGuildEvents(guildId: string): Promise { + try { + const config = useRuntimeConfig() + return await discordFetch<{ id: string, name: string, icon: string | null }>( + `/guilds/${guildId}`, + { + headers: { Authorization: `Bot ${config.discordBotToken}` }, + }, + ) + } + catch { + return null + } +} + export async function checkBotInGuild(guildId: string): Promise { const cacheKey = `cache:bot-in-guild:${guildId}` const cached = await useStorage('kv').getItem(cacheKey) diff --git a/uno.config.ts b/uno.config.ts index 782bec0..5c7c56b 100644 --- a/uno.config.ts +++ b/uno.config.ts @@ -153,7 +153,7 @@ export default defineConfig({ /* ——— Skeleton ——— */ 'skeleton': 'bg-surface-raised rounded relative overflow-hidden', - 'skeleton-shimmer': 'after:absolute after:inset-0 after:bg-gradient-to-r after:from-transparent after:via-white/10 after:to-transparent after:animate-shimmer', + 'skeleton-shimmer': 'after:absolute after:inset-0 after:bg-gradient-to-r after:from-transparent after:via-primary/10 after:to-transparent after:animate-shimmer', /* ——— Links ——— */ 'link-accent': 'text-accent hover:text-accent-hover transition-colors underline underline-offset-2 decoration-accent/30 hover:decoration-accent', -- knotmirror 0.0.1