From 46613f88548b9f1787d7fc64a4c0d2e004ecbcf1 Mon Sep 17 00:00:00 2001 From: silverpill Date: Wed, 14 Sep 2022 22:40:17 +0000 Subject: [PATCH] Switch between profile tabs without reloading page --- src/router/index.ts | 6 --- src/views/Profile.vue | 93 ++++++++++++++++++++++++++----------------- 2 files changed, 56 insertions(+), 43 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index 25be483..398eb31 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -102,12 +102,6 @@ const routes: Array = [ component: ProfileView, meta: { }, }, - { - path: "/profile/:profileId/:tabName", - name: "profile-tab", - component: ProfileView, - meta: { }, - }, { path: "/profile/:profileId/subscription", name: "profile-subscription", diff --git a/src/views/Profile.vue b/src/views/Profile.vue index e159cfa..288943a 100644 --- a/src/views/Profile.vue +++ b/src/views/Profile.vue @@ -127,72 +127,76 @@
{{ profile.statuses_count }} posts + :is="isCurrentUser() ? 'a' : 'span'" + @click="isCurrentUser() && switchTab('followers')" + > {{ profile.followers_count }} followers {{ profile.following_count }} following -
+ {{ profile.subscribers_count }} subscribers -
+
Followers Following
- - + +
+ + +
@@ -218,6 +222,7 @@ import { ProfileWrapper, } from "@/api/users" import Avatar from "@/components/Avatar.vue" +import Loader from "@/components/Loader.vue" import PostList from "@/components/PostList.vue" import ProfileListItem from "@/components/ProfileListItem.vue" import SidebarLayout from "@/components/SidebarLayout.vue" @@ -242,6 +247,7 @@ let relationship = $ref(null) let profileMenuVisible = $ref(false) let tabName = $ref("posts") +let isLoading = $ref(false) let posts = $ref([]) let followList = $ref([]) let followListNextPageUrl = $ref(null) @@ -258,7 +264,15 @@ onMounted(async () => { profile.id, ) } - tabName = route.params.tabName as string || "posts" + await switchTab("posts") +}) + +async function switchTab(name: string) { + if (!profile) { + return + } + isLoading = true + tabName = name if (tabName === "posts") { posts = await getProfileTimeline( authToken, @@ -286,7 +300,8 @@ onMounted(async () => { followList = page.profiles followListNextPageUrl = page.nextPageUrl } -}) + isLoading = false +} const actorAddress = $computed(() => { if (!profile) { @@ -702,4 +717,8 @@ $avatar-size: 170px; .profile { margin-bottom: $block-outer-padding; } + +.loader { + margin: 0 auto; +}