partially working, index page does not update when route is changed

This commit is contained in:
Moriz Wahl 2020-02-11 09:27:41 +01:00
parent 16ad565ec8
commit 014be6e7f8
8 changed files with 110 additions and 21 deletions

View File

@ -43,6 +43,16 @@ export default {
`
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
AND NOT (resource.deleted = true OR resource.disabled = true)
RETURN resource {.*, __typename: labels(resource)[0]}
LIMIT $limit
`
const session = context.driver.session()
const searchResultPromise = session.readTransaction(async transaction => {
const postTransactionResponse = transaction.run(postCypher, {
@ -55,14 +65,25 @@ export default {
limit,
thisUserId,
})
return Promise.all([postTransactionResponse, userTransactionResponse])
const tagTransactionResponse = transaction.run(tagCypher, {
query: myQuery,
limit,
})
return Promise.all([
postTransactionResponse,
userTransactionResponse,
tagTransactionResponse,
])
})
try {
const [postResults, userResults] = await searchResultPromise
const [postResults, userResults, tagResults] = await searchResultPromise
log(postResults)
log(userResults)
return [...postResults.records, ...userResults.records].map(r => r.get('resource'))
log(tagResults)
return [...postResults.records, ...userResults.records, ...tagResults.records].map(r =>
r.get('resource'),
)
} finally {
session.close()
}

View File

@ -1,4 +1,4 @@
union SearchResult = Post | User
union SearchResult = Post | User | Tag
type Query {
findResources(query: String!, limit: Int = 5): [SearchResult]!

View File

@ -1,5 +1,5 @@
<template>
<ds-tag>
<ds-tag class="hc-hashtag">
<nuxt-link :to="hashtagUrl">#{{ id }}</nuxt-link>
</ds-tag>
</template>

View File

@ -6,18 +6,18 @@
</ds-flex>
</template>
<script>
export default {
name: 'SearchTag',
props: {
option: { type: Object, required: true },
},
}
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;
}
.search-tag {
width: 100%;
}
.search-tag-label {
color: $text-color-primary;
}
</style>

View File

@ -35,6 +35,12 @@
>
<search-post :option="option" />
</p>
<p
v-if="option.__typename === 'Tag'"
:class="{ 'option-with-heading': isFirstOfType(option) }"
>
<hc-hashtag :id="option.id" />
</p>
</template>
</ds-select>
<base-button v-if="isActive" icon="close" circle ghost size="small" @click="clear" />
@ -45,6 +51,7 @@
import { isEmpty } from 'lodash'
import SearchHeading from '~/components/generic/SearchHeading/SearchHeading.vue'
import SearchPost from '~/components/generic/SearchPost/SearchPost.vue'
import HcHashtag from '~/components/Hashtag/Hashtag.vue'
import UserTeaser from '~/components/UserTeaser/UserTeaser.vue'
export default {
@ -52,6 +59,7 @@ export default {
components: {
SearchHeading,
SearchPost,
HcHashtag,
UserTeaser,
},
props: {
@ -77,6 +85,16 @@ 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 (
@ -138,12 +156,20 @@ export default {
isPost(item) {
return item.__typename === 'Post'
},
isTag(item) {
return item.__typename === 'Tag'
},
goToResource(item) {
this.$nextTick(() => {
this.$router.push({
name: this.isPost(item) ? 'post-id-slug' : 'profile-id-slug',
params: { id: item.id, slug: item.slug },
})
if (!this.isTag(item)) {
this.$router.push({
name: this.isPost(item) ? 'post-id-slug' : 'profile-id-slug',
params: { id: item.id, slug: item.slug },
})
} else {
console.log('HIT¡')
this.$router.push('?hashtag=' + item.id)
}
})
},
},

View File

@ -19,6 +19,9 @@ export const findResourcesQuery = gql`
... on User {
...user
}
... on Tag {
id
}
}
}
`

View File

@ -558,6 +558,35 @@
"message": "Bist Du sicher, dass Du den Kommentar von „<b>{name}</b>“ melden möchtest?",
"title": "Kommentar melden",
"type": "Kommentar"
"content": {
"unavailable-placeholder": "… dieser Kommentar ist nicht mehr verfügbar"
},
"menu": {
"edit": "Kommentar bearbeiten",
"delete": "Kommentar löschen"
},
"show": {
"more": "mehr anzeigen",
"less": "weniger anzeigen"
},
"edited": "bearbeitet"
},
"followButton": {
"follow": "Folgen",
"following": "Folge Ich"
},
"shoutButton": {
"shouted": "empfohlen"
},
"search": {
"placeholder": "Suchen",
"hint": "Wonach suchst Du?",
"failed": "Nichts gefunden",
"heading": {
"Post": "Beiträge",
"User": "Benutzer",
"Tag": "Hashtags"
}
},
"contribution": {
"error": "Du hast den Beitrag bereits gemeldet!",

View File

@ -549,6 +549,16 @@
"message": "Do you really want to release the user \"<b>{name}</b>\"?",
"title": "Release User",
"type": "User"
"empty": "Sorry, you don't have any notifications at the moment."
},
"search": {
"placeholder": "Search",
"hint": "What are you searching for?",
"failed": "Nothing found",
"heading": {
"Post": "Posts",
"User": "Users",
"Tag": "Hashtags"
}
},
"report": {