Cache updated guild icon and/or name
When a user updates their server icon and/or name, it does not update in the guild cache, which leads to the server listing always showing the old icon and/or name until they refresh the list. This fixes that by checking if the guild icon or name has been changed and updates the cache. How to check if the code works: Open the dashboard. Inspect elements. Go into application. Open local storage. Find the guilds key and change one of the server's icon or name. Reload. Click/open the server settings. Go back. Reload. The icon and/or name should be fixed then (hopefully).
This commit is contained in:
parent
d32d07287b
commit
2a5c4834c8
@ -124,11 +124,39 @@
|
||||
guild = res.data;
|
||||
}
|
||||
|
||||
function checkGuildCache(id, newIcon, newName) {
|
||||
// Retrieve the guilds array from localStorage
|
||||
let guilds = JSON.parse(window.localStorage.getItem('guilds')) || [];
|
||||
|
||||
// Find the guild with the specified id
|
||||
let guild = guilds.find(g => g.id === id);
|
||||
|
||||
// If the guild is found, update its icon and name
|
||||
if (guild) {
|
||||
let updated = false;
|
||||
if (guild.icon !== newIcon) {
|
||||
guild.icon = newIcon;
|
||||
updated = true;
|
||||
}
|
||||
if (guild.name !== newName) {
|
||||
guild.name = newName;
|
||||
updated = true;
|
||||
}
|
||||
// Save the updated guilds array back to localStorage if there were changes
|
||||
if (updated) {
|
||||
window.localStorage.setItem('guilds', JSON.stringify(guilds));
|
||||
}
|
||||
} else {
|
||||
console.error(`Guild with id ${id} not found`);
|
||||
}
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
await withLoadingScreen(async () => {
|
||||
await loadGuild();
|
||||
|
||||
iconUrl = getIconUrl(guildId, guild.icon);
|
||||
checkGuildCache(guildId, guild.icon, guild.name);
|
||||
})
|
||||
});
|
||||
</script>
|
Loading…
x
Reference in New Issue
Block a user