From efdd7638d4ac631f55c225625e5717fc93587c59 Mon Sep 17 00:00:00 2001 From: John Hunter Date: Wed, 27 Sep 2023 17:30:04 +0100 Subject: [PATCH] Fix typing and update tests --- src/App/components/Loading/Loading.test.tsx | 4 ++-- src/App/components/Loading/Loading.tsx | 6 +++--- src/App/components/Post/useData.ts | 4 ++-- src/App/components/Posts/Posts.tsx | 3 ++- src/App/components/Posts/useData.ts | 4 ++-- src/api/api.ts | 10 ++++++---- src/types.ts | 5 +---- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/App/components/Loading/Loading.test.tsx b/src/App/components/Loading/Loading.test.tsx index 61f55db..4807b58 100644 --- a/src/App/components/Loading/Loading.test.tsx +++ b/src/App/components/Loading/Loading.test.tsx @@ -19,9 +19,9 @@ describe('Loading', () => { }); test('Displays given error', () => { - const message = 'given error'; + const statusText = 'given error'; render( - + {children} , ); diff --git a/src/App/components/Loading/Loading.tsx b/src/App/components/Loading/Loading.tsx index 82e3169..b3533aa 100644 --- a/src/App/components/Loading/Loading.tsx +++ b/src/App/components/Loading/Loading.tsx @@ -1,10 +1,10 @@ import { FC, ReactNode } from 'react'; import Info from '../Info'; -import type { Status, Error } from '@/types'; +import type { Status, HttpError } from '@/types'; interface LoadingProps { status: Status; - error: Error | null; + error: HttpError | null; children: ReactNode; } @@ -19,7 +19,7 @@ const Loading: FC = ({ status, error, children }) => { default: { return ( - Error: {error?.message || 'an unknown error occurred'} + Error: {error?.statusText || 'an unknown error occurred'} ); } diff --git a/src/App/components/Post/useData.ts b/src/App/components/Post/useData.ts index c162482..4a3faeb 100644 --- a/src/App/components/Post/useData.ts +++ b/src/App/components/Post/useData.ts @@ -1,12 +1,12 @@ import { useQuery } from '@tanstack/react-query'; import { getJson } from '@/api'; -import type { PostData } from '@/types'; +import type { PostData, HttpError } from '@/types'; const fetchPostById = async (id: number) => await getJson(`posts/${id}`); const useData = (postId: number) => - useQuery(['post', postId], () => fetchPostById(postId), { + useQuery(['post', postId], () => fetchPostById(postId), { enabled: !!postId, }); diff --git a/src/App/components/Posts/Posts.tsx b/src/App/components/Posts/Posts.tsx index 4271745..d1174b3 100644 --- a/src/App/components/Posts/Posts.tsx +++ b/src/App/components/Posts/Posts.tsx @@ -5,6 +5,7 @@ import css from './Posts.module.css'; import Info from '../Info'; import Loading from '../Loading'; import useData from './useData'; +import { PostData } from '@/types'; interface PostsProps { setPostId: (id: number | null) => void; @@ -25,7 +26,7 @@ const Posts: FC = ({ setPostId }) => { Background Updating