mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Fix bug, maintain filters across page changes
- filter was a bit off for categories, clear the filter if there are no categories - a user should maintain their filter until they clear it
This commit is contained in:
parent
c00ab4450b
commit
0cee0ecccb
@ -131,29 +131,29 @@ export default {
|
|||||||
},
|
},
|
||||||
toggleCategory(categoryId) {
|
toggleCategory(categoryId) {
|
||||||
if (!categoryId) {
|
if (!categoryId) {
|
||||||
this.setSelectedCategoryIds([])
|
this.setSelectedCategoryIds()
|
||||||
} else {
|
} else {
|
||||||
this.setSelectedCategoryIds(categoryId)
|
this.setSelectedCategoryIds(categoryId)
|
||||||
}
|
}
|
||||||
this.setFilteredByCategories(!!this.selectedCategoryIds.length)
|
this.setFilteredByCategories(!!this.selectedCategoryIds.length)
|
||||||
this.setCategoriesFilter({ categories_some: { id_in: this.selectedCategoryIds } })
|
this.setCategoriesFilter(
|
||||||
|
this.selectedCategoryIds.length
|
||||||
|
? { categories_some: { id_in: this.selectedCategoryIds } }
|
||||||
|
: {},
|
||||||
|
)
|
||||||
this.toggleFilter()
|
this.toggleFilter()
|
||||||
},
|
},
|
||||||
toggleOnlyFollowed() {
|
toggleOnlyFollowed() {
|
||||||
this.setFilteredByFollowers(!this.filteredByUsersFollowed)
|
this.setFilteredByFollowers(!this.filteredByUsersFollowed)
|
||||||
this.setUsersFollowedFilter({ author: { followedBy_some: { id: this.user.id } } })
|
this.setUsersFollowedFilter(
|
||||||
|
this.filteredByUsersFollowed ? { author: { followedBy_some: { id: this.user.id } } } : {},
|
||||||
|
)
|
||||||
this.toggleFilter()
|
this.toggleFilter()
|
||||||
},
|
},
|
||||||
toggleFilter() {
|
toggleFilter() {
|
||||||
if (this.filteredByUsersFollowed) {
|
this.filter = {
|
||||||
this.filter = this.filteredByCategories
|
...this.usersFollowedFilter,
|
||||||
? {
|
...this.categoriesFilter,
|
||||||
...this.usersFollowedFilter,
|
|
||||||
...this.categoriesFilter,
|
|
||||||
}
|
|
||||||
: { ...this.usersFollowedFilter }
|
|
||||||
} else {
|
|
||||||
this.filter = this.filteredByCategories ? { ...this.categoriesFilter } : {}
|
|
||||||
}
|
}
|
||||||
this.$emit('filterPosts', this.filter)
|
this.$emit('filterPosts', this.filter)
|
||||||
},
|
},
|
||||||
|
|||||||
@ -184,6 +184,8 @@ export default {
|
|||||||
quickSearchResults: 'search/quickResults',
|
quickSearchResults: 'search/quickResults',
|
||||||
quickSearchPending: 'search/quickPending',
|
quickSearchPending: 'search/quickPending',
|
||||||
showFilterPostsDropdown: 'default/showFilterPostsDropdown',
|
showFilterPostsDropdown: 'default/showFilterPostsDropdown',
|
||||||
|
usersFollowedFilter: 'posts/usersFollowedFilter',
|
||||||
|
categoriesFilter: 'posts/categoriesFilter',
|
||||||
}),
|
}),
|
||||||
userName() {
|
userName() {
|
||||||
const { name } = this.user || {}
|
const { name } = this.user || {}
|
||||||
@ -256,8 +258,14 @@ export default {
|
|||||||
},
|
},
|
||||||
redirectToRoot() {
|
redirectToRoot() {
|
||||||
this.$router.replace('/')
|
this.$router.replace('/')
|
||||||
this.setFilteredByFollowers(false)
|
this.fetchPosts({
|
||||||
this.fetchPosts({ i18n: this.$i18n, filter: {} })
|
i18n: this.$i18n,
|
||||||
|
filter: {
|
||||||
|
...this.usersFollowedFilter,
|
||||||
|
...this.categoriesFilter,
|
||||||
|
...this.filter,
|
||||||
|
},
|
||||||
|
})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
apollo: {
|
apollo: {
|
||||||
|
|||||||
@ -99,10 +99,6 @@ export default {
|
|||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
this.toggleShowFilterPostsDropdown(false)
|
this.toggleShowFilterPostsDropdown(false)
|
||||||
this.setFilteredByUserFollowed(false)
|
|
||||||
this.setFilteredByCategories(false)
|
|
||||||
this.setFilteredByUserFollowed(false)
|
|
||||||
this.setSelectedCategoryIds([])
|
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
Post(post) {
|
Post(post) {
|
||||||
@ -127,9 +123,6 @@ export default {
|
|||||||
...mapMutations({
|
...mapMutations({
|
||||||
setPosts: 'posts/SET_POSTS',
|
setPosts: 'posts/SET_POSTS',
|
||||||
toggleShowFilterPostsDropdown: 'default/SET_SHOW_FILTER_POSTS_DROPDOWN',
|
toggleShowFilterPostsDropdown: 'default/SET_SHOW_FILTER_POSTS_DROPDOWN',
|
||||||
setFilteredByUserFollowed: 'posts/SET_FILTERED_BY_FOLLOWERS',
|
|
||||||
setFilteredByCategories: 'posts/SET_FILTERED_BY_CATEGORIES',
|
|
||||||
setSelectedCategoryIds: 'posts/SET_SELECTED_CATEGORY_IDS',
|
|
||||||
}),
|
}),
|
||||||
changeFilterBubble(filter) {
|
changeFilterBubble(filter) {
|
||||||
if (this.hashtag) {
|
if (this.hashtag) {
|
||||||
@ -201,7 +194,11 @@ export default {
|
|||||||
},
|
},
|
||||||
variables() {
|
variables() {
|
||||||
return {
|
return {
|
||||||
filter: this.filter,
|
filter: {
|
||||||
|
...this.usersFollowedFilter,
|
||||||
|
...this.categoriesFilter,
|
||||||
|
...this.filter,
|
||||||
|
},
|
||||||
first: this.pageSize,
|
first: this.pageSize,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
orderBy: this.sorting,
|
orderBy: this.sorting,
|
||||||
|
|||||||
@ -28,7 +28,7 @@ export const mutations = {
|
|||||||
state.categoriesFilter = filter || null
|
state.categoriesFilter = filter || null
|
||||||
},
|
},
|
||||||
SET_SELECTED_CATEGORY_IDS(state, categoryId) {
|
SET_SELECTED_CATEGORY_IDS(state, categoryId) {
|
||||||
if (!categoryId.length) {
|
if (!categoryId) {
|
||||||
state.selectedCategoryIds = []
|
state.selectedCategoryIds = []
|
||||||
} else {
|
} else {
|
||||||
const index = state.selectedCategoryIds.indexOf(categoryId)
|
const index = state.selectedCategoryIds.indexOf(categoryId)
|
||||||
@ -68,7 +68,7 @@ export const actions = {
|
|||||||
const {
|
const {
|
||||||
data: { Post },
|
data: { Post },
|
||||||
} = await client.query({
|
} = await client.query({
|
||||||
query: gql(`
|
query: gql`
|
||||||
query Post($filter: _PostFilter, $first: Int, $offset: Int) {
|
query Post($filter: _PostFilter, $first: Int, $offset: Int) {
|
||||||
Post(filter: $filter, first: $first, offset: $offset) {
|
Post(filter: $filter, first: $first, offset: $offset) {
|
||||||
id
|
id
|
||||||
@ -107,7 +107,7 @@ export const actions = {
|
|||||||
}
|
}
|
||||||
shoutedCount
|
shoutedCount
|
||||||
}
|
}
|
||||||
}`),
|
}`,
|
||||||
variables: {
|
variables: {
|
||||||
filter,
|
filter,
|
||||||
first: 12,
|
first: 12,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user