From eed2f08bc9f9191092326f125e2332402dd57cc8 Mon Sep 17 00:00:00 2001 From: Matthew Russell Date: Wed, 2 Mar 2022 11:16:10 -0800 Subject: [PATCH] use already installed lodash.debounce, destructuring --- .../trading/pages/markets/[marketId].page.tsx | 27 +++++++++++-------- package.json | 1 - 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/apps/trading/pages/markets/[marketId].page.tsx b/apps/trading/pages/markets/[marketId].page.tsx index 41e43c891..c0243490c 100644 --- a/apps/trading/pages/markets/[marketId].page.tsx +++ b/apps/trading/pages/markets/[marketId].page.tsx @@ -1,7 +1,7 @@ import { gql } from '@apollo/client'; import { useRouter } from 'next/router'; import React, { useEffect, useState } from 'react'; -import debounce from 'lodash/debounce'; +import debounce from 'lodash.debounce'; import { Market, MarketVariables } from './__generated__/Market'; import { PageQueryContainer } from '../../components/page-query-container'; import { TradeGrid, TradePanels } from './trade-grid'; @@ -23,25 +23,30 @@ const MARKET_QUERY = gql` `; const MarketPage = () => { - const { query } = useRouter(); + const { + query: { marketId }, + } = useRouter(); const { w } = useWindowSize(); return ( query={MARKET_QUERY} options={{ - variables: { marketId: query.marketId as string }, - skip: !query.marketId, + // Not sure exactly why marketId is string | string[] but just the first item in the array if + // it is one + variables: { + marketId: Array.isArray(marketId) ? marketId[0] : marketId, + }, + skip: !marketId, }} > - {(data) => + {({ market }) => w > 1050 ? ( - + ) : ( - + ) } - {} ); }; @@ -65,10 +70,10 @@ const useWindowSize = () => { }); useEffect(() => { - const handleResize = debounce((event) => { + const handleResize = debounce(({ target }) => { setWindowSize({ - w: event.target.innerWidth, - h: event.target.innerHeight, + w: target.innerWidth, + h: target.innerHeight, }); }, 300); diff --git a/package.json b/package.json index 4593b06ff..aac0f9aba 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,6 @@ "core-js": "^3.6.5", "env-cmd": "^10.1.0", "graphql": "^15.7.2", - "lodash": "^4.17.21", "lodash.debounce": "^4.0.8", "next": "12.0.7", "postcss": "^8.4.6",