From 18ae7bd5f366598d46a65e9da1312c98f7bb00e7 Mon Sep 17 00:00:00 2001 From: shpuld Date: Sun, 3 Feb 2019 11:58:49 +0200 Subject: Combine friends/followers --- src/components/follow_list/follow_list.js | 62 ++++++++++++++++++++++++ src/components/follow_list/follow_list.vue | 33 +++++++++++++ src/components/followers_list/followers_list.js | 61 ----------------------- src/components/followers_list/followers_list.vue | 12 ----- src/components/friends_list/friends_list.js | 61 ----------------------- src/components/friends_list/friends_list.vue | 12 ----- src/components/user_profile/user_profile.js | 6 +-- src/components/user_profile/user_profile.vue | 4 +- src/i18n/en.json | 10 ++-- src/i18n/fi.json | 4 +- 10 files changed, 108 insertions(+), 157 deletions(-) create mode 100644 src/components/follow_list/follow_list.js create mode 100644 src/components/follow_list/follow_list.vue delete mode 100644 src/components/followers_list/followers_list.js delete mode 100644 src/components/followers_list/followers_list.vue delete mode 100644 src/components/friends_list/friends_list.js delete mode 100644 src/components/friends_list/friends_list.vue (limited to 'src') diff --git a/src/components/follow_list/follow_list.js b/src/components/follow_list/follow_list.js new file mode 100644 index 00000000..6d00eb94 --- /dev/null +++ b/src/components/follow_list/follow_list.js @@ -0,0 +1,62 @@ +import UserCard from '../user_card/user_card.vue' + +const FollowList = { + data () { + return { + loading: false, + bottomedOut: false, + error: false + } + }, + props: ['userId', 'showFollowers'], + created () { + window.addEventListener('scroll', this.scrollLoad) + if (this.entries.length === 0) { + this.fetchEntries() + } + }, + destroyed () { + window.removeEventListener('scroll', this.scrollLoad) + this.$store.dispatch('clearFriendsAndFollowers', this.userId) + }, + computed: { + user () { + return this.$store.getters.userById(this.userId) + }, + entries () { + return this.showFollowers ? this.user.followers : this.user.friends + } + }, + methods: { + fetchEntries () { + if (!this.loading) { + const command = this.showFollowers ? 'addFollowers' : 'addFriends' + this.loading = true + this.$store.dispatch(command, this.userId).then(entries => { + this.error = false + this.loading = false + this.bottomedOut = entries.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.fetchEntries() + } + } + }, + components: { + UserCard + } +} + +export default FollowList diff --git a/src/components/follow_list/follow_list.vue b/src/components/follow_list/follow_list.vue new file mode 100644 index 00000000..24ab97d8 --- /dev/null +++ b/src/components/follow_list/follow_list.vue @@ -0,0 +1,33 @@ + + + + + diff --git a/src/components/followers_list/followers_list.js b/src/components/followers_list/followers_list.js deleted file mode 100644 index 13aace18..00000000 --- a/src/components/followers_list/followers_list.js +++ /dev/null @@ -1,61 +0,0 @@ -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 diff --git a/src/components/followers_list/followers_list.vue b/src/components/followers_list/followers_list.vue deleted file mode 100644 index b6bd35e1..00000000 --- a/src/components/followers_list/followers_list.vue +++ /dev/null @@ -1,12 +0,0 @@ - - -