From 7dfcabb5433a5eb805bbda6ef87390c6ed2d5372 Mon Sep 17 00:00:00 2001 From: taehoon Date: Sat, 10 Aug 2019 14:49:37 -0400 Subject: [PATCH] sync profile tab state with location query --- src/components/user_profile/user_profile.js | 14 ++++++++-- src/components/user_profile/user_profile.vue | 29 ++++++++++++-------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/components/user_profile/user_profile.js b/src/components/user_profile/user_profile.js index 1250d6f1..00055707 100644 --- a/src/components/user_profile/user_profile.js +++ b/src/components/user_profile/user_profile.js @@ -22,16 +22,20 @@ const FriendList = withLoadMore({ additionalPropNames: ['userId'] })(List) +const defaultTabKey = 'statuses' + const UserProfile = { data () { return { error: false, - userId: null + userId: null, + tab: defaultTabKey } }, created () { const routeParams = this.$route.params this.load(routeParams.name || routeParams.id) + this.tab = get(this.$route, 'query.tab', defaultTabKey) }, destroyed () { this.stopFetching() @@ -115,6 +119,10 @@ const UserProfile = { switchUser (userNameOrId) { this.stopFetching() this.load(userNameOrId) + }, + onTabSwitch (tab) { + this.tab = tab + this.$router.replace({ query: { tab } }) } }, watch: { @@ -128,8 +136,8 @@ const UserProfile = { this.switchUser(newVal) } }, - $route () { - this.$refs.tabSwitcher.activateTab(0)() + '$route.query': function (newVal) { + this.tab = newVal.tab || defaultTabKey } }, components: { diff --git a/src/components/user_profile/user_profile.vue b/src/components/user_profile/user_profile.vue index cffa28f1..42516916 100644 --- a/src/components/user_profile/user_profile.vue +++ b/src/components/user_profile/user_profile.vue @@ -12,22 +12,24 @@ rounded="top" /> -
- -
+
@@ -42,6 +44,7 @@
@@ -58,6 +61,7 @@