summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/helpers/pages.ts18
-rw-r--r--src/utils/hooks/use-article.tsx6
-rw-r--r--src/utils/hooks/use-comments.tsx6
-rw-r--r--src/utils/hooks/use-pagination.tsx7
4 files changed, 25 insertions, 12 deletions
diff --git a/src/utils/helpers/pages.ts b/src/utils/helpers/pages.ts
index 773d454..eb4453b 100644
--- a/src/utils/helpers/pages.ts
+++ b/src/utils/helpers/pages.ts
@@ -1,8 +1,8 @@
import { type Post } from '@components/organisms/layout/posts-list';
import { type LinksListItems } from '@components/organisms/widgets/links-list-widget';
-import { type EdgesResponse } from '@services/graphql/api';
import { getArticleFromRawData } from '@services/graphql/articles';
import { type Article, type PageLink } from '@ts/types/app';
+import { EdgesResponse } from '@ts/types/graphql/queries';
import {
type RawArticle,
type RawThematicPreview,
@@ -36,6 +36,22 @@ export const getPageLinkFromRawData = (
};
/**
+ * Method to sort PageLink objects by name.
+ *
+ * @param {PageLink} a - A PageLink object.
+ * @param {PageLink} b - Another PageLink object.
+ * @returns {1 | -1 | 0}
+ */
+export const sortPageLinksByName = (a: PageLink, b: PageLink) => {
+ const nameA = a.name.toUpperCase();
+ const nameB = b.name.toUpperCase();
+
+ if (nameA < nameB) return -1;
+ if (nameA > nameB) return 1;
+ return 0;
+};
+
+/**
* Convert page link data to an array of links items.
*
* @param {PageLink[]} links - An array of page links.
diff --git a/src/utils/hooks/use-article.tsx b/src/utils/hooks/use-article.tsx
index 6281a54..e658407 100644
--- a/src/utils/hooks/use-article.tsx
+++ b/src/utils/hooks/use-article.tsx
@@ -1,4 +1,4 @@
-import { fetchAPI, getAPIUrl } from '@services/graphql/api';
+import { fetchAPI } from '@services/graphql/api';
import { getArticleFromRawData } from '@services/graphql/articles';
import { articleBySlugQuery } from '@services/graphql/articles.query';
import { Article } from '@ts/types/app';
@@ -22,9 +22,7 @@ const useArticle = ({
fallback,
}: UseArticleConfig): Article | undefined => {
const { data } = useSWR(
- slug
- ? { api: getAPIUrl(), query: articleBySlugQuery, variables: { slug } }
- : null,
+ slug ? { query: articleBySlugQuery, variables: { slug } } : null,
fetchAPI<RawArticle, typeof articleBySlugQuery>
);
diff --git a/src/utils/hooks/use-comments.tsx b/src/utils/hooks/use-comments.tsx
index 9076888..cb0848b 100644
--- a/src/utils/hooks/use-comments.tsx
+++ b/src/utils/hooks/use-comments.tsx
@@ -1,4 +1,4 @@
-import { fetchAPI, getAPIUrl } from '@services/graphql/api';
+import { fetchAPI } from '@services/graphql/api';
import {
buildCommentsTree,
getCommentFromRawData,
@@ -24,9 +24,7 @@ const useComments = ({
fallback,
}: UseCommentsConfig): Comment[] | undefined => {
const { data } = useSWR(
- contentId
- ? { api: getAPIUrl(), query: commentsQuery, variables: { contentId } }
- : null,
+ contentId ? { query: commentsQuery, variables: { contentId } } : null,
fetchAPI<RawComment, typeof commentsQuery>
);
diff --git a/src/utils/hooks/use-pagination.tsx b/src/utils/hooks/use-pagination.tsx
index a80a539..f17b6ff 100644
--- a/src/utils/hooks/use-pagination.tsx
+++ b/src/utils/hooks/use-pagination.tsx
@@ -1,4 +1,5 @@
-import { type EdgesResponse, type EdgesVars } from '@services/graphql/api';
+import { GraphQLEdgesInput } from '@ts/types/graphql/generics';
+import { EdgesResponse, Search } from '@ts/types/graphql/queries';
import useSWRInfinite, { SWRInfiniteKeyLoader } from 'swr/infinite';
export type UsePaginationProps<T> = {
@@ -9,7 +10,7 @@ export type UsePaginationProps<T> = {
/**
* A function to fetch more data.
*/
- fetcher: (props: EdgesVars) => Promise<EdgesResponse<T>>;
+ fetcher: (props: GraphQLEdgesInput & Search) => Promise<EdgesResponse<T>>;
/**
* The number of results per page.
*/
@@ -74,7 +75,7 @@ const usePagination = <T extends object>({
const getKey: SWRInfiniteKeyLoader = (
pageIndex: number,
previousData: EdgesResponse<T>
- ): EdgesVars | null => {
+ ): (GraphQLEdgesInput & Search) | null => {
// Reached the end.
if (previousData && !previousData.edges.length) return null;