From 9681eb42c37ae036d6bc47988f1f0af478568305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=C3=ADna=20T=C3=B3thov=C3=A1?= Date: Mon, 29 Apr 2024 20:16:25 +0200 Subject: [PATCH 1/3] :sparkles: display user followers --- pages/profile/[address].vue | 158 +++++++++++++++++++++++++++++++++-- pages/profile/index.vue | 162 +++++++++++++++++++++++++++++++++++- types/dtos/user.ts | 6 +- 3 files changed, 315 insertions(+), 11 deletions(-) diff --git a/pages/profile/[address].vue b/pages/profile/[address].vue index 1d1bd7d..1174385 100644 --- a/pages/profile/[address].vue +++ b/pages/profile/[address].vue @@ -12,8 +12,8 @@

{{ userProfile.address }}

+ + @@ -38,7 +110,7 @@ import { ref, onMounted } from 'vue'; import { useRoute } from 'vue-router'; import { useAccountStore } from '~/store'; -import type { UserPostResponseDTO, UserProfileDTO } from '~/types/dtos'; +import type { UserFollowersDTO, UserFollowingDTO, UserPostResponseDTO, UserProfileDTO } from '~/types/dtos'; import NftPost from '~/components/posts/NftPost.vue'; const error = ref(null); @@ -46,6 +118,8 @@ const error = ref(null); const route = useRoute(); const accountStore = useAccountStore(); const userProfile = ref(null); +const userFollowers = ref(null); +const userFollowing = ref(null); const fetchUserProfile = async () => { const address = route.params.address; // Get the address from the URL parameter @@ -72,6 +146,23 @@ const toggleFollow = async () => { } }; +const showFollowersModal = ref(false); +const showFollowingModal = ref(false); + +const toggleFollowersModal = async () => { + showFollowersModal.value = !showFollowersModal.value; + if (showFollowersModal.value) { + await getFollowers(); + } +}; + +const toggleFollowingModal = async () => { + showFollowingModal.value = !showFollowingModal.value; + if (showFollowingModal.value) { + await getFollowing(); + } +}; + const unfollowUser = async () => { await $fetch(`/api/user/${route.params.address}/following`, { method: 'DELETE', @@ -92,6 +183,26 @@ const followUser = async () => { fetchUserProfile(); // Re-fetch or adjust local state to show updated follower count }; +const getFollowers = async () => { + const data = await $fetch(`/api/user/${route.params.address}/followers`, { + headers: { + Authorization: `Bearer ${accountStore.accessToken}`, + }, + }); + userFollowers.value = data; + fetchUserProfile(); +}; + +const getFollowing = async () => { + const data = await $fetch(`/api/user/${route.params.address}/following`, { + headers: { + Authorization: `Bearer ${accountStore.accessToken}`, + }, + }); + userFollowing.value = data; + fetchUserProfile(); +}; + const posts = ref([]); const pageSize = 20; const pageNumber = ref(1); @@ -185,7 +296,7 @@ h2 { .follow-button { @apply mt-5 py-2.5 px-5 bg-[#f472b6] text-white border-none rounded cursor-pointer transition-colors; - width: 100%; /* Ensures the button stretches to fill its container */ + width: 100%; } .follow-button:hover { @@ -194,7 +305,7 @@ h2 { .follow-info { @apply flex gap-5 mt-2.5 justify-end items-center; - width: 100%; /* This ensures the flex container takes full width */ + width: 100%; } .follow-info h3 { @@ -218,4 +329,41 @@ hr { @apply justify-center; } } +.modal { + @apply fixed top-0 left-0 w-full h-full bg-[rgba(0,0,0,0.5)] flex items-start p-48 justify-center; +} + +.modal-content { + @apply bg-[#1e293b] p-5 rounded w-11/12 max-w-5xl relative; +} + +.close { + @apply absolute top-2 right-2 text-xl cursor-pointer; +} + +.follower-item { + @apply flex items-center mt-2; +} + +.follower-info { + @apply flex flex-col; +} + +.follower-avatar-container { + @apply flex-shrink-0; /* Prevents the avatar container from shrinking */ +} + +.follower-avatar, +.follower-avatar.placeholder { + @apply w-8 h-8 rounded-full bg-gray-300; /* Sets the width and height, and background color for placeholder */ + display: inline-block; /* Ensures that the img element behaves like a block element filling the container */ +} + +.follower-avatar img { + @apply w-full h-full object-cover; /* Ensures the image covers the entire area of the avatar */ +} + +.follower-link { + @apply text-white no-underline hover:underline py-3; +} diff --git a/pages/profile/index.vue b/pages/profile/index.vue index f92a2af..2f21124 100644 --- a/pages/profile/index.vue +++ b/pages/profile/index.vue @@ -12,8 +12,8 @@

{{ userProfile.address }}

@@ -30,13 +30,92 @@ /> + +