From 5c0d21578fdca55376933503d02557756fba48da Mon Sep 17 00:00:00 2001 From: Matthew Russell Date: Tue, 1 Mar 2022 17:08:32 -0800 Subject: [PATCH] use page query container for market list page, add styles to center loading and error message --- .../components/page-query-container/index.tsx | 15 +++++-- apps/trading/pages/markets/index.page.tsx | 42 +++++++++---------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/apps/trading/components/page-query-container/index.tsx b/apps/trading/components/page-query-container/index.tsx index afb262034..f1e7bf9ae 100644 --- a/apps/trading/components/page-query-container/index.tsx +++ b/apps/trading/components/page-query-container/index.tsx @@ -1,4 +1,5 @@ -import { QueryHookOptions, useQuery } from '@apollo/client'; +import { OperationVariables, QueryHookOptions, useQuery } from '@apollo/client'; +import classNames from 'classnames'; import { DocumentNode } from 'graphql'; import { ReactNode } from 'react'; @@ -8,19 +9,25 @@ interface PageQueryContainerProps { children: (data: TData) => ReactNode; } -export const PageQueryContainer = ({ +export const PageQueryContainer = ({ query, options, children, }: PageQueryContainerProps) => { const { data, loading, error } = useQuery(query, options); + const splashClasses = classNames( + 'w-full h-full', + 'flex items-center justify-center' + ); if (loading || !data) { - return
Loading...
; + return
Loading...
; } if (error) { - return
Something went wrong: {error.message}
; + return ( +
Something went wrong: {error.message}
+ ); } return <>{children(data)}; diff --git a/apps/trading/pages/markets/index.page.tsx b/apps/trading/pages/markets/index.page.tsx index e751f74c2..07f59ee6a 100644 --- a/apps/trading/pages/markets/index.page.tsx +++ b/apps/trading/pages/markets/index.page.tsx @@ -1,4 +1,5 @@ import { gql, useQuery } from '@apollo/client'; +import { PageQueryContainer } from '../../components/page-query-container'; import Link from 'next/link'; import { useRouter } from 'next/router'; import { Markets } from './__generated__/Markets'; @@ -13,32 +14,27 @@ const MARKETS_QUERY = gql` const Markets = () => { const { pathname } = useRouter(); - const { data, loading, error } = useQuery(MARKETS_QUERY); - - if (loading || !data) { - return
Loading...
; - } return ( -
-

Markets

- {error ? ( -
Could not load markets {error.message}
- ) : ( - + query={MARKETS_QUERY}> + {(data) => ( + <> +

Markets

+ + )} -
+ ); };