diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-05-15 16:36:58 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-05-15 16:36:58 +0200 |
| commit | 235fe67d770f83131c9ec10b99012319440db690 (patch) | |
| tree | 3b96e2c8a5877fe15a9cfa6bff46130fa7a04a65 /src/services | |
| parent | fe2252ced2bb895e26179640553b5a6c02957d54 (diff) | |
chore: add Search page
Diffstat (limited to 'src/services')
| -rw-r--r-- | src/services/graphql/api.ts | 15 | ||||
| -rw-r--r-- | src/services/graphql/articles.query.ts | 4 | ||||
| -rw-r--r-- | src/services/graphql/articles.ts | 3 | ||||
| -rw-r--r-- | src/services/graphql/contact.ts | 4 |
4 files changed, 17 insertions, 9 deletions
diff --git a/src/services/graphql/api.ts b/src/services/graphql/api.ts index 5bed9f9..171ab23 100644 --- a/src/services/graphql/api.ts +++ b/src/services/graphql/api.ts @@ -48,7 +48,7 @@ export type ArticlesResponse<T> = { }; export type CommentsResponse<T> = { - comments: T[]; + comments: T; }; export type SendMailResponse<T> = { @@ -147,7 +147,14 @@ export type ByContentIdVar = { contentId: number; }; -export type sendMailVars = { +export type SearchVar = { + /** + * A search term. + */ + search?: string; +}; + +export type SendMailVars = { body: string; clientMutationId: string; replyTo: string; @@ -160,14 +167,14 @@ export type VariablesMap = { [articlesQuery]: EdgesVars; [articlesSlugQuery]: EdgesVars; [commentsQuery]: ByContentIdVar; - [sendMailMutation]: sendMailVars; + [sendMailMutation]: SendMailVars; [thematicBySlugQuery]: BySlugVar; [thematicsListQuery]: EdgesVars; [thematicsSlugQuery]: EdgesVars; [topicBySlugQuery]: BySlugVar; [topicsListQuery]: EdgesVars; [topicsSlugQuery]: EdgesVars; - [totalArticlesQuery]: null; + [totalArticlesQuery]: SearchVar; [totalThematicsQuery]: null; [totalTopicsQuery]: null; }; diff --git a/src/services/graphql/articles.query.ts b/src/services/graphql/articles.query.ts index e62835d..d65bc9e 100644 --- a/src/services/graphql/articles.query.ts +++ b/src/services/graphql/articles.query.ts @@ -166,8 +166,8 @@ export const articlesSlugQuery = `query ArticlesSlug($first: Int = 10, $after: S /** * Query the total number of articles. */ -export const totalArticlesQuery = `query PostsTotal { - posts { +export const totalArticlesQuery = `query PostsTotal($search: String = "") { + posts(where: {search: $search}) { pageInfo { total } diff --git a/src/services/graphql/articles.ts b/src/services/graphql/articles.ts index 1eb112e..41052c4 100644 --- a/src/services/graphql/articles.ts +++ b/src/services/graphql/articles.ts @@ -21,10 +21,11 @@ import { * * @returns {Promise<number>} - The articles total number. */ -export const getTotalArticles = async (): Promise<number> => { +export const getTotalArticles = async (search?: string): Promise<number> => { const response = await fetchAPI<TotalItems, typeof totalArticlesQuery>({ api: getAPIUrl(), query: totalArticlesQuery, + variables: { search }, }); return response.posts.pageInfo.total; diff --git a/src/services/graphql/contact.ts b/src/services/graphql/contact.ts index fca718f..00c6ca2 100644 --- a/src/services/graphql/contact.ts +++ b/src/services/graphql/contact.ts @@ -1,4 +1,4 @@ -import { fetchAPI, getAPIUrl, sendMailVars } from './api'; +import { fetchAPI, getAPIUrl, SendMailVars } from './api'; import { sendMailMutation } from './contact.mutation'; export type SentEmail = { @@ -15,7 +15,7 @@ export type SentEmail = { * @param {sendMailVars} data - The mail data. * @returns {Promise<SentEmail>} The mutation response. */ -export const sendMail = async (data: sendMailVars): Promise<SentEmail> => { +export const sendMail = async (data: SendMailVars): Promise<SentEmail> => { const response = await fetchAPI<SentEmail, typeof sendMailMutation>({ api: getAPIUrl(), query: sendMailMutation, |
