From 125019efc8a246f14f41c30a62858cd20965d1da Mon Sep 17 00:00:00 2001 From: lutangar Date: Tue, 28 Nov 2023 14:51:32 +0100 Subject: [PATCH] fix(ux): fix loader not showing up --- .../src/components/ErrorComponent.tsx | 21 ++++++ apps/frontend/src/components/Loader.tsx | 27 ++++++- apps/frontend/src/pages/ErrorPage.tsx | 18 ++--- apps/frontend/src/pages/ProjectPage.tsx | 41 ++++++++--- apps/frontend/src/pages/ProjectsPage.tsx | 70 +++++++++---------- 5 files changed, 120 insertions(+), 57 deletions(-) create mode 100644 apps/frontend/src/components/ErrorComponent.tsx diff --git a/apps/frontend/src/components/ErrorComponent.tsx b/apps/frontend/src/components/ErrorComponent.tsx new file mode 100644 index 00000000..23593287 --- /dev/null +++ b/apps/frontend/src/components/ErrorComponent.tsx @@ -0,0 +1,21 @@ +import React from 'react'; +import { FetchBaseQueryError } from '@reduxjs/toolkit/query'; +import { SerializedError } from '@reduxjs/toolkit'; + +export const ErrorComponent = ({ error }: { error: FetchBaseQueryError | SerializedError | Error }) => { + return ( + <> + {/* +// @ts-ignore */} +

Oops! {error.status}

+ {/* +// @ts-ignore */} +

{error.statusText}

+

+ {/* +// @ts-ignore */} + {error.data.message} +

+ + ); +}; diff --git a/apps/frontend/src/components/Loader.tsx b/apps/frontend/src/components/Loader.tsx index 5124f683..1298f564 100644 --- a/apps/frontend/src/components/Loader.tsx +++ b/apps/frontend/src/components/Loader.tsx @@ -1,7 +1,8 @@ import React, { SVGProps } from 'react'; import styled from 'styled-components'; -export const Loader = styled((props: SVGProps & { dark?: boolean }) => ( +export type LoaderProps = { dark?: boolean; fullscreen?: boolean }; +export const SVGLoader = styled(({ dark, fullscreen, ...props }: SVGProps & LoaderProps) => ( & { dark?: boolean } color: rgb(${({ dark }) => (dark ? '0 0 0' : '255 255 255')} / 1); - width: 1.25rem; - height: 1.25rem; + width: ${({ fullscreen }) => (fullscreen ? '2.5rem' : ' 1.25rem')}; + height: ${({ fullscreen }) => (fullscreen ? '2.5rem' : ' 1.25rem')}; margin-right: 0.75rem; margin-left: -0.25rem; @@ -32,3 +33,23 @@ export const Loader = styled((props: SVGProps & { dark?: boolean opacity: 0.75; } `; + +const FullscreenContainer = styled.div` + display: flex; + align-items: center; + justify-content: center; + width: 100%; + height: 100%; +`; + +export const Loader = (props: LoaderProps) => { + if (props.fullscreen) { + return ( + + + + ); + } + + return ; +}; diff --git a/apps/frontend/src/pages/ErrorPage.tsx b/apps/frontend/src/pages/ErrorPage.tsx index 6311cd37..697a0e6a 100644 --- a/apps/frontend/src/pages/ErrorPage.tsx +++ b/apps/frontend/src/pages/ErrorPage.tsx @@ -1,5 +1,6 @@ import React from 'react'; import { isRouteErrorResponse, useRouteError } from 'react-router-dom'; +import { ErrorComponent } from '../components/ErrorComponent'; export const ErrorPage = () => { const error = useRouteError(); @@ -7,13 +8,7 @@ export const ErrorPage = () => { if (isRouteErrorResponse(error)) { return (
-

Oops! {error.status}

-

{error.statusText}

- {error.data?.message && ( -

- {error.data.message} -

- )} +
); } else if (error instanceof Error) { @@ -27,6 +22,13 @@ export const ErrorPage = () => { ); } else { - return <>?; + return ( +
+

+

Oops!

+ This definitely shouldn't happend +

+
+ ); } }; diff --git a/apps/frontend/src/pages/ProjectPage.tsx b/apps/frontend/src/pages/ProjectPage.tsx index 5719b561..24b3e025 100644 --- a/apps/frontend/src/pages/ProjectPage.tsx +++ b/apps/frontend/src/pages/ProjectPage.tsx @@ -1,12 +1,20 @@ import React from 'react'; import { useParams } from 'react-router-dom'; import { useSelector } from 'react-redux'; +import styled from 'styled-components'; import { skipToken } from '@reduxjs/toolkit/query/react'; import { Project } from '@datatlas/models'; import KeplerMap from '../components/KeplerMap'; import { getUser, useGetProjectQuery } from '../store/api'; import { Loader } from '../components/Loader'; import { selectCurrentUserId } from '../store/selectors'; +import { ErrorComponent } from '../components/ErrorComponent'; + +const MapContainer = styled.div` + position: relative; + width: 100%; + height: 100%; +`; export const ProjectPage = () => { const { id } = useParams(); @@ -15,22 +23,39 @@ export const ProjectPage = () => { } const currentUserId = useSelector(selectCurrentUserId); - const { data: user, isError: isUserError, error: userError } = getUser.useQuery(currentUserId ?? skipToken); + const { + isLoading: isUserLoading, + isFetching: isUserFetching, + data: user, + isError: isUserError, + error: userError, + } = getUser.useQuery(currentUserId ?? skipToken); if (isUserError) { console.error(userError); } - const { isLoading, isFetching, isError, error, data: project } = useGetProjectQuery(+id ?? skipToken); - if (isLoading || isFetching) { - return ; + const { + isLoading: isProjectLoading, + isFetching: isProjectFetching, + isError, + error, + data: project, + } = useGetProjectQuery(+id ?? skipToken); + const isLoading = isUserLoading || isUserFetching || isProjectLoading || isProjectFetching; + + if (isLoading) { + return ( + + + + ); } else if (isError) { - console.error(error); - return
{error.toString()}
; + return ; } return ( -
+ -
+ ); }; diff --git a/apps/frontend/src/pages/ProjectsPage.tsx b/apps/frontend/src/pages/ProjectsPage.tsx index 75fafe3d..fd938f25 100644 --- a/apps/frontend/src/pages/ProjectsPage.tsx +++ b/apps/frontend/src/pages/ProjectsPage.tsx @@ -51,44 +51,38 @@ export const ProjectsPage = () => { - {myProjects.length > 0 && ( - <> - -

- -

-
- - - )} - {communityProjects.length > 0 && ( - <> - -

- -

-

- Vous trouverez ici les projets partagés par l’ensemble de la communauté Datatlas, n’hésitez pas à - les découvrir et à vous en inspirer ! -

-
- - - )} + +

+ +

+
+ + +

+ +

+
+ <> +

+ Vous trouverez ici les projets partagés par l’ensemble de la communauté Datatlas, n’hésitez pas à les + découvrir et à vous en inspirer ! +

+ +