@@ -7,6 +7,9 @@ import DiscordAuthButton from "../../components/auth/DiscordAuthButton.vue";
77import MainWithFooter from " ../../components/MainWithFooter.vue" ;
88import {Guild } from " ../../stores/guild.js" ;
99import {INVITE_URL } from " ../../helpers/redirect.js" ;
10+ import {getCurrentUserGuildMetadata , isGuildAdmin , toAdminCurrentUserGuilds } from " ../../helpers/discord.js" ;
11+ import {User } from " ../../stores/user.js" ;
12+ import {fetchGuildMetaMap , filterByAdmin } from " ../../helpers/meta.js" ;
1013
1114const currentPath = ref (window .location .pathname )
1215
@@ -36,9 +39,17 @@ function reviver(key, value) {
3639 return value;
3740}
3841
42+ let user = ref (User .loadCache ());
43+ let guildMetaMap = ref (new Map ());
44+
3945let guildsKb = ref (new Map ());
4046let currentGuildId = ref (null );
4147
48+ async function loadMetadata () {
49+ guildMetaMap .value = filterByAdmin (await fetchGuildMetaMap (user .value .token .accessToken ),
50+ await getCurrentUserGuildMetadata (user .value .token .accessToken ));
51+ }
52+
4253function loadMemGuilds () {
4354 let memGuilds = JSON .parse (localStorage .getItem (' guilds' ), reviver);
4455 if (memGuilds === null ) return ;
@@ -49,14 +60,15 @@ function loadMemGuilds() {
4960 if (guildsKb .value .size > 0 ) {
5061 guildsLoaded .value = true ;
5162 }
52- currentGuildId .value = JSON .parse (localStorage .getItem (' currentGuildId' )) || null ;
63+ currentGuildId .value = JSON .parse (localStorage .getItem (' currentGuildId' )|| null ) ;
5364}
5465
5566onMounted (async () => {
67+ await loadMetadata ();
5668 loadMemGuilds ();
5769 // Load remaining guilds
70+ // await getAdminDscGuilds();
5871 await sync_guilds_kb ();
59- guildsLoaded .value = true ;
6072})
6173
6274async function setCurrentGuild (gid ) {
@@ -101,20 +113,22 @@ async function sync_guilds_kb() {
101113 <div tabindex =" 0" role =" button" class =" card-title btn btn-sm btn-ghost" v-if =" currentGuildId" >
102114 <div class =" avatar" >
103115 <div class =" w-6 rounded-xl" >
104- <img :src =" `https://cdn.discordapp.com/icons/${currentGuildId}/${guildsKb .get(currentGuildId).icon}.webp`" v-if =" guildsKb .get(currentGuildId).icon" />
116+ <img :src =" `https://cdn.discordapp.com/icons/${currentGuildId}/${guildMetaMap .get(currentGuildId).icon}.webp`" v-if =" guildMetaMap.get(currentGuildId) && guildMetaMap .get(currentGuildId).icon" />
105117 </div >
106118 </div >
107- {{ guildsKb .get(currentGuildId).name }}
119+ {{ guildMetaMap .get(currentGuildId).name }}
108120 </div >
109121 <ul tabindex =" 0" class =" dropdown-content menu bg-base-100 rounded-box z-1 p-2 shadow-sm" >
110122 <li v-if =" !guildsLoaded" >
111123 <a class =" justify-between" >
112124 <span >Loading...</span >
113125 </a >
114126 </li >
115- <li v-for =" [gid, guild] in guildsKb" ><a :class =" (gid === currentGuildId && 'menu-active')" @click =" setCurrentGuild(gid)" >
116- <div class =" w-6 rounded-xl" ><img :src =" `https://cdn.discordapp.com/icons/${gid}/${guildsKb.get(gid).icon}.webp`" v-if =" guildsKb.has(gid) && guildsKb.get(gid).icon" />
117- </div > {{ guildsKb.get(gid).name }}</a ></li >
127+ <li v-for =" [gid, guild] in guildMetaMap" >
128+ <a :class =" (gid === currentGuildId && 'menu-active')" @click =" setCurrentGuild(guild.id)" >
129+ <div class =" w-6 rounded-xl" ><img :src =" `https://cdn.discordapp.com/icons/${guild.id}/${guild.icon}.webp`" v-if =" guild.icon" />
130+ </div > {{ guild.name }}</a >
131+ </li >
118132 <li class =" bg-primary text-primary-content" >
119133 <a class =" justify-between" :href =" INVITE_URL" >
120134 <span >+ Add Server</span >
0 commit comments