parent
8ce513ed09
commit
dbb16d56e2
@ -0,0 +1,61 @@
|
||||
import UserCard from '../user_card/user_card.vue'
|
||||
|
||||
const FollowersList = {
|
||||
data () {
|
||||
return {
|
||||
loading: false,
|
||||
bottomedOut: false,
|
||||
error: false
|
||||
}
|
||||
},
|
||||
props: ['userId'],
|
||||
created () {
|
||||
window.addEventListener('scroll', this.scrollLoad)
|
||||
if (this.user.followers.length === 0) {
|
||||
this.fetchFollowers()
|
||||
}
|
||||
},
|
||||
destroyed () {
|
||||
window.removeEventListener('scroll', this.scrollLoad)
|
||||
this.$store.dispatch('clearFriendsAndFollowers', this.userId)
|
||||
},
|
||||
computed: {
|
||||
user () {
|
||||
return this.$store.getters.userById(this.userId)
|
||||
},
|
||||
followers () {
|
||||
return this.user.followers
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
fetchFollowers () {
|
||||
if (!this.loading) {
|
||||
this.loading = true
|
||||
this.$store.dispatch('addFollowers', this.userId).then(followers => {
|
||||
this.error = false
|
||||
this.loading = false
|
||||
this.bottomedOut = followers.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.fetchFollowers()
|
||||
}
|
||||
}
|
||||
},
|
||||
components: {
|
||||
UserCard
|
||||
}
|
||||
}
|
||||
|
||||
export default FollowersList
|
@ -0,0 +1,12 @@
|
||||
<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" />
|
@ -0,0 +1,61 @@
|
||||
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
|
@ -0,0 +1,12 @@
|
||||
<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" />
|
Loading…
Reference in new issue