diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-08-20 21:39:51 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-08-20 21:39:51 +0200 |
| commit | a0d00743cbbdb77b27c1a3d5711407ffed5befac (patch) | |
| tree | f4caab160daf6b93c74d60ab93edd265c8edb158 /src/utils/helpers/pages.ts | |
| parent | 46b158bf9d2f7fa9cc253915151e0b53c052a444 (diff) | |
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.
Diffstat (limited to 'src/utils/helpers/pages.ts')
| -rw-r--r-- | src/utils/helpers/pages.ts | 18 |
1 files changed, 17 insertions, 1 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. |
