Skip to content

Commit

Permalink
feat: create query getter for next queries & use it in the NQ request
Browse files Browse the repository at this point in the history
  • Loading branch information
annacv committed Mar 4, 2024
1 parent fa62706 commit 6c4292d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createRelatedTagsQueryGetter } from '../../../../store/utils/query.utils';
import { NextQueriesXStoreModule } from '../types';

/**
* Default implementation for the next-queries query getter.
*
* @param state - Current {@link https://vuex.vuejs.org/guide/state.html | state} of the related
* tags' module.
*
* @returns The query with the selected related tags concatenated.
*
* @public
*/
export const query: NextQueriesXStoreModule['getters']['query'] = createRelatedTagsQueryGetter({
getRelatedTags: state => state.relatedTags
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import { NextQueriesXStoreModule } from '../types';
*
* @param state - Current {@link https://vuex.vuejs.org/guide/state.html | state} of the next
* queries module.
* @param getters - Current {@link https://vuex.vuejs.org/guide/getters.html | getters} of the
* search module.
*
* @returns The next queries request to fetch data from the API.
*
* @public
*/
export const request: NextQueriesXStoreModule['getters']['request'] = ({
query,
config,
params
}) => {
return query.trim()
export const request: NextQueriesXStoreModule['getters']['request'] = (
{ config, params },
{ query }
) => {
return query
? {
query,
rows: config.maxItemsToRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { setUrlParams } from './actions/set-url-params.action';
import { fetchNextQueryPreview } from './actions/fetch-next-query-preview.action';
import { fetchAndSaveNextQueryPreview } from './actions/fetch-and-save-next-query-preview.action';
import { nextQueries } from './getters/next-queries.getter';
import { query } from './getters/next-queries-query.getter';
import { request } from './getters/request.getter';
import { NextQueriesXStoreModule } from './types';

Expand All @@ -37,7 +38,8 @@ export const nextQueriesXStoreModule: NextQueriesXStoreModule = {
}),
getters: {
request,
nextQueries
nextQueries,
query
},
mutations: {
setQuery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export interface NextQueriesGetters {
request: NextQueriesRequest | null;
/** List of next queries that have not been searched before. */
nextQueries: NextQuery[];
/** The combination of the query and the selected related tags. */
query: string;
}

/**
Expand Down

0 comments on commit 6c4292d

Please sign in to comment.