From 12df967cb6f182f02318c166fe459ab86cc4f4ab Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 13 Feb 2019 07:13:48 -0500 Subject: [PATCH 01/29] Add withLoadMore hoc --- src/hocs/with_load_more/with_load_more.js | 73 +++++++++++++++++++++ src/hocs/with_load_more/with_load_more.scss | 10 +++ 2 files changed, 83 insertions(+) create mode 100644 src/hocs/with_load_more/with_load_more.js create mode 100644 src/hocs/with_load_more/with_load_more.scss diff --git a/src/hocs/with_load_more/with_load_more.js b/src/hocs/with_load_more/with_load_more.js new file mode 100644 index 00000000..0f72ffd6 --- /dev/null +++ b/src/hocs/with_load_more/with_load_more.js @@ -0,0 +1,73 @@ +import Vue from 'vue' +import filter from 'lodash/filter' +import './with_load_more.scss' + +const withLoadMore = (Component, fetchEntries, getEntries) => { + const originalProps = Component.props || [] + const props = filter(originalProps, v => v !== 'entries') + + return Vue.component('withLoadMore', { + render (createElement) { + return ( +
+ + +
+ ) + }, + props, + data () { + return { + loading: false, + bottomedOut: false, + error: false + } + }, + computed: { + entries () { + return getEntries(this.$props, this.$store) || [] + } + }, + created () { + window.addEventListener('scroll', this.scrollLoad) + if (this.entries.length === 0) { + this.fetch() + } + }, + destroyed () { + window.removeEventListener('scroll', this.scrollLoad) + }, + methods: { + fetch () { + if (!this.loading) { + this.loading = true + fetchEntries(this.$props, this.$store).then((newEntries) => { + this.error = false + this.loading = false + this.bottomedOut = newEntries.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.fetch() + } + } + } + }) +} + +export default withLoadMore diff --git a/src/hocs/with_load_more/with_load_more.scss b/src/hocs/with_load_more/with_load_more.scss new file mode 100644 index 00000000..af1e1fe8 --- /dev/null +++ b/src/hocs/with_load_more/with_load_more.scss @@ -0,0 +1,10 @@ +.with-load-more { + &-footer { + padding: 10px; + text-align: center; + } + + .error { + font-size: 14px; + } +} \ No newline at end of file From 4a737cbe4507e0d0a042871725a310eb4307a766 Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 13 Feb 2019 07:14:23 -0500 Subject: [PATCH 02/29] Add reusable BasicUserCard and UserList components --- .../basic_user_card/basic_user_card.js | 28 ++++++ .../basic_user_card/basic_user_card.vue | 94 +++++++++++++++++++ src/components/user_list/user_list.js | 10 ++ src/components/user_list/user_list.vue | 11 +++ 4 files changed, 143 insertions(+) create mode 100644 src/components/basic_user_card/basic_user_card.js create mode 100644 src/components/basic_user_card/basic_user_card.vue create mode 100644 src/components/user_list/user_list.js create mode 100644 src/components/user_list/user_list.vue diff --git a/src/components/basic_user_card/basic_user_card.js b/src/components/basic_user_card/basic_user_card.js new file mode 100644 index 00000000..a8441446 --- /dev/null +++ b/src/components/basic_user_card/basic_user_card.js @@ -0,0 +1,28 @@ +import UserCardContent from '../user_card_content/user_card_content.vue' +import UserAvatar from '../user_avatar/user_avatar.vue' +import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator' + +const BasicUserCard = { + props: [ + 'user' + ], + data () { + return { + userExpanded: false + } + }, + components: { + UserCardContent, + UserAvatar + }, + methods: { + toggleUserExpanded () { + this.userExpanded = !this.userExpanded + }, + userProfileLink (user) { + return generateProfileLink(user.id, user.screen_name, this.$store.state.instance.restrictedNicknames) + } + } +} + +export default BasicUserCard diff --git a/src/components/basic_user_card/basic_user_card.vue b/src/components/basic_user_card/basic_user_card.vue new file mode 100644 index 00000000..37f810ed --- /dev/null +++ b/src/components/basic_user_card/basic_user_card.vue @@ -0,0 +1,94 @@ + + + + + diff --git a/src/components/user_list/user_list.js b/src/components/user_list/user_list.js new file mode 100644 index 00000000..30e3d765 --- /dev/null +++ b/src/components/user_list/user_list.js @@ -0,0 +1,10 @@ +import BasicUserCard from '../basic_user_card/basic_user_card.vue' + +const UserList = { + props: ['entries'], + components: { + BasicUserCard + } +} + +export default UserList diff --git a/src/components/user_list/user_list.vue b/src/components/user_list/user_list.vue new file mode 100644 index 00000000..242c04fc --- /dev/null +++ b/src/components/user_list/user_list.vue @@ -0,0 +1,11 @@ + + + \ No newline at end of file From a56d2dfeb1c5ddd93c1c23036c0e0f2ca16d273c Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 13 Feb 2019 07:15:08 -0500 Subject: [PATCH 03/29] Add blocks tab with test data to user settings page --- src/components/user_settings/user_settings.js | 14 ++++++++++++-- src/components/user_settings/user_settings.vue | 4 ++++ src/i18n/en.json | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index 904060b2..34ab99c7 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -1,9 +1,18 @@ -import { unescape } from 'lodash' +import unescape from 'lodash/unescape' +import get from 'lodash/get' import TabSwitcher from '../tab_switcher/tab_switcher.js' import ImageCropper from '../image_cropper/image_cropper.vue' import StyleSwitcher from '../style_switcher/style_switcher.vue' import fileSizeFormatService from '../../services/file_size_format/file_size_format.js' +import UserList from '../user_list/user_list.vue' +import withLoadMore from '../../hocs/with_load_more/with_load_more' + +const BlockListWithLoadMore = withLoadMore( + UserList, + (props, $store) => $store.dispatch('addFriends', $store.state.users.currentUser.id), + (props, $store) => get($store.getters.userById($store.state.users.currentUser.id), 'friends', []) +) const UserSettings = { data () { @@ -41,7 +50,8 @@ const UserSettings = { components: { StyleSwitcher, TabSwitcher, - ImageCropper + ImageCropper, + 'block-list': BlockListWithLoadMore }, computed: { user () { diff --git a/src/components/user_settings/user_settings.vue b/src/components/user_settings/user_settings.vue index 948b5c25..be9f27e7 100644 --- a/src/components/user_settings/user_settings.vue +++ b/src/components/user_settings/user_settings.vue @@ -162,6 +162,10 @@

{{$t('settings.follow_export_processing')}}

+ +
+ +
diff --git a/src/i18n/en.json b/src/i18n/en.json index 78e8fced..ddde1de2 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -110,6 +110,7 @@ "avatarRadius": "Avatars", "background": "Background", "bio": "Bio", + "blocks_tab": "Blocks", "btnRadius": "Buttons", "cBlue": "Blue (Reply, follow)", "cGreen": "Green (Retweet)", From a817cc7cb464d804ccd8af2bbe22e9b738959a3a Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 13 Feb 2019 12:05:23 -0500 Subject: [PATCH 04/29] Wire up ui to real blocks api data --- src/components/user_settings/user_settings.js | 4 ++-- src/hocs/with_load_more/with_load_more.js | 2 +- src/modules/users.js | 17 +++++++++++++++++ src/services/api/api.service.js | 17 +++++++++++++++++ .../backend_interactor_service.js | 2 ++ .../entity_normalizer.service.js | 1 + 6 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index 34ab99c7..5d8541f0 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -10,8 +10,8 @@ import withLoadMore from '../../hocs/with_load_more/with_load_more' const BlockListWithLoadMore = withLoadMore( UserList, - (props, $store) => $store.dispatch('addFriends', $store.state.users.currentUser.id), - (props, $store) => get($store.getters.userById($store.state.users.currentUser.id), 'friends', []) + (props, $store) => $store.dispatch('fetchBlocks'), + (props, $store) => get($store.state.users.currentUser, 'blocks', []) ) const UserSettings = { diff --git a/src/hocs/with_load_more/with_load_more.js b/src/hocs/with_load_more/with_load_more.js index 0f72ffd6..14d4303d 100644 --- a/src/hocs/with_load_more/with_load_more.js +++ b/src/hocs/with_load_more/with_load_more.js @@ -48,7 +48,7 @@ const withLoadMore = (Component, fetchEntries, getEntries) => { fetchEntries(this.$props, this.$store).then((newEntries) => { this.error = false this.loading = false - this.bottomedOut = newEntries.length === 0 + this.bottomedOut = !newEntries || newEntries.length === 0 }).catch(() => { this.error = true this.loading = false diff --git a/src/modules/users.js b/src/modules/users.js index 000cfd72..6ea4e0c9 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -85,6 +85,15 @@ export const mutations = { addNewUsers (state, users) { each(users, (user) => mergeOrAdd(state.users, state.usersObject, user)) }, + addBlocks (state, { blocks, page }) { + const user = state.currentUser + each(blocks, block => { + if (!find(user.blocks, { id: block.id })) { + user.blocks.push(block) + } + }) + user.blocksPage = page + 1 + }, setUserForStatus (state, status) { status.user = state.usersObject[status.user.id] }, @@ -137,6 +146,14 @@ const users = { store.rootState.api.backendInteractor.fetchUser({ id }) .then((user) => store.commit('addNewUsers', [user])) }, + fetchBlocks (store) { + const page = store.state.currentUser.blocksPage || 1 + return store.rootState.api.backendInteractor.fetchBlocks({ page }) + .then((blocks) => { + store.commit('addBlocks', { blocks, page }) + return blocks + }) + }, addFriends ({ rootState, commit }, fetchBy) { return new Promise((resolve, reject) => { const user = rootState.users.usersObject[fetchBy] diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 13d31d91..908edf7c 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -18,6 +18,7 @@ const MENTIONS_URL = '/api/statuses/mentions.json' const DM_TIMELINE_URL = '/api/statuses/dm_timeline.json' const FOLLOWERS_URL = '/api/statuses/followers.json' const FRIENDS_URL = '/api/statuses/friends.json' +const BLOCKS_URL = '/api/statuses/blocks.json' const FOLLOWING_URL = '/api/friendships/create.json' const UNFOLLOWING_URL = '/api/friendships/destroy.json' const QVITTER_USER_PREF_URL = '/api/qvitter/set_profile_pref.json' @@ -519,6 +520,21 @@ const fetchMutes = ({credentials}) => { }).then((data) => data.json()) } +const fetchBlocks = ({page, credentials}) => { + let url = BLOCKS_URL + if (page) { + url = url + `?page=${page}` + } + return fetch(url, { + headers: authHeaders(credentials) + }).then((data) => { + if (data.ok) { + return data.json() + } + throw new Error('Error fetching blocks', data) + }) +} + const suggestions = ({credentials}) => { return fetch(SUGGESTIONS_URL, { headers: authHeaders(credentials) @@ -560,6 +576,7 @@ const apiService = { fetchAllFollowing, setUserMute, fetchMutes, + fetchBlocks, register, getCaptcha, updateAvatar, diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index 80c5cc5e..43c914d9 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -63,6 +63,7 @@ const backendInteractorService = (credentials) => { } const fetchMutes = () => apiService.fetchMutes({credentials}) + const fetchBlocks = (params) => apiService.fetchBlocks({credentials, ...params}) const fetchFollowRequests = () => apiService.fetchFollowRequests({credentials}) const getCaptcha = () => apiService.getCaptcha() @@ -94,6 +95,7 @@ const backendInteractorService = (credentials) => { startFetching, setUserMute, fetchMutes, + fetchBlocks, register, getCaptcha, updateAvatar, diff --git a/src/services/entity_normalizer/entity_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js index d20ce77f..1192b6cc 100644 --- a/src/services/entity_normalizer/entity_normalizer.service.js +++ b/src/services/entity_normalizer/entity_normalizer.service.js @@ -120,6 +120,7 @@ export const parseUser = (data) => { if (data.pleroma) { output.follow_request_count = data.pleroma.follow_request_count } + output.blocks = [] return output } From 94e6de11b7f9aebbc0130c836f334921fc70ae81 Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 13 Feb 2019 14:30:12 -0500 Subject: [PATCH 05/29] Add withList hoc and remove UserList component --- src/components/user_list/user_list.js | 10 ------- src/components/user_list/user_list.vue | 11 -------- src/components/user_settings/user_settings.js | 4 ++- src/hocs/with_list/with_list.js | 27 +++++++++++++++++++ 4 files changed, 30 insertions(+), 22 deletions(-) delete mode 100644 src/components/user_list/user_list.js delete mode 100644 src/components/user_list/user_list.vue create mode 100644 src/hocs/with_list/with_list.js diff --git a/src/components/user_list/user_list.js b/src/components/user_list/user_list.js deleted file mode 100644 index 30e3d765..00000000 --- a/src/components/user_list/user_list.js +++ /dev/null @@ -1,10 +0,0 @@ -import BasicUserCard from '../basic_user_card/basic_user_card.vue' - -const UserList = { - props: ['entries'], - components: { - BasicUserCard - } -} - -export default UserList diff --git a/src/components/user_list/user_list.vue b/src/components/user_list/user_list.vue deleted file mode 100644 index 242c04fc..00000000 --- a/src/components/user_list/user_list.vue +++ /dev/null @@ -1,11 +0,0 @@ - - - \ No newline at end of file diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index 5d8541f0..a46afda6 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -5,9 +5,11 @@ import TabSwitcher from '../tab_switcher/tab_switcher.js' import ImageCropper from '../image_cropper/image_cropper.vue' import StyleSwitcher from '../style_switcher/style_switcher.vue' import fileSizeFormatService from '../../services/file_size_format/file_size_format.js' -import UserList from '../user_list/user_list.vue' +import BasicUserCard from '../basic_user_card/basic_user_card.vue' import withLoadMore from '../../hocs/with_load_more/with_load_more' +import withList from '../../hocs/with_list/with_list' +const UserList = withList(BasicUserCard, entry => ({ user: entry })) const BlockListWithLoadMore = withLoadMore( UserList, (props, $store) => $store.dispatch('fetchBlocks'), diff --git a/src/hocs/with_list/with_list.js b/src/hocs/with_list/with_list.js new file mode 100644 index 00000000..21aa288b --- /dev/null +++ b/src/hocs/with_list/with_list.js @@ -0,0 +1,27 @@ +import Vue from 'vue' +import map from 'lodash/map' + +const defaultEntryPropsGetter = entry => ({ entry }) +const defaultKeyGetter = entry => entry.id + +const withList = (Component, getEntryProps = defaultEntryPropsGetter, getKey = defaultKeyGetter) => { + return Vue.component('withList', { + render (createElement) { + return ( +
+ {map(this.entries, (entry, index) => { + const props = { + key: getKey(entry, index), + ...this.$props.entryProps, + ...getEntryProps(entry, index) + } + return + })} +
+ ) + }, + props: ['entries', 'entryProps'] + }) +} + +export default withList From 5d6e1864a5602505dedf519ef5f8e64cf19ee158 Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 13 Feb 2019 14:31:02 -0500 Subject: [PATCH 06/29] Update BasicUserCard template and add a slot for customization --- .../basic_user_card/basic_user_card.vue | 121 +++++++++--------- 1 file changed, 60 insertions(+), 61 deletions(-) diff --git a/src/components/basic_user_card/basic_user_card.vue b/src/components/basic_user_card/basic_user_card.vue index 37f810ed..7cbf647c 100644 --- a/src/components/basic_user_card/basic_user_card.vue +++ b/src/components/basic_user_card/basic_user_card.vue @@ -1,20 +1,25 @@ diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index 3bcecdf4..621dcd4b 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -9,7 +9,7 @@ import BlockCard from '../block_card/block_card.vue' import withLoadMore from '../../hocs/with_load_more/with_load_more' import withList from '../../hocs/with_list/with_list' -const BlockList = withList(BlockCard, entry => ({ user: entry })) +const BlockList = withList(BlockCard, entry => ({ userId: entry.id })) const BlockListWithLoadMore = withLoadMore( BlockList, (props, $store) => $store.dispatch('fetchBlocks'), diff --git a/src/i18n/en.json b/src/i18n/en.json index 9027803d..eeb95f9c 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -368,7 +368,8 @@ "remote_follow": "Remote follow", "statuses": "Statuses", "unblock": "Unblock", - "unblock_progress": "Unblocking..." + "unblock_progress": "Unblocking...", + "block_progress": "Blocking..." }, "user_profile": { "timeline_title": "User Timeline" diff --git a/src/modules/users.js b/src/modules/users.js index 6ea4e0c9..ce8af68c 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -154,6 +154,14 @@ const users = { return blocks }) }, + blockUser (store, id) { + return store.rootState.api.backendInteractor.blockUser(id) + .then((user) => store.commit('addNewUsers', [user])) + }, + unblockUser (store, id) { + return store.rootState.api.backendInteractor.unblockUser(id) + .then((user) => store.commit('addNewUsers', [user])) + }, addFriends ({ rootState, commit }, fetchBy) { return new Promise((resolve, reject) => { const user = rootState.users.usersObject[fetchBy] From 82702748653c7630e4f337433d47863f52c57ee4 Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 13 Feb 2019 20:59:26 -0500 Subject: [PATCH 09/29] Update hocs to pass parent-scope bindings to the wrapped component --- src/hocs/with_list/with_list.js | 11 +++--- src/hocs/with_load_more/with_load_more.js | 42 ++++++++++++++--------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/hocs/with_list/with_list.js b/src/hocs/with_list/with_list.js index 21aa288b..5ec37a2b 100644 --- a/src/hocs/with_list/with_list.js +++ b/src/hocs/with_list/with_list.js @@ -12,15 +12,18 @@ const withList = (Component, getEntryProps = defaultEntryPropsGetter, getKey = d {map(this.entries, (entry, index) => { const props = { key: getKey(entry, index), - ...this.$props.entryProps, - ...getEntryProps(entry, index) + props: { + ...this.$props.entryProps, + ...getEntryProps(entry, index) + }, + on: this.$props.entryListeners } - return + return })} ) }, - props: ['entries', 'entryProps'] + props: ['entries', 'entryProps', 'entryListeners'] }) } diff --git a/src/hocs/with_load_more/with_load_more.js b/src/hocs/with_load_more/with_load_more.js index 14d4303d..8877f8d3 100644 --- a/src/hocs/with_load_more/with_load_more.js +++ b/src/hocs/with_load_more/with_load_more.js @@ -1,20 +1,28 @@ import Vue from 'vue' import filter from 'lodash/filter' +import isEmpty from 'lodash/isEmpty' import './with_load_more.scss' -const withLoadMore = (Component, fetchEntries, getEntries) => { +const withLoadMore = (Component, fetch, select, entriesPropName = 'entries') => { const originalProps = Component.props || [] const props = filter(originalProps, v => v !== 'entries') return Vue.component('withLoadMore', { render (createElement) { + const props = { + props: { + ...this.$props, + [entriesPropName]: this.entries + }, + on: this.$listeners + } return (
- +
) @@ -29,30 +37,32 @@ const withLoadMore = (Component, fetchEntries, getEntries) => { }, computed: { entries () { - return getEntries(this.$props, this.$store) || [] + return select(this.$props, this.$store) || [] } }, created () { window.addEventListener('scroll', this.scrollLoad) if (this.entries.length === 0) { - this.fetch() + this.fetchEntries() } }, destroyed () { window.removeEventListener('scroll', this.scrollLoad) }, methods: { - fetch () { + fetchEntries () { if (!this.loading) { this.loading = true - fetchEntries(this.$props, this.$store).then((newEntries) => { - this.error = false - this.loading = false - this.bottomedOut = !newEntries || newEntries.length === 0 - }).catch(() => { - this.error = true - this.loading = false - }) + this.error = false + fetch(this.$props, this.$store) + .then((newEntries) => { + this.loading = false + this.bottomedOut = isEmpty(newEntries) + }) + .catch(() => { + this.loading = false + this.error = true + }) } }, scrollLoad (e) { @@ -63,7 +73,7 @@ const withLoadMore = (Component, fetchEntries, getEntries) => { this.$el.offsetHeight > 0 && (window.innerHeight + window.pageYOffset) >= (height - 750) ) { - this.fetch() + this.fetchEntries() } } } From 159e84532ebdae038e1263efe8832015597a5e20 Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 13 Feb 2019 21:07:28 -0500 Subject: [PATCH 10/29] Add withSubscription hoc --- .../with_subscription/with_subscription.js | 65 +++++++++++++++++++ .../with_subscription/with_subscription.scss | 10 +++ 2 files changed, 75 insertions(+) create mode 100644 src/hocs/with_subscription/with_subscription.js create mode 100644 src/hocs/with_subscription/with_subscription.scss diff --git a/src/hocs/with_subscription/with_subscription.js b/src/hocs/with_subscription/with_subscription.js new file mode 100644 index 00000000..31fc106f --- /dev/null +++ b/src/hocs/with_subscription/with_subscription.js @@ -0,0 +1,65 @@ +import Vue from 'vue' +import filter from 'lodash/filter' +import isEmpty from 'lodash/isEmpty' +import './with_subscription.scss' + +const withSubscription = (Component, fetch, select, contentPropName = 'content') => { + const originalProps = Component.props || [] + const props = filter(originalProps, v => v !== 'content') + + return Vue.component('withSubscription', { + render (createElement) { + const props = { + props: { + ...this.$props, + [contentPropName]: this.fetchedData + }, + on: this.$listeners + } + return ( +
+ + +
+ ) + }, + props, + data () { + return { + loading: false, + error: false + } + }, + computed: { + fetchedData () { + return select(this.$props, this.$store) + } + }, + created () { + if (isEmpty(this.fetchedData)) { + this.fetchData() + } + }, + methods: { + fetchData () { + if (!this.loading) { + this.loading = true + this.error = false + fetch(this.$props, this.$store) + .then(() => { + this.loading = false + }) + .catch(() => { + this.error = true + this.loading = false + }) + } + } + } + }) +} + +export default withSubscription diff --git a/src/hocs/with_subscription/with_subscription.scss b/src/hocs/with_subscription/with_subscription.scss new file mode 100644 index 00000000..5114029d --- /dev/null +++ b/src/hocs/with_subscription/with_subscription.scss @@ -0,0 +1,10 @@ +.with-subscription { + &-footer { + padding: 10px; + text-align: center; + } + + .error { + font-size: 14px; + } +} \ No newline at end of file From 8c8a6edc7800bac854ef23f29aa87f5b932cb415 Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 13 Feb 2019 21:08:14 -0500 Subject: [PATCH 11/29] Remove pagination support from block-list --- src/components/user_settings/user_settings.js | 10 ++++++---- src/components/user_settings/user_settings.vue | 2 +- src/modules/users.js | 17 ++++++----------- .../entity_normalizer.service.js | 2 +- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index 621dcd4b..8eade382 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -7,13 +7,15 @@ import StyleSwitcher from '../style_switcher/style_switcher.vue' import fileSizeFormatService from '../../services/file_size_format/file_size_format.js' import BlockCard from '../block_card/block_card.vue' import withLoadMore from '../../hocs/with_load_more/with_load_more' +import withSubscription from '../../hocs/with_subscription/with_subscription' import withList from '../../hocs/with_list/with_list' -const BlockList = withList(BlockCard, entry => ({ userId: entry.id })) -const BlockListWithLoadMore = withLoadMore( +const BlockList = withList(BlockCard, userId => ({ userId })) +const BlockListWithSubscription = withSubscription( BlockList, (props, $store) => $store.dispatch('fetchBlocks'), - (props, $store) => get($store.state.users.currentUser, 'blocks', []) + (props, $store) => get($store.state.users.currentUser, 'blockIds', []), + 'entries' ) const UserSettings = { @@ -53,7 +55,7 @@ const UserSettings = { StyleSwitcher, TabSwitcher, ImageCropper, - 'block-list': BlockListWithLoadMore + 'block-list': BlockListWithSubscription }, computed: { user () { diff --git a/src/components/user_settings/user_settings.vue b/src/components/user_settings/user_settings.vue index be9f27e7..5cf21815 100644 --- a/src/components/user_settings/user_settings.vue +++ b/src/components/user_settings/user_settings.vue @@ -164,7 +164,7 @@
- +
diff --git a/src/modules/users.js b/src/modules/users.js index ce8af68c..1f03b47e 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -1,5 +1,5 @@ import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js' -import { compact, map, each, merge, find } from 'lodash' +import { compact, map, each, merge, find, union } from 'lodash' import { set } from 'vue' import { registerPushNotifications, unregisterPushNotifications } from '../services/push/push.js' import oauthApi from '../services/new_api/oauth' @@ -85,14 +85,9 @@ export const mutations = { addNewUsers (state, users) { each(users, (user) => mergeOrAdd(state.users, state.usersObject, user)) }, - addBlocks (state, { blocks, page }) { + addBlocks (state, blockIds) { const user = state.currentUser - each(blocks, block => { - if (!find(user.blocks, { id: block.id })) { - user.blocks.push(block) - } - }) - user.blocksPage = page + 1 + user.blockIds = union(user.blockIds, blockIds) }, setUserForStatus (state, status) { status.user = state.usersObject[status.user.id] @@ -147,10 +142,10 @@ const users = { .then((user) => store.commit('addNewUsers', [user])) }, fetchBlocks (store) { - const page = store.state.currentUser.blocksPage || 1 - return store.rootState.api.backendInteractor.fetchBlocks({ page }) + return store.rootState.api.backendInteractor.fetchBlocks() .then((blocks) => { - store.commit('addBlocks', { blocks, page }) + store.commit('addBlocks', map(blocks, 'id')) + store.commit('addNewUsers', blocks) return blocks }) }, diff --git a/src/services/entity_normalizer/entity_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js index 1192b6cc..0e1be61e 100644 --- a/src/services/entity_normalizer/entity_normalizer.service.js +++ b/src/services/entity_normalizer/entity_normalizer.service.js @@ -120,7 +120,7 @@ export const parseUser = (data) => { if (data.pleroma) { output.follow_request_count = data.pleroma.follow_request_count } - output.blocks = [] + output.blockIds = [] return output } From 09315b27804beadb7590f8e908ae9d0eb1d6a992 Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 13 Feb 2019 21:21:56 -0500 Subject: [PATCH 12/29] Add a prop to force-refresh data to withSubscription hoc --- src/components/user_settings/user_settings.vue | 2 +- src/hocs/with_subscription/with_subscription.js | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/components/user_settings/user_settings.vue b/src/components/user_settings/user_settings.vue index 5cf21815..5bae583c 100644 --- a/src/components/user_settings/user_settings.vue +++ b/src/components/user_settings/user_settings.vue @@ -164,7 +164,7 @@
- +
diff --git a/src/hocs/with_subscription/with_subscription.js b/src/hocs/with_subscription/with_subscription.js index 31fc106f..633517e3 100644 --- a/src/hocs/with_subscription/with_subscription.js +++ b/src/hocs/with_subscription/with_subscription.js @@ -1,24 +1,25 @@ import Vue from 'vue' -import filter from 'lodash/filter' +import reject from 'lodash/reject' import isEmpty from 'lodash/isEmpty' +import omit from 'lodash/omit' import './with_subscription.scss' const withSubscription = (Component, fetch, select, contentPropName = 'content') => { const originalProps = Component.props || [] - const props = filter(originalProps, v => v !== 'content') + const props = reject(originalProps, v => v === 'content') return Vue.component('withSubscription', { render (createElement) { const props = { props: { - ...this.$props, + ...omit(this.$props, 'refresh'), [contentPropName]: this.fetchedData }, on: this.$listeners } return (
- + {!this.error && !this.loading && } ) }, - props, + props: [...props, 'refresh'], data () { return { loading: false, @@ -39,7 +40,7 @@ const withSubscription = (Component, fetch, select, contentPropName = 'content') } }, created () { - if (isEmpty(this.fetchedData)) { + if (this.refresh || isEmpty(this.fetchedData)) { this.fetchData() } }, From e91a94ff9c4b9559f53a4b001f8972ceca843771 Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 13 Feb 2019 22:04:28 -0500 Subject: [PATCH 13/29] Add mutes tab --- src/components/mute_card/mute_card.js | 37 +++++++++++++++++++ src/components/mute_card/mute_card.vue | 24 ++++++++++++ src/components/user_settings/user_settings.js | 13 ++++++- .../user_settings/user_settings.vue | 4 ++ src/i18n/en.json | 1 + src/modules/users.js | 25 +++++++++++-- .../entity_normalizer.service.js | 1 + 7 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 src/components/mute_card/mute_card.js create mode 100644 src/components/mute_card/mute_card.vue diff --git a/src/components/mute_card/mute_card.js b/src/components/mute_card/mute_card.js new file mode 100644 index 00000000..5dd0a9e5 --- /dev/null +++ b/src/components/mute_card/mute_card.js @@ -0,0 +1,37 @@ +import BasicUserCard from '../basic_user_card/basic_user_card.vue' + +const MuteCard = { + props: ['userId'], + data () { + return { + progress: false + } + }, + computed: { + user () { + return this.$store.getters.userById(this.userId) + }, + muted () { + return this.user.muted + } + }, + components: { + BasicUserCard + }, + methods: { + unmuteUser () { + this.progress = true + this.$store.dispatch('unmuteUser', this.user.id).then(() => { + this.progress = false + }) + }, + muteUser () { + this.progress = true + this.$store.dispatch('muteUser', this.user.id).then(() => { + this.progress = false + }) + } + } +} + +export default MuteCard diff --git a/src/components/mute_card/mute_card.vue b/src/components/mute_card/mute_card.vue new file mode 100644 index 00000000..e1bfe20b --- /dev/null +++ b/src/components/mute_card/mute_card.vue @@ -0,0 +1,24 @@ + + + \ No newline at end of file diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index 8eade382..8114d5e2 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -6,7 +6,7 @@ import ImageCropper from '../image_cropper/image_cropper.vue' import StyleSwitcher from '../style_switcher/style_switcher.vue' import fileSizeFormatService from '../../services/file_size_format/file_size_format.js' import BlockCard from '../block_card/block_card.vue' -import withLoadMore from '../../hocs/with_load_more/with_load_more' +import MuteCard from '../mute_card/mute_card.vue' import withSubscription from '../../hocs/with_subscription/with_subscription' import withList from '../../hocs/with_list/with_list' @@ -18,6 +18,14 @@ const BlockListWithSubscription = withSubscription( 'entries' ) +const MuteList = withList(MuteCard, userId => ({ userId })) +const MuteListWithSubscription = withSubscription( + MuteList, + (props, $store) => $store.dispatch('fetchMutes'), + (props, $store) => get($store.state.users.currentUser, 'muteIds', []), + 'entries' +) + const UserSettings = { data () { return { @@ -55,7 +63,8 @@ const UserSettings = { StyleSwitcher, TabSwitcher, ImageCropper, - 'block-list': BlockListWithSubscription + 'block-list': BlockListWithSubscription, + 'mute-list': MuteListWithSubscription }, computed: { user () { diff --git a/src/components/user_settings/user_settings.vue b/src/components/user_settings/user_settings.vue index 5bae583c..27f3e7cb 100644 --- a/src/components/user_settings/user_settings.vue +++ b/src/components/user_settings/user_settings.vue @@ -166,6 +166,10 @@
+ +
+ +
diff --git a/src/i18n/en.json b/src/i18n/en.json index eeb95f9c..b41b6db9 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -165,6 +165,7 @@ "lock_account_description": "Restrict your account to approved followers only", "loop_video": "Loop videos", "loop_video_silent_only": "Loop only videos without sound (i.e. Mastodon's \"gifs\")", + "mutes_tab": "Mutes", "play_videos_in_modal": "Play videos directly in the media viewer", "use_contain_fit": "Don't crop the attachment in thumbnails", "name": "Name", diff --git a/src/modules/users.js b/src/modules/users.js index 1f03b47e..71201a77 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -89,6 +89,10 @@ export const mutations = { const user = state.currentUser user.blockIds = union(user.blockIds, blockIds) }, + saveMutes (state, ids) { + const user = state.currentUser + user.muteIds = union(user.muteIds, ids) + }, setUserForStatus (state, status) { status.user = state.usersObject[status.user.id] }, @@ -157,6 +161,22 @@ const users = { return store.rootState.api.backendInteractor.unblockUser(id) .then((user) => store.commit('addNewUsers', [user])) }, + fetchMutes (store) { + return store.rootState.api.backendInteractor.fetchMutes() + .then((mutedUsers) => { + each(mutedUsers, (user) => { user.muted = true }) + store.commit('addNewUsers', mutedUsers) + store.commit('saveMutes', map(mutedUsers, 'id')) + }) + }, + muteUser (store, id) { + return store.state.api.backendInteractor.setUserMute({ id, muted: true }) + .then((user) => store.commit('addNewUsers', [user])) + }, + unmuteUser (store, id) { + return store.state.api.backendInteractor.setUserMute({ id, muted: false }) + .then((user) => store.commit('addNewUsers', [user])) + }, addFriends ({ rootState, commit }, fetchBy) { return new Promise((resolve, reject) => { const user = rootState.users.usersObject[fetchBy] @@ -300,10 +320,7 @@ const users = { store.dispatch('startFetching', { timeline: 'friends' }) // Get user mutes and follower info - store.rootState.api.backendInteractor.fetchMutes().then((mutedUsers) => { - each(mutedUsers, (user) => { user.muted = true }) - store.commit('addNewUsers', mutedUsers) - }) + store.dispatch('fetchMutes') // Fetch our friends store.rootState.api.backendInteractor.fetchFriends({ id: user.id }) diff --git a/src/services/entity_normalizer/entity_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js index 0e1be61e..49c83811 100644 --- a/src/services/entity_normalizer/entity_normalizer.service.js +++ b/src/services/entity_normalizer/entity_normalizer.service.js @@ -121,6 +121,7 @@ export const parseUser = (data) => { output.follow_request_count = data.pleroma.follow_request_count } output.blockIds = [] + output.muteIds = [] return output } From 1fd9a1c7c0f9efb3660af44f9a8fa8722e6819cc Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 13 Feb 2019 22:14:46 -0500 Subject: [PATCH 14/29] Set blockIds and muteIds to the currentUser state only --- src/modules/users.js | 4 +++- src/services/entity_normalizer/entity_normalizer.service.js | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/users.js b/src/modules/users.js index 71201a77..5921370d 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -303,6 +303,8 @@ const users = { const user = data // user.credentials = userCredentials user.credentials = accessToken + user.blockIds = [] + user.muteIds = [] commit('setCurrentUser', user) commit('addNewUsers', [user]) @@ -319,7 +321,7 @@ const users = { // Start getting fresh posts. store.dispatch('startFetching', { timeline: 'friends' }) - // Get user mutes and follower info + // Get user mutes store.dispatch('fetchMutes') // Fetch our friends diff --git a/src/services/entity_normalizer/entity_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js index 49c83811..d20ce77f 100644 --- a/src/services/entity_normalizer/entity_normalizer.service.js +++ b/src/services/entity_normalizer/entity_normalizer.service.js @@ -120,8 +120,6 @@ export const parseUser = (data) => { if (data.pleroma) { output.follow_request_count = data.pleroma.follow_request_count } - output.blockIds = [] - output.muteIds = [] return output } From 8f608e060c813dc6d9aeeb548beca971ce9b74bd Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 13 Feb 2019 22:24:09 -0500 Subject: [PATCH 15/29] Just save blocks/mutes instead of adding --- src/modules/users.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/modules/users.js b/src/modules/users.js index 5921370d..77df7168 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -1,5 +1,5 @@ import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js' -import { compact, map, each, merge, find, union } from 'lodash' +import { compact, map, each, merge, find } from 'lodash' import { set } from 'vue' import { registerPushNotifications, unregisterPushNotifications } from '../services/push/push.js' import oauthApi from '../services/new_api/oauth' @@ -85,13 +85,11 @@ export const mutations = { addNewUsers (state, users) { each(users, (user) => mergeOrAdd(state.users, state.usersObject, user)) }, - addBlocks (state, blockIds) { - const user = state.currentUser - user.blockIds = union(user.blockIds, blockIds) + saveBlocks (state, blockIds) { + state.currentUser.blockIds = blockIds }, - saveMutes (state, ids) { - const user = state.currentUser - user.muteIds = union(user.muteIds, ids) + saveMutes (state, muteIds) { + state.currentUser.muteIds = muteIds }, setUserForStatus (state, status) { status.user = state.usersObject[status.user.id] @@ -148,7 +146,7 @@ const users = { fetchBlocks (store) { return store.rootState.api.backendInteractor.fetchBlocks() .then((blocks) => { - store.commit('addBlocks', map(blocks, 'id')) + store.commit('saveBlocks', map(blocks, 'id')) store.commit('addNewUsers', blocks) return blocks }) From f81b82b4714643ba396b69ca54b97259a36a6b9f Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 13 Feb 2019 22:52:57 -0500 Subject: [PATCH 16/29] Use hoc definitions to be factor of factory --- src/components/user_settings/user_settings.js | 26 +++++++++---------- src/hocs/with_list/with_list.js | 8 +++--- src/hocs/with_load_more/with_load_more.js | 6 ++--- .../with_subscription/with_subscription.js | 6 ++--- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index 8114d5e2..21023841 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -10,21 +10,19 @@ import MuteCard from '../mute_card/mute_card.vue' import withSubscription from '../../hocs/with_subscription/with_subscription' import withList from '../../hocs/with_list/with_list' -const BlockList = withList(BlockCard, userId => ({ userId })) -const BlockListWithSubscription = withSubscription( - BlockList, - (props, $store) => $store.dispatch('fetchBlocks'), - (props, $store) => get($store.state.users.currentUser, 'blockIds', []), - 'entries' -) +const BlockList = withList({ getEntryProps: userId => ({ userId }) })(BlockCard) +const BlockListWithSubscription = withSubscription({ + fetch: (props, $store) => $store.dispatch('fetchBlocks'), + select: (props, $store) => get($store.state.users.currentUser, 'blockIds', []), + contentPropName: 'entries' +})(BlockList) -const MuteList = withList(MuteCard, userId => ({ userId })) -const MuteListWithSubscription = withSubscription( - MuteList, - (props, $store) => $store.dispatch('fetchMutes'), - (props, $store) => get($store.state.users.currentUser, 'muteIds', []), - 'entries' -) +const MuteList = withList({ getEntryProps: userId => ({ userId }) })(MuteCard) +const MuteListWithSubscription = withSubscription({ + fetch: (props, $store) => $store.dispatch('fetchMutes'), + select: (props, $store) => get($store.state.users.currentUser, 'muteIds', []), + contentPropName: 'entries' +})(MuteList) const UserSettings = { data () { diff --git a/src/hocs/with_list/with_list.js b/src/hocs/with_list/with_list.js index 5ec37a2b..c31cdcb1 100644 --- a/src/hocs/with_list/with_list.js +++ b/src/hocs/with_list/with_list.js @@ -4,8 +4,8 @@ import map from 'lodash/map' const defaultEntryPropsGetter = entry => ({ entry }) const defaultKeyGetter = entry => entry.id -const withList = (Component, getEntryProps = defaultEntryPropsGetter, getKey = defaultKeyGetter) => { - return Vue.component('withList', { +const withList = ({ getEntryProps = defaultEntryPropsGetter, getKey = defaultKeyGetter }) => (ItemComponent) => ( + Vue.component('withList', { render (createElement) { return (
@@ -18,13 +18,13 @@ const withList = (Component, getEntryProps = defaultEntryPropsGetter, getKey = d }, on: this.$props.entryListeners } - return + return })}
) }, props: ['entries', 'entryProps', 'entryListeners'] }) -} +) export default withList diff --git a/src/hocs/with_load_more/with_load_more.js b/src/hocs/with_load_more/with_load_more.js index 8877f8d3..28c741e3 100644 --- a/src/hocs/with_load_more/with_load_more.js +++ b/src/hocs/with_load_more/with_load_more.js @@ -3,8 +3,8 @@ import filter from 'lodash/filter' import isEmpty from 'lodash/isEmpty' import './with_load_more.scss' -const withLoadMore = (Component, fetch, select, entriesPropName = 'entries') => { - const originalProps = Component.props || [] +const withLoadMore = ({ fetch, select, entriesPropName = 'entries' }) => (WrappedComponent) => { + const originalProps = WrappedComponent.props || [] const props = filter(originalProps, v => v !== 'entries') return Vue.component('withLoadMore', { @@ -18,7 +18,7 @@ const withLoadMore = (Component, fetch, select, entriesPropName = 'entries') => } return (
- +