Merge branch 'user-profile-overhault' into 'develop'

Small refactor for followers/friends, change display to use tabs instead of "leaky brains"

Closes #111

See merge request pleroma/pleroma-fe!427
This commit is contained in:
HJ 2018-12-18 19:48:05 +00:00
commit 562c68a51c
10 changed files with 120 additions and 110 deletions

View File

@ -26,7 +26,6 @@
.tab-wrapper { .tab-wrapper {
height: 28px; height: 28px;
overflow: hidden;
position: relative; position: relative;
display: flex; display: flex;
flex: 0 0 auto; flex: 0 0 auto;

View File

@ -10,7 +10,8 @@ const Timeline = {
'timelineName', 'timelineName',
'title', 'title',
'userId', 'userId',
'tag' 'tag',
'embedded'
], ],
data () { data () {
return { return {
@ -20,15 +21,6 @@ const Timeline = {
}, },
computed: { computed: {
timelineError () { return this.$store.state.statuses.error }, timelineError () { return this.$store.state.statuses.error },
followers () {
return this.timeline.followers
},
friends () {
return this.timeline.friends
},
viewing () {
return this.timeline.viewing
},
newStatusCount () { newStatusCount () {
return this.timeline.newStatusCount return this.timeline.newStatusCount
}, },
@ -38,6 +30,14 @@ const Timeline = {
} else { } else {
return ` (${this.newStatusCount})` return ` (${this.newStatusCount})`
} }
},
classes () {
return {
root: ['timeline'].concat(!this.embedded ? ['panel', 'panel-default'] : []),
header: ['timeline-heading'].concat(!this.embedded ? ['panel-heading'] : []),
body: ['timeline-body'].concat(!this.embedded ? ['panel-body'] : []),
footer: ['timeline-footer'].concat(!this.embedded ? ['panel-footer'] : [])
}
} }
}, },
components: { components: {
@ -60,12 +60,6 @@ const Timeline = {
userId: this.userId, userId: this.userId,
tag: this.tag tag: this.tag
}) })
// don't fetch followers for public, friend, twkn
if (this.timelineName === 'user') {
this.fetchFriends()
this.fetchFollowers()
}
}, },
mounted () { mounted () {
if (typeof document.hidden !== 'undefined') { if (typeof document.hidden !== 'undefined') {
@ -103,16 +97,6 @@ const Timeline = {
tag: this.tag tag: this.tag
}).then(() => store.commit('setLoading', { timeline: this.timelineName, value: false })) }).then(() => store.commit('setLoading', { timeline: this.timelineName, value: false }))
}, 1000, this), }, 1000, this),
fetchFollowers () {
const id = this.userId
this.$store.state.api.backendInteractor.fetchFollowers({ id })
.then((followers) => this.$store.dispatch('addFollowers', { followers }))
},
fetchFriends () {
const id = this.userId
this.$store.state.api.backendInteractor.fetchFriends({ id })
.then((friends) => this.$store.dispatch('addFriends', { friends }))
},
scrollLoad (e) { scrollLoad (e) {
const bodyBRect = document.body.getBoundingClientRect() const bodyBRect = document.body.getBoundingClientRect()
const height = Math.max(bodyBRect.height, -(bodyBRect.y)) const height = Math.max(bodyBRect.height, -(bodyBRect.y))

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="timeline panel panel-default" v-if="viewing == 'statuses'"> <div :class="classes.root">
<div class="panel-heading timeline-heading"> <div :class="classes.header">
<div class="title"> <div class="title">
{{title}} {{title}}
</div> </div>
@ -14,43 +14,20 @@
{{$t('timeline.up_to_date')}} {{$t('timeline.up_to_date')}}
</div> </div>
</div> </div>
<div class="panel-body"> <div :class="classes.body">
<div class="timeline"> <div class="timeline">
<status-or-conversation v-for="status in timeline.visibleStatuses" :key="status.id" v-bind:statusoid="status" class="status-fadein"></status-or-conversation> <status-or-conversation v-for="status in timeline.visibleStatuses" :key="status.id" v-bind:statusoid="status" class="status-fadein"></status-or-conversation>
</div> </div>
</div> </div>
<div class="panel-footer"> <div :class="classes.footer">
<a href="#" v-on:click.prevent='fetchOlderStatuses()' v-if="!timeline.loading"> <a href="#" v-on:click.prevent='fetchOlderStatuses()' v-if="!timeline.loading">
<div class="new-status-notification text-center panel-footer">{{$t('timeline.load_older')}}</div> <div class="new-status-notification text-center panel-footer">{{$t('timeline.load_older')}}</div>
</a> </a>
<div class="new-status-notification text-center panel-footer" v-else>...</div> <div class="new-status-notification text-center panel-footer" v-else>...</div>
</div> </div>
</div> </div>
<div class="timeline panel panel-default" v-else-if="viewing == 'followers'">
<div class="panel-heading timeline-heading">
<div class="title">
{{$t('user_card.followers')}}
</div>
</div>
<div class="panel-body">
<div class="timeline">
<user-card v-for="follower in followers" :key="follower.id" :user="follower" :showFollows="false"></user-card>
</div>
</div>
</div>
<div class="timeline panel panel-default" v-else-if="viewing == 'friends'">
<div class="panel-heading timeline-heading">
<div class="title">
{{$t('user_card.followees')}}
</div>
</div>
<div class="panel-body">
<div class="timeline">
<user-card v-for="friend in friends" :key="friend.id" :user="friend" :showFollows="true"></user-card>
</div>
</div>
</div>
</template> </template>
<script src="./timeline.js"></script> <script src="./timeline.js"></script>
<style lang="scss"> <style lang="scss">

View File

@ -1,4 +1,5 @@
import UserCardContent from '../user_card_content/user_card_content.vue' import UserCardContent from '../user_card_content/user_card_content.vue'
import StillImage from '../still-image/still-image.vue'
import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator' import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
const UserCard = { const UserCard = {
@ -13,7 +14,8 @@ const UserCard = {
} }
}, },
components: { components: {
UserCardContent UserCardContent,
StillImage
}, },
computed: { computed: {
currentUser () { return this.$store.state.users.currentUser } currentUser () { return this.$store.state.users.currentUser }

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="card"> <div class="card">
<a href="#"> <a href="#">
<img @click.prevent="toggleUserExpanded" class="avatar" :src="user.profile_image_url"> <StillImage @click.prevent="toggleUserExpanded" class="avatar" :src="user.profile_image_url"/>
</a> </a>
<div class="usercard" v-if="userExpanded"> <div class="usercard" v-if="userExpanded">
<user-card-content :user="user" :switcher="false"></user-card-content> <user-card-content :user="user" :switcher="false"></user-card-content>
@ -41,6 +41,14 @@
margin-top:0.0em; margin-top:0.0em;
text-align: left; text-align: left;
width: 100%; width: 100%;
.user-name {
img {
object-fit: contain;
height: 16px;
width: 16px;
vertical-align: middle;
}
}
} }
.follows-you { .follows-you {

View File

@ -104,16 +104,16 @@
</div> </div>
</div> </div>
<div class="panel-body profile-panel-body" v-if="!hideBio"> <div class="panel-body profile-panel-body" v-if="!hideBio">
<div v-if="!hideUserStatsLocal || switcher" class="user-counts" :class="{clickable: switcher}"> <div v-if="!hideUserStatsLocal || switcher" class="user-counts">
<div class="user-count" v-on:click.prevent="setProfileView('statuses')" :class="{selected: selected === 'statuses'}"> <div class="user-count" v-on:click.prevent="setProfileView('statuses')">
<h5>{{ $t('user_card.statuses') }}</h5> <h5>{{ $t('user_card.statuses') }}</h5>
<span v-if="!hideUserStatsLocal">{{user.statuses_count}} <br></span> <span v-if="!hideUserStatsLocal">{{user.statuses_count}} <br></span>
</div> </div>
<div class="user-count" v-on:click.prevent="setProfileView('friends')" :class="{selected: selected === 'friends'}"> <div class="user-count" v-on:click.prevent="setProfileView('friends')">
<h5>{{ $t('user_card.followees') }}</h5> <h5>{{ $t('user_card.followees') }}</h5>
<span v-if="!hideUserStatsLocal">{{user.friends_count}}</span> <span v-if="!hideUserStatsLocal">{{user.friends_count}}</span>
</div> </div>
<div class="user-count" v-on:click.prevent="setProfileView('followers')" :class="{selected: selected === 'followers'}"> <div class="user-count" v-on:click.prevent="setProfileView('followers')">
<h5>{{ $t('user_card.followers') }}</h5> <h5>{{ $t('user_card.followers') }}</h5>
<span v-if="!hideUserStatsLocal">{{user.followers_count}}</span> <span v-if="!hideUserStatsLocal">{{user.followers_count}}</span>
</div> </div>
@ -304,18 +304,6 @@
justify-content: space-between; justify-content: space-between;
color: $fallback--lightText; color: $fallback--lightText;
color: var(--lightText, $fallback--lightText); color: var(--lightText, $fallback--lightText);
&.clickable {
.user-count {
cursor: pointer;
&:hover:not(.selected) {
transition: border-bottom 100ms;
border-bottom: 3px solid $fallback--link;
border-bottom: 3px solid var(--link, $fallback--link);
}
}
}
} }
.user-count { .user-count {
@ -323,14 +311,6 @@
padding: .5em 0 .5em 0; padding: .5em 0 .5em 0;
margin: 0 .5em; margin: 0 .5em;
&.selected {
transition: none;
border-bottom: 5px solid $fallback--link;
border-bottom: 5px solid var(--link, $fallback--link);
border-radius: $fallback--btnRadius;
border-radius: var(--btnRadius, $fallback--btnRadius);
}
h5 { h5 {
font-size:1em; font-size:1em;
font-weight: bolder; font-weight: bolder;

View File

@ -1,4 +1,5 @@
import UserCardContent from '../user_card_content/user_card_content.vue' import UserCardContent from '../user_card_content/user_card_content.vue'
import UserCard from '../user_card/user_card.vue'
import Timeline from '../timeline/timeline.vue' import Timeline from '../timeline/timeline.vue'
const UserProfile = { const UserProfile = {
@ -39,6 +40,16 @@ const UserProfile = {
return this.$route.name === 'external-user-profile' return this.$route.name === 'external-user-profile'
} }
}, },
methods: {
fetchFollowers () {
const id = this.userId
this.$store.dispatch('addFollowers', { id })
},
fetchFriends () {
const id = this.userId
this.$store.dispatch('addFriends', { id })
}
},
watch: { watch: {
userName () { userName () {
if (this.isExternal) { if (this.isExternal) {
@ -55,10 +66,17 @@ const UserProfile = {
this.$store.dispatch('stopFetching', 'user') this.$store.dispatch('stopFetching', 'user')
this.$store.commit('clearTimeline', { timeline: 'user' }) this.$store.commit('clearTimeline', { timeline: 'user' })
this.$store.dispatch('startFetching', ['user', this.userId]) this.$store.dispatch('startFetching', ['user', this.userId])
},
user () {
if (!this.user.followers) {
this.fetchFollowers()
this.fetchFriends()
}
} }
}, },
components: { components: {
UserCardContent, UserCardContent,
UserCard,
Timeline Timeline
} }
} }

View File

@ -1,20 +1,38 @@
<template> <template>
<div> <div>
<div v-if="user" class="user-profile panel panel-default"> <div v-if="user" class="user-profile panel panel-default">
<user-card-content :user="user" :switcher="true" :selected="timeline.viewing"></user-card-content> <user-card-content :user="user" :switcher="true" :selected="timeline.viewing"></user-card-content>
</div> <tab-switcher>
<div v-else class="panel user-profile-placeholder"> <Timeline :label="$t('user_card.statuses')" :embedded="true" :title="$t('user_profile.timeline_title')" :timeline="timeline" :timeline-name="'user'" :user-id="userId"/>
<div class="panel-heading"> <div :label="$t('user_card.followees')">
<div class="title"> <div v-if="friends">
{{ $t('settings.profile_tab') }} <user-card v-for="friend in friends" :key="friend.id" :user="friend" :showFollows="true"></user-card>
</div>
<div class="userlist-placeholder" v-else>
<i class="icon-spin3 animate-spin"></i>
</div> </div>
</div> </div>
<div class="panel-body"> <div :label="$t('user_card.followers')">
<i class="icon-spin3 animate-spin"></i> <div v-if="followers">
<user-card v-for="follower in followers" :key="follower.id" :user="follower" :showFollows="false"></user-card>
</div>
<div class="userlist-placeholder" v-else>
<i class="icon-spin3 animate-spin"></i>
</div>
</div>
</tab-switcher>
</div>
<div v-else class="panel user-profile-placeholder">
<div class="panel-heading">
<div class="title">
{{ $t('settings.profile_tab') }}
</div> </div>
</div> </div>
<Timeline :title="$t('user_profile.timeline_title')" :timeline="timeline" :timeline-name="'user'" :user-id="userId"/> <div class="panel-body">
<i class="icon-spin3 animate-spin"></i>
</div>
</div> </div>
</div>
</template> </template>
<script src="./user_profile.js"></script> <script src="./user_profile.js"></script>
@ -24,12 +42,36 @@
.user-profile { .user-profile {
flex: 2; flex: 2;
flex-basis: 500px; flex-basis: 500px;
padding-bottom: 10px;
.panel-heading { .panel-heading {
background: transparent; background: transparent;
flex-direction: column; flex-direction: column;
align-items: stretch; align-items: stretch;
} }
.userlist-placeholder {
display: flex;
justify-content: center;
align-items: middle;
padding: 2em;
}
.timeline-heading {
display: flex;
justify-content: center;
.loadmore-button, .alert {
flex: 1;
}
.loadmore-button {
height: 28px;
margin: 10px .6em;
}
.title, .loadmore-text {
display: none
}
}
} }
.user-profile-placeholder { .user-profile-placeholder {
.panel-body { .panel-body {

View File

@ -14,7 +14,6 @@ const emptyTl = () => ({
loading: false, loading: false,
followers: [], followers: [],
friends: [], friends: [],
viewing: 'statuses',
userId: 0, userId: 0,
flushMarker: 0 flushMarker: 0
}) })
@ -399,16 +398,6 @@ export const mutations = {
setNotificationsSilence (state, { value }) { setNotificationsSilence (state, { value }) {
state.notifications.desktopNotificationSilence = value state.notifications.desktopNotificationSilence = value
}, },
setProfileView (state, { v }) {
// load followers / friends only when needed
state.timelines['user'].viewing = v
},
addFriends (state, { friends }) {
state.timelines['user'].friends = friends
},
addFollowers (state, { followers }) {
state.timelines['user'].followers = followers
},
markNotificationsAsSeen (state) { markNotificationsAsSeen (state) {
each(state.notifications.data, (notification) => { each(state.notifications.data, (notification) => {
notification.seen = true notification.seen = true
@ -437,12 +426,6 @@ const statuses = {
setNotificationsSilence ({ rootState, commit }, { value }) { setNotificationsSilence ({ rootState, commit }, { value }) {
commit('setNotificationsSilence', { value }) commit('setNotificationsSilence', { value })
}, },
addFriends ({ rootState, commit }, { friends }) {
commit('addFriends', { friends })
},
addFollowers ({ rootState, commit }, { followers }) {
commit('addFollowers', { followers })
},
deleteStatus ({ rootState, commit }, status) { deleteStatus ({ rootState, commit }, status) {
commit('setDeleted', { status }) commit('setDeleted', { status })
apiService.deleteStatus({ id: status.id, credentials: rootState.users.currentUser.credentials }) apiService.deleteStatus({ id: status.id, credentials: rootState.users.currentUser.credentials })

View File

@ -51,6 +51,15 @@ export const mutations = {
endLogin (state) { endLogin (state) {
state.loggingIn = false state.loggingIn = false
}, },
// TODO Clean after ourselves?
addFriends (state, { id, friends }) {
const user = state.usersObject[id]
user.friends = friends
},
addFollowers (state, { id, followers }) {
const user = state.usersObject[id]
user.followers = followers
},
addNewUsers (state, users) { addNewUsers (state, users) {
each(users, (user) => mergeOrAdd(state.users, state.usersObject, user)) each(users, (user) => mergeOrAdd(state.users, state.usersObject, user))
}, },
@ -92,6 +101,14 @@ const users = {
store.rootState.api.backendInteractor.fetchUser({ id }) store.rootState.api.backendInteractor.fetchUser({ id })
.then((user) => store.commit('addNewUsers', [user])) .then((user) => store.commit('addNewUsers', [user]))
}, },
addFriends ({ rootState, commit }, { id }) {
rootState.api.backendInteractor.fetchFriends({ id })
.then((friends) => commit('addFriends', { id, friends }))
},
addFollowers ({ rootState, commit }, { id }) {
rootState.api.backendInteractor.fetchFollowers({ id })
.then((followers) => commit('addFollowers', { id, followers }))
},
registerPushNotifications (store) { registerPushNotifications (store) {
const token = store.state.currentUser.credentials const token = store.state.currentUser.credentials
const vapidPublicKey = store.rootState.instance.vapidPublicKey const vapidPublicKey = store.rootState.instance.vapidPublicKey