forked from AkkomaGang/akkoma-fe
Combine friends/followers
This commit is contained in:
parent
b614cb94e5
commit
18ae7bd5f3
9 changed files with 58 additions and 107 deletions
|
@ -1,6 +1,6 @@
|
||||||
import UserCard from '../user_card/user_card.vue'
|
import UserCard from '../user_card/user_card.vue'
|
||||||
|
|
||||||
const FollowersList = {
|
const FollowList = {
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
loading: false,
|
loading: false,
|
||||||
|
@ -8,11 +8,11 @@ const FollowersList = {
|
||||||
error: false
|
error: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
props: ['userId'],
|
props: ['userId', 'showFollowers'],
|
||||||
created () {
|
created () {
|
||||||
window.addEventListener('scroll', this.scrollLoad)
|
window.addEventListener('scroll', this.scrollLoad)
|
||||||
if (this.user.followers.length === 0) {
|
if (this.entries.length === 0) {
|
||||||
this.fetchFollowers()
|
this.fetchEntries()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
destroyed () {
|
destroyed () {
|
||||||
|
@ -23,18 +23,19 @@ const FollowersList = {
|
||||||
user () {
|
user () {
|
||||||
return this.$store.getters.userById(this.userId)
|
return this.$store.getters.userById(this.userId)
|
||||||
},
|
},
|
||||||
followers () {
|
entries () {
|
||||||
return this.user.followers
|
return this.showFollowers ? this.user.followers : this.user.friends
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
fetchFollowers () {
|
fetchEntries () {
|
||||||
if (!this.loading) {
|
if (!this.loading) {
|
||||||
|
const command = this.showFollowers ? 'addFollowers' : 'addFriends'
|
||||||
this.loading = true
|
this.loading = true
|
||||||
this.$store.dispatch('addFollowers', this.userId).then(followers => {
|
this.$store.dispatch(command, this.userId).then(entries => {
|
||||||
this.error = false
|
this.error = false
|
||||||
this.loading = false
|
this.loading = false
|
||||||
this.bottomedOut = followers.length === 0
|
this.bottomedOut = entries.length === 0
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
this.error = true
|
this.error = true
|
||||||
this.loading = false
|
this.loading = false
|
||||||
|
@ -49,7 +50,7 @@ const FollowersList = {
|
||||||
this.$el.offsetHeight > 0 &&
|
this.$el.offsetHeight > 0 &&
|
||||||
(window.innerHeight + window.pageYOffset) >= (height - 750)
|
(window.innerHeight + window.pageYOffset) >= (height - 750)
|
||||||
) {
|
) {
|
||||||
this.fetchFollowers()
|
this.fetchEntries()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -58,4 +59,4 @@ const FollowersList = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default FollowersList
|
export default FollowList
|
33
src/components/follow_list/follow_list.vue
Normal file
33
src/components/follow_list/follow_list.vue
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<template>
|
||||||
|
<div class="follow-list">
|
||||||
|
<user-card
|
||||||
|
v-for="entry in entries"
|
||||||
|
:key="entry.id" :user="entry"
|
||||||
|
:showFollows="true"
|
||||||
|
/>
|
||||||
|
<div class="text-center panel-footer">
|
||||||
|
<a v-if="error" @click="fetchEntries" class="alert error">
|
||||||
|
{{$t('general.generic_error')}}
|
||||||
|
</a>
|
||||||
|
<i v-else-if="loading" class="icon-spin3 animate-spin"/>
|
||||||
|
<span v-else-if="bottomedOut"></span>
|
||||||
|
<a v-else @click="fetchEntries">{{$t('general.more')}}</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script src="./follow_list.js"></script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
|
||||||
|
.follow-list {
|
||||||
|
.panel-footer {
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
|
@ -1,12 +0,0 @@
|
||||||
<template>
|
|
||||||
<div>
|
|
||||||
<user-card v-for="follower in followers" :key="follower.id" :user="follower" :showFollows="true"></user-card>
|
|
||||||
<div @click="fetchFollowers" class="new-status-notification text-center panel-footer">
|
|
||||||
<span v-if="error" class="alert error">Error loading followers</span>
|
|
||||||
<i v-else-if="loading" class="icon-spin3 animate-spin"/>
|
|
||||||
<span v-else-if="bottomedOut"></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script src="./followers_list.js" />
|
|
|
@ -1,61 +0,0 @@
|
||||||
import UserCard from '../user_card/user_card.vue'
|
|
||||||
|
|
||||||
const FriendsList = {
|
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
loading: false,
|
|
||||||
bottomedOut: false,
|
|
||||||
error: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
props: ['userId'],
|
|
||||||
created () {
|
|
||||||
window.addEventListener('scroll', this.scrollLoad)
|
|
||||||
if (this.user.followers.length === 0) {
|
|
||||||
this.fetchFriends()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
destroyed () {
|
|
||||||
window.removeEventListener('scroll', this.scrollLoad)
|
|
||||||
this.$store.dispatch('clearFriendsAndFollowers', this.userId)
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
user () {
|
|
||||||
return this.$store.getters.userById(this.userId)
|
|
||||||
},
|
|
||||||
friends () {
|
|
||||||
return this.user.friends
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
fetchFriends () {
|
|
||||||
if (!this.loading) {
|
|
||||||
this.loading = true
|
|
||||||
this.$store.dispatch('addFriends', this.userId).then(friends => {
|
|
||||||
this.error = false
|
|
||||||
this.loading = false
|
|
||||||
this.bottomedOut = friends.length === 0
|
|
||||||
}).catch(() => {
|
|
||||||
this.error = true
|
|
||||||
this.loading = false
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
scrollLoad (e) {
|
|
||||||
const bodyBRect = document.body.getBoundingClientRect()
|
|
||||||
const height = Math.max(bodyBRect.height, -(bodyBRect.y))
|
|
||||||
if (this.loading === false &&
|
|
||||||
this.bottomedOut === false &&
|
|
||||||
this.$el.offsetHeight > 0 &&
|
|
||||||
(window.innerHeight + window.pageYOffset) >= (height - 750)
|
|
||||||
) {
|
|
||||||
this.fetchFriends()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
components: {
|
|
||||||
UserCard
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default FriendsList
|
|
|
@ -1,12 +0,0 @@
|
||||||
<template>
|
|
||||||
<div>
|
|
||||||
<user-card v-for="friend in friends" :key="friend.id" :user="friend" :showFollows="true"></user-card>
|
|
||||||
<div @click="fetchFriends" class="new-status-notification text-center panel-footer">
|
|
||||||
<span v-if="error" class="alert error">Error loading follows</span>
|
|
||||||
<i v-else-if="loading" class="icon-spin3 animate-spin"/>
|
|
||||||
<span v-else-if="bottomedOut"></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script src="./friends_list.js" />
|
|
|
@ -1,8 +1,7 @@
|
||||||
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 UserCard from '../user_card/user_card.vue'
|
||||||
import Timeline from '../timeline/timeline.vue'
|
import Timeline from '../timeline/timeline.vue'
|
||||||
import FriendsList from '../friends_list/friends_list.vue'
|
import FollowList from '../follow_list/follow_list.vue'
|
||||||
import FollowersList from '../followers_list/followers_list.vue'
|
|
||||||
|
|
||||||
const UserProfile = {
|
const UserProfile = {
|
||||||
created () {
|
created () {
|
||||||
|
@ -102,8 +101,7 @@ const UserProfile = {
|
||||||
UserCardContent,
|
UserCardContent,
|
||||||
UserCard,
|
UserCard,
|
||||||
Timeline,
|
Timeline,
|
||||||
FriendsList,
|
FollowList
|
||||||
FollowersList
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,13 +16,13 @@
|
||||||
:user-id="fetchBy"
|
:user-id="fetchBy"
|
||||||
/>
|
/>
|
||||||
<div :label="$t('user_card.followees')">
|
<div :label="$t('user_card.followees')">
|
||||||
<FriendsList v-if="user.friends_count > 0" :userId="userId" />
|
<FollowList v-if="user.friends_count > 0" :userId="userId" :showFollowers="false" />
|
||||||
<div class="userlist-placeholder" v-else>
|
<div class="userlist-placeholder" v-else>
|
||||||
<i class="icon-spin3 animate-spin"></i>
|
<i class="icon-spin3 animate-spin"></i>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div :label="$t('user_card.followers')">
|
<div :label="$t('user_card.followers')">
|
||||||
<FollowersList v-if="user.followers_count > 0" :userId="userId" />
|
<FollowList v-if="user.followers_count > 0" :userId="userId" :showFollowers="true" />
|
||||||
<div class="userlist-placeholder" v-else>
|
<div class="userlist-placeholder" v-else>
|
||||||
<i class="icon-spin3 animate-spin"></i>
|
<i class="icon-spin3 animate-spin"></i>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -17,7 +17,9 @@
|
||||||
},
|
},
|
||||||
"general": {
|
"general": {
|
||||||
"apply": "Apply",
|
"apply": "Apply",
|
||||||
"submit": "Submit"
|
"submit": "Submit",
|
||||||
|
"more": "More",
|
||||||
|
"generic_error": "An error occured"
|
||||||
},
|
},
|
||||||
"login": {
|
"login": {
|
||||||
"login": "Log in",
|
"login": "Log in",
|
||||||
|
@ -365,9 +367,9 @@
|
||||||
},
|
},
|
||||||
"upload":{
|
"upload":{
|
||||||
"error": {
|
"error": {
|
||||||
"base": "Upload failed.",
|
"base": "Upload failed.",
|
||||||
"file_too_big": "File too big [{filesize}{filesizeunit} / {allowedsize}{allowedsizeunit}]",
|
"file_too_big": "File too big [{filesize}{filesizeunit} / {allowedsize}{allowedsizeunit}]",
|
||||||
"default": "Try again later"
|
"default": "Try again later"
|
||||||
},
|
},
|
||||||
"file_size_units": {
|
"file_size_units": {
|
||||||
"B": "B",
|
"B": "B",
|
||||||
|
|
|
@ -17,7 +17,9 @@
|
||||||
},
|
},
|
||||||
"general": {
|
"general": {
|
||||||
"apply": "Aseta",
|
"apply": "Aseta",
|
||||||
"submit": "Lähetä"
|
"submit": "Lähetä",
|
||||||
|
"more": "Lisää",
|
||||||
|
"generic_error": "Virhe tapahtui"
|
||||||
},
|
},
|
||||||
"login": {
|
"login": {
|
||||||
"login": "Kirjaudu sisään",
|
"login": "Kirjaudu sisään",
|
||||||
|
|
Loading…
Reference in a new issue