Skip to content

Commit

Permalink
Merge pull request #26 from fiit-tp7-2023/AB#362-follow/unfollow-user
Browse files Browse the repository at this point in the history
  • Loading branch information
brano-hozza authored Apr 25, 2024
2 parents da7e798 + 2aa80f7 commit d8e6839
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion pages/profile/[address].vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
<h3>Followers: {{ userProfile.followerCount }}</h3>
<h3>Following: {{ userProfile.followingCount }}</h3>
</div>
<button v-if="!myProfile" class="follow-button" @click="followUser">Follow</button>
<button v-if="!myProfile" class="follow-button" @click="toggleFollow">
{{ userProfile.isFollowed ? 'Unfollow' : 'Follow' }}
</button>
</div>
</div>
<hr class="mt-6 border-t border-gray-500" />
Expand Down Expand Up @@ -60,6 +62,26 @@ const fetchUserProfile = async () => {
}
};
const toggleFollow = async () => {
if (userProfile.value.isFollowed) {
userProfile.value.isFollowed = false;
await unfollowUser();
} else {
userProfile.value.isFollowed = true;
await followUser();
}
};
const unfollowUser = async () => {
await $fetch(`/api/user/${route.params.address}/following`, {
method: 'DELETE',
headers: {
Authorization: `Bearer ${accountStore.accessToken}`,
},
});
fetchUserProfile(); // Re-fetch or adjust local state to show updated follower count
};
const followUser = async () => {
await $fetch(`/api/user/${route.params.address}/following`, {
method: 'POST',
Expand Down

0 comments on commit d8e6839

Please sign in to comment.