Skip to content

Commit

Permalink
fix: ButtonFollow loading state should be per button (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e authored May 27, 2024
1 parent d5a5681 commit a8f3394
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion apps/ui/src/components/ButtonFollow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const followedSpacesStore = useFollowedSpacesStore();
const spaceFollowed = computed(() => followedSpacesStore.isFollowed(spaceIdComposite));
const loading = computed(
() => !followedSpacesStore.followedSpacesLoaded || followedSpacesStore.followedSpaceLoading
() =>
!followedSpacesStore.followedSpacesLoaded ||
followedSpacesStore.followedSpaceLoading.has(spaceIdComposite)
);
</script>

Expand Down
6 changes: 3 additions & 3 deletions apps/ui/src/stores/followedSpaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const useFollowedSpacesStore = defineStore('followedSpaces', () => {

const followedSpacesIds = ref<string[]>([]);
const followedSpacesLoaded = ref(false);
const followedSpaceLoading = ref(false);
const followedSpaceLoading = reactive(new Set<string>());
const followedSpacesIdsByAccount = useStorage(
`${pkg.name}.spaces-followed`,
{} as Record<string, string[]>
Expand Down Expand Up @@ -88,7 +88,7 @@ export const useFollowedSpacesStore = defineStore('followedSpaces', () => {
async function toggleSpaceFollow(id: string) {
const alreadyFollowed = followedSpacesIds.value.includes(id);
const [spaceNetwork, spaceId] = id.split(':') as [NetworkID, string];
followedSpaceLoading.value = true;
followedSpaceLoading.add(id);

try {
if (alreadyFollowed) {
Expand All @@ -111,7 +111,7 @@ export const useFollowedSpacesStore = defineStore('followedSpaces', () => {
followedSpacesIdsByAccount.value[web3.value.account].unshift(id);
}
} finally {
followedSpaceLoading.value = false;
followedSpaceLoading.delete(id);
}
}

Expand Down

0 comments on commit a8f3394

Please sign in to comment.