Skip to content

Commit

Permalink
Merge branch 'main' of github.com:wepublish/hauptstadt
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-scheurer committed May 17, 2024
2 parents c38c254 + 8a20577 commit 0c16a4c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
7 changes: 3 additions & 4 deletions pages/p/_PageSlug.vue
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ export default Vue.extend({
if (this.isSearchPage) {
const searchQuery: string = this.$route.query.query as string
articles = await new PhraseService({ vue: this }).searchPhrase({
searchQuery
searchQuery,
take: this.teaserCount,
skip
})
// Sort articles by publication date, newest first
if (articles) {
Expand Down Expand Up @@ -173,9 +175,6 @@ export default Vue.extend({
if (this.isArchivePage && totalPages > 1) {
totalPages -= 1
}
if (this.isSearchPage) {
totalPages = 1
}
this.pagination!.update({ totalPages })
return articles
},
Expand Down
38 changes: 19 additions & 19 deletions sdk/wep/services/PhraseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Article from '~/sdk/wep/models/wepPublication/article/Article'
import Articles from '../models/wepPublication/article/Articles'
import PageInfo from '../models/wepPublication/page/PageInfo'
import ReducedArticle from '../models/wepPublication/article/ReducedArticle'
import { ArticleSort, SortOrder } from '../interfacesAndTypes/WePublish'

export default class PhraseService extends Service {
constructor({vue}: {vue: Vue}) {
Expand All @@ -15,7 +16,7 @@ export default class PhraseService extends Service {
* Fetch articles and pages by search term from wep api.
* @param searchQuery
*/
async searchPhrase({searchQuery}: {searchQuery: String}): Promise<Articles | false> {
async searchPhrase({searchQuery, take, skip, articleSort, order}: {searchQuery: String, take?: number, skip?: number, articleSort?: ArticleSort, order?: SortOrder}): Promise<Articles | false> {
if (!searchQuery) {
throw new Error('No query provided in searchPhrase() method within PhraseService class.')
}
Expand All @@ -24,40 +25,39 @@ export default class PhraseService extends Service {
})
try {
const query = gql`
query Phrase($query: String!) {
phrase(query: $query) {
query Phrase($query: String!, $take: Int, $skip: Int, $articleSort: ArticleSort, $order: SortOrder) {
phrase(query: $query, take: $take, skip: $skip, articleSort: $articleSort, order: $order) {
articles {
...reducedArticle
nodes {
...reducedArticle
}
pageInfo {
...pageInfo
}
totalCount
}
}
}
${ReducedArticle.reducedArticleFragment}
${PageInfo.pageInfoFragment}
`

const response = await this.$apollo.query({
query,
variables: {
query: searchQuery
query: searchQuery,
take,
skip,
articleSort,
order
},
errorPolicy: 'all'
})
if (response.data.phrase.articles.length === 0) {
if (response.data.phrase.articles.totalCount === 0) {
return false
}

const articles = new Articles(
{
nodes: response.data.phrase.articles as Article[],
pageInfo: new PageInfo({
startCursor: '',
endCursor: '',
hasNextPage: false,
hasPreviousPage: false
}),
totalCount: response.data.phrase.articles.length
},
true
)
const articles = new Articles(response.data.phrase.articles, true)
this.loadingFinish()
return articles
} catch (e) {
Expand Down

0 comments on commit 0c16a4c

Please sign in to comment.