aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-01-04 13:35:25 +0100
committerArmand Philippot <git@armandphilippot.com>2022-01-04 13:35:25 +0100
commitd53d375d09dd86a85ffb249de1c0cc7c3b3438bc (patch)
tree827e02f739a542e674e5d447f46ee97096f02cd7 /src
parentab5e5f4bdf40b5bc1ccf82dc1b4aca94d5171ec3 (diff)
refactor: avoid useless assignement before return statement
Diffstat (limited to 'src')
-rw-r--r--src/pages/blog/index.tsx15
-rw-r--r--src/pages/recherche/index.tsx17
-rw-r--r--src/services/graphql/api.ts7
-rw-r--r--src/services/graphql/queries.ts17
-rw-r--r--src/utils/helpers/format.ts8
-rw-r--r--src/utils/hooks/useHeadingsTree.tsx7
6 files changed, 24 insertions, 47 deletions
diff --git a/src/pages/blog/index.tsx b/src/pages/blog/index.tsx
index a638bd4..095af72 100644
--- a/src/pages/blog/index.tsx
+++ b/src/pages/blog/index.tsx
@@ -16,15 +16,12 @@ const Blog: NextPageWithLayout<BlogPageProps> = ({ fallback }) => {
const getKey = (pageIndex: number, previousData: PostsListData) => {
if (previousData && !previousData.posts) return null;
- const args =
- pageIndex === 0
- ? { first: config.postsPerPage }
- : {
- first: config.postsPerPage,
- after: previousData.pageInfo.endCursor,
- };
-
- return args;
+ return pageIndex === 0
+ ? { first: config.postsPerPage }
+ : {
+ first: config.postsPerPage,
+ after: previousData.pageInfo.endCursor,
+ };
};
const { data, error, size, setSize } = useSWRInfinite(
diff --git a/src/pages/recherche/index.tsx b/src/pages/recherche/index.tsx
index b39d3f9..c1ea0d3 100644
--- a/src/pages/recherche/index.tsx
+++ b/src/pages/recherche/index.tsx
@@ -28,16 +28,13 @@ const Search: NextPageWithLayout = () => {
const getKey = (pageIndex: number, previousData: PostsListData) => {
if (previousData && !previousData.posts) return null;
- const args =
- pageIndex === 0
- ? { first: config.postsPerPage, searchQuery: query }
- : {
- first: config.postsPerPage,
- after: previousData.pageInfo.endCursor,
- searchQuery: query,
- };
-
- return args;
+ return pageIndex === 0
+ ? { first: config.postsPerPage, searchQuery: query }
+ : {
+ first: config.postsPerPage,
+ after: previousData.pageInfo.endCursor,
+ searchQuery: query,
+ };
};
const { data, error, size, setSize } = useSWRInfinite(
diff --git a/src/services/graphql/api.ts b/src/services/graphql/api.ts
index de8024f..33cc89a 100644
--- a/src/services/graphql/api.ts
+++ b/src/services/graphql/api.ts
@@ -6,9 +6,7 @@ export const getGraphQLClient = (): GraphQLClient => {
if (!apiUrl) throw new Error('API URL not defined.');
- const graphQLClient = new GraphQLClient(apiUrl);
-
- return graphQLClient;
+ return new GraphQLClient(apiUrl);
};
export const fetchApi = async <T extends RequestType>(
@@ -18,8 +16,7 @@ export const fetchApi = async <T extends RequestType>(
const client = getGraphQLClient();
try {
- const response = await client.request(query, variables);
- return response;
+ return await client.request(query, variables);
} catch (error) {
console.error(error, undefined, 2);
process.exit(1);
diff --git a/src/services/graphql/queries.ts b/src/services/graphql/queries.ts
index 1cbb616..afc9f69 100644
--- a/src/services/graphql/queries.ts
+++ b/src/services/graphql/queries.ts
@@ -100,17 +100,13 @@ export const getPublishedPosts = async ({
const variables = { first, after, searchQuery };
const response = await fetchApi<RawPostsList>(query, variables);
const formattedPosts = response.posts.edges.map((post) => {
- const formattedPost = getFormattedPostPreview(post.node);
-
- return formattedPost;
+ return getFormattedPostPreview(post.node);
});
- const postsList = {
+ return {
posts: formattedPosts,
pageInfo: response.posts.pageInfo,
};
-
- return postsList;
};
export const getAllPostsSlug = async (): Promise<Slug[]> => {
@@ -226,9 +222,8 @@ export const getPostBySlug = async (slug: string): Promise<Article> => {
`;
const variables = { slug };
const response = await fetchApi<PostBy>(query, variables);
- const post = getFormattedPost(response.postBy);
- return post;
+ return getFormattedPost(response.postBy);
};
//==============================================================================
@@ -328,9 +323,8 @@ export const getSubjectBySlug = async (slug: string): Promise<Subject> => {
`;
const variables = { slug };
const response = await fetchApi<SubjectBy>(query, variables);
- const subject = getFormattedSubject(response.subjectBy);
- return subject;
+ return getFormattedSubject(response.subjectBy);
};
export const getAllSubjectsSlug = async (): Promise<Slug[]> => {
@@ -437,9 +431,8 @@ export const getThematicBySlug = async (slug: string): Promise<Thematic> => {
`;
const variables = { slug };
const response = await fetchApi<ThematicBy>(query, variables);
- const thematic = getFormattedThematic(response.thematicBy);
- return thematic;
+ return getFormattedThematic(response.thematicBy);
};
export const getAllThematicsSlug = async (): Promise<Slug[]> => {
diff --git a/src/utils/helpers/format.ts b/src/utils/helpers/format.ts
index 94aa2e7..44536dd 100644
--- a/src/utils/helpers/format.ts
+++ b/src/utils/helpers/format.ts
@@ -61,15 +61,11 @@ export const getFormattedPostPreview = (rawPost: RawArticlePreview) => {
export const getFormattedPostsList = (
rawPosts: RawArticlePreview[]
): ArticlePreview[] => {
- const formattedPosts = rawPosts
+ return rawPosts
.filter((post) => Object.getOwnPropertyNames(post).length > 0)
.map((post) => {
- const formattedPost = getFormattedPostPreview(post);
-
- return formattedPost;
+ return getFormattedPostPreview(post);
});
-
- return formattedPosts;
};
/**
diff --git a/src/utils/hooks/useHeadingsTree.tsx b/src/utils/hooks/useHeadingsTree.tsx
index 94d3b4b..745ba23 100644
--- a/src/utils/hooks/useHeadingsTree.tsx
+++ b/src/utils/hooks/useHeadingsTree.tsx
@@ -8,9 +8,7 @@ const useHeadingsTree = (wrapper: string) => {
const getElementDepth = useCallback(
(el: HTMLHeadingElement) => {
- const elDepth = depths.findIndex((depth) => depth === el.localName);
-
- return elDepth;
+ return depths.findIndex((depth) => depth === el.localName);
},
[depths]
);
@@ -73,9 +71,8 @@ const useHeadingsTree = (wrapper: string) => {
const getHeadingsList = useCallback(
(headings: NodeListOf<HTMLHeadingElement>): Heading[] => {
const formattedHeadings = formatHeadings(headings);
- const headingsList = buildTree(formattedHeadings);
- return headingsList;
+ return buildTree(formattedHeadings);
},
[formatHeadings, buildTree]
);