Search for Hashtags works due watching route in pages/index.vue

This commit is contained in:
Moriz Wahl 2020-03-19 14:19:13 +01:00
parent 07fbe92fa8
commit 1c43d5fe6f
6 changed files with 162 additions and 187 deletions

View File

@ -40,6 +40,7 @@ export async function down(next) {
await transaction.rollback()
// eslint-disable-next-line no-console
console.log('rolled back')
throw new Error(error)
} finally {
session.close()
}

View File

@ -20,6 +20,7 @@ export async function up(next) {
await transaction.rollback()
// eslint-disable-next-line no-console
console.log('rolled back')
throw new Error(error)
} finally {
session.close()
}
@ -43,6 +44,7 @@ export async function down(next) {
await transaction.rollback()
// eslint-disable-next-line no-console
console.log('rolled back')
throw new Error(error)
} finally {
session.close()
}

View File

@ -41,18 +41,18 @@ export default {
RETURN resource {.*, __typename: labels(resource)[0]}
LIMIT $limit
`
const myQuery = queryString(query)
const tagCypher = `
CALL db.index.fulltext.queryNodes('tag_fulltext_search', $query)
YIELD node as resource, score
MATCH (resource)
WHERE score >= 0.5
WHERE score >= 0.0
AND NOT (resource.deleted = true OR resource.disabled = true)
RETURN resource {.*, __typename: labels(resource)[0]}
LIMIT $limit
`
const myQuery = queryString(query)
const session = context.driver.session()
const searchResultPromise = session.readTransaction(async transaction => {
const postTransactionResponse = transaction.run(postCypher, {

View File

@ -1,23 +0,0 @@
<template>
<ds-flex class="search-tag">
<ds-flex-item class="search-tag-label">
<ds-text>#{{ option.id }}</ds-text>
</ds-flex-item>
</ds-flex>
</template>
<script>
export default {
name: 'SearchTag',
props: {
option: { type: Object, required: true },
},
}
</script>
<style lang="scss">
.search-tag {
width: 100%;
}
.search-tag-label {
color: $text-color-primary;
}
</style>

View File

@ -85,16 +85,6 @@ export default {
return !isEmpty(this.previousSearchTerm)
},
},
watch: {
$route(to, from) {
console.log('to', to)
console.log('from', from)
// console.log(this.finalFilters)
if (to.query.hashtag) {
this.hashtag = to.query.hashtag
}
},
},
methods: {
isFirstOfType(option) {
return (
@ -167,7 +157,6 @@ export default {
params: { id: item.id, slug: item.slug },
})
} else {
console.log('HIT¡')
this.$router.push('?hashtag=' + item.id)
}
})

View File

@ -64,158 +64,164 @@
</template>
<script>
// import DonationInfo from '~/components/DonationInfo/DonationInfo.vue'
import FilterMenu from '~/components/FilterMenu/FilterMenu.vue'
import HcEmpty from '~/components/Empty/Empty'
import PostTeaser from '~/components/PostTeaser/PostTeaser.vue'
import MasonryGrid from '~/components/MasonryGrid/MasonryGrid.vue'
import MasonryGridItem from '~/components/MasonryGrid/MasonryGridItem.vue'
import { mapGetters, mapMutations } from 'vuex'
import { filterPosts } from '~/graphql/PostQuery.js'
import PostMutations from '~/graphql/PostMutations'
import UpdateQuery from '~/components/utils/UpdateQuery'
// import DonationInfo from '~/components/DonationInfo/DonationInfo.vue'
import FilterMenu from '~/components/FilterMenu/FilterMenu.vue'
import HcEmpty from '~/components/Empty/Empty'
import PostTeaser from '~/components/PostTeaser/PostTeaser.vue'
import MasonryGrid from '~/components/MasonryGrid/MasonryGrid.vue'
import MasonryGridItem from '~/components/MasonryGrid/MasonryGridItem.vue'
import { mapGetters, mapMutations } from 'vuex'
import { filterPosts } from '~/graphql/PostQuery.js'
import PostMutations from '~/graphql/PostMutations'
import UpdateQuery from '~/components/utils/UpdateQuery'
export default {
components: {
// DonationInfo,
FilterMenu,
PostTeaser,
HcEmpty,
MasonryGrid,
MasonryGridItem,
},
data() {
const { hashtag = null } = this.$route.query
return {
posts: [],
hasMore: true,
// Initialize your apollo data
offset: 0,
pageSize: 12,
hashtag,
}
},
computed: {
...mapGetters({
postsFilter: 'posts/filter',
orderOptions: 'posts/orderOptions',
orderBy: 'posts/orderBy',
selectedOrder: 'posts/selectedOrder',
sortingIcon: 'posts/orderIcon',
}),
selected: {
get() {
return this.selectedOrder(this)
},
set({ value }) {
this.offset = 0
this.posts = []
this.selectOrder(value)
},
},
sortingOptions() {
return this.orderOptions(this)
},
finalFilters() {
let filter = this.postsFilter
if (this.hashtag) {
filter = {
...filter,
tags_some: { id: this.hashtag },
}
}
return filter
},
hasResults() {
return this.$apollo.loading || (this.posts && this.posts.length > 0)
},
},
methods: {
...mapMutations({
selectOrder: 'posts/SELECT_ORDER',
}),
clearSearch() {
this.$router.push({ path: '/' })
this.hashtag = null
},
href(post) {
return this.$router.resolve({
name: 'post-id-slug',
params: { id: post.id, slug: post.slug },
}).href
},
showMoreContributions($state) {
const { Post: PostQuery } = this.$apollo.queries
if (!PostQuery) return // seems this can be undefined on subpages
export default {
components: {
// DonationInfo,
FilterMenu,
PostTeaser,
HcEmpty,
MasonryGrid,
MasonryGridItem,
},
data() {
const { hashtag = null } = this.$route.query
console.log(this.$route.query)
return {
posts: [],
hasMore: true,
// Initialize your apollo data
offset: 0,
pageSize: 12,
hashtag,
}
},
computed: {
...mapGetters({
postsFilter: 'posts/filter',
orderOptions: 'posts/orderOptions',
orderBy: 'posts/orderBy',
selectedOrder: 'posts/selectedOrder',
sortingIcon: 'posts/orderIcon',
}),
selected: {
get() {
return this.selectedOrder(this)
},
set({ value }) {
this.offset = 0
this.posts = []
this.selectOrder(value)
},
},
sortingOptions() {
return this.orderOptions(this)
},
finalFilters() {
let filter = this.postsFilter
if (this.hashtag) {
filter = {
...filter,
tags_some: { id: this.hashtag },
}
}
return filter
},
hasResults() {
return this.$apollo.loading || (this.posts && this.posts.length > 0)
},
},
watch: {
'$route.query.hashtag'() {
this.hashtag = this.$route.query.hashtag
},
},
methods: {
...mapMutations({
selectOrder: 'posts/SELECT_ORDER',
}),
clearSearch() {
this.$router.push({ path: '/' })
this.hashtag = null
},
href(post) {
return this.$router.resolve({
name: 'post-id-slug',
params: { id: post.id, slug: post.slug },
}).href
},
showMoreContributions($state) {
const { Post: PostQuery } = this.$apollo.queries
if (!PostQuery) return // seems this can be undefined on subpages
this.offset += this.pageSize
PostQuery.fetchMore({
variables: {
offset: this.offset,
filter: this.finalFilters,
first: this.pageSize,
orderBy: ['pinned_asc', this.orderBy],
},
updateQuery: UpdateQuery(this, { $state, pageKey: 'Post' }),
})
},
deletePost(deletedPost) {
this.posts = this.posts.filter(post => {
return post.id !== deletedPost.id
})
},
resetPostList() {
this.offset = 0
this.posts = []
this.hasMore = true
},
pinPost(post) {
this.$apollo
.mutate({
mutation: PostMutations().pinPost,
variables: { id: post.id },
})
.then(() => {
this.$toast.success(this.$t('post.menu.pinnedSuccessfully'))
this.resetPostList()
this.$apollo.queries.Post.refetch()
})
.catch(error => this.$toast.error(error.message))
},
unpinPost(post) {
this.$apollo
.mutate({
mutation: PostMutations().unpinPost,
variables: { id: post.id },
})
.then(() => {
this.$toast.success(this.$t('post.menu.unpinnedSuccessfully'))
this.resetPostList()
this.$apollo.queries.Post.refetch()
})
.catch(error => this.$toast.error(error.message))
},
},
apollo: {
Post: {
query() {
return filterPosts(this.$i18n)
},
variables() {
return {
filter: this.finalFilters,
first: this.pageSize,
orderBy: ['pinned_asc', this.orderBy],
offset: 0,
}
},
update({ Post }) {
this.posts = Post
},
fetchPolicy: 'cache-and-network',
},
},
}
this.offset += this.pageSize
PostQuery.fetchMore({
variables: {
offset: this.offset,
filter: this.finalFilters,
first: this.pageSize,
orderBy: ['pinned_asc', this.orderBy],
},
updateQuery: UpdateQuery(this, { $state, pageKey: 'Post' }),
})
},
deletePost(deletedPost) {
this.posts = this.posts.filter(post => {
return post.id !== deletedPost.id
})
},
resetPostList() {
this.offset = 0
this.posts = []
this.hasMore = true
},
pinPost(post) {
this.$apollo
.mutate({
mutation: PostMutations().pinPost,
variables: { id: post.id },
})
.then(() => {
this.$toast.success(this.$t('post.menu.pinnedSuccessfully'))
this.resetPostList()
this.$apollo.queries.Post.refetch()
})
.catch(error => this.$toast.error(error.message))
},
unpinPost(post) {
this.$apollo
.mutate({
mutation: PostMutations().unpinPost,
variables: { id: post.id },
})
.then(() => {
this.$toast.success(this.$t('post.menu.unpinnedSuccessfully'))
this.resetPostList()
this.$apollo.queries.Post.refetch()
})
.catch(error => this.$toast.error(error.message))
},
},
apollo: {
Post: {
query() {
return filterPosts(this.$i18n)
},
variables() {
return {
filter: this.finalFilters,
first: this.pageSize,
orderBy: ['pinned_asc', this.orderBy],
offset: 0,
}
},
update({ Post }) {
this.posts = Post
},
fetchPolicy: 'cache-and-network',
},
},
}
</script>
<style lang="scss">