From 70f31c013149cd3292f56964e7b7582d77473b53 Mon Sep 17 00:00:00 2001 From: RaenonX Date: Thu, 27 May 2021 16:46:34 -0500 Subject: [PATCH] FIX - Ensure scroll to correct position on initial search Signed-off-by: RaenonX --- .../elements/posts/analysis/lookup/main.test.tsx | 11 +++++++---- .../elements/posts/analysis/lookup/main.tsx | 2 +- .../elements/posts/analysis/lookup/out/main.tsx | 8 ++++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/components/elements/posts/analysis/lookup/main.test.tsx b/src/components/elements/posts/analysis/lookup/main.test.tsx index f280bf46..7462d55f 100644 --- a/src/components/elements/posts/analysis/lookup/main.test.tsx +++ b/src/components/elements/posts/analysis/lookup/main.test.tsx @@ -95,7 +95,7 @@ describe('Analysis lookup page', () => { expect(fnGetLookup).toHaveBeenCalledTimes(1); }); await waitFor(async () => { - expect(fnScroll).toHaveBeenCalledTimes(1); + expect(fnScroll).toHaveBeenCalledTimes(2); expect(screen.queryByAltText('Gala Leonidas')).toBeInTheDocument(); }); }); @@ -121,7 +121,7 @@ describe('Analysis lookup page', () => { expect(fnGetLookup).toHaveBeenCalledTimes(1); }); await waitFor(async () => { - expect(fnScroll).toHaveBeenCalledTimes(1); + expect(fnScroll).toHaveBeenCalledTimes(2); }); expect(screen.queryByAltText('Gala Leonidas')).not.toBeInTheDocument(); }); @@ -147,7 +147,7 @@ describe('Analysis lookup page', () => { expect(fnGetLookup).toHaveBeenCalledTimes(1); }); await waitFor(async () => { - expect(fnScroll).toHaveBeenCalledTimes(1); + expect(fnScroll).toHaveBeenCalledTimes(2); }); expect(screen.queryByText('Gala Leonidas')).not.toBeInTheDocument(); @@ -165,6 +165,9 @@ describe('Analysis lookup page', () => { await waitFor(async () => { expect(fnGetLookup).toHaveBeenCalledTimes(1); }); + await waitFor(async () => { + expect(fnScroll).toHaveBeenCalledTimes(3); + }); await waitFor(async () => { expect(screen.queryByAltText('Gala Leonidas')).toBeInTheDocument(); }); @@ -310,7 +313,7 @@ describe('Analysis lookup page', () => { await waitFor(() => { expect(fnGetLookup).toHaveBeenCalledTimes(1); - expect(fnScroll).toHaveBeenCalledTimes(1); + expect(fnScroll).toHaveBeenCalledTimes(2); expect(screen.queryByText(translationEN.posts.analysis.error.noResult)).toBeInTheDocument(); }); const errorText = screen.getByText(translationEN.posts.analysis.error.noResult); diff --git a/src/components/elements/posts/analysis/lookup/main.tsx b/src/components/elements/posts/analysis/lookup/main.tsx index 76559302..6544dc25 100644 --- a/src/components/elements/posts/analysis/lookup/main.tsx +++ b/src/components/elements/posts/analysis/lookup/main.tsx @@ -37,7 +37,7 @@ export const AnalysisPostLookup = () => { setInputForward(data); }} /> - {inputForward && } + ); }; diff --git a/src/components/elements/posts/analysis/lookup/out/main.tsx b/src/components/elements/posts/analysis/lookup/out/main.tsx index 82871101..5b5df18d 100644 --- a/src/components/elements/posts/analysis/lookup/out/main.tsx +++ b/src/components/elements/posts/analysis/lookup/out/main.tsx @@ -14,7 +14,7 @@ import {getUnitInfo} from '../utils'; import {AnalysisEntry} from './entry'; type AnalysisLookupOutputProps = { - inputData: InputData, + inputData: InputData | undefined, } export const AnalysisLookupOutput = ({inputData}: AnalysisLookupOutputProps) => { @@ -42,6 +42,10 @@ export const AnalysisLookupOutput = ({inputData}: AnalysisLookupOutputProps) => scrollToTop(rowElem); }, [inputData]); + if (!inputData) { + return <>; + } + fetchAnalysisMeta(); const unitInfoFiltered = getUnitInfo(inputData, charaInfo, dragonInfo); @@ -49,7 +53,7 @@ export const AnalysisLookupOutput = ({inputData}: AnalysisLookupOutputProps) => const unitInfoHasAnalysis = unitInfoFiltered.filter((info) => info.id in analysisMeta.data.analyses); const unitInfoNoAnalysis = unitInfoFiltered.filter((info) => !(info.id in analysisMeta.data.analyses)); - if (inputData && charaInfo.length && dragonInfo.length && !unitInfoFiltered.length) { + if (charaInfo.length && dragonInfo.length && !unitInfoFiltered.length) { return (
{t((t) => t.posts.analysis.error.noResult)}