From a0d00743cbbdb77b27c1a3d5711407ffed5befac Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Sat, 20 Aug 2022 21:39:51 +0200 Subject: refactor(types): move and rename GraphQL types The api file in services was not really readable. So I move the types and I also rewrite a little the fetch function. I also rename most of the type to avoid conflict with preexisting types (like Node) and to keep consistency. --- src/utils/helpers/pages.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/utils/helpers') 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, @@ -35,6 +35,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. * -- cgit v1.2.3