Merge branch 't3code/company-overview-loading-cache'
This commit is contained in:
@@ -4,6 +4,7 @@ import { useQueryClient } from '@tanstack/react-query';
|
||||
import { Suspense, useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
import { AppShell } from '@/components/shell/app-shell';
|
||||
import { CompanyAnalysisSkeleton } from '@/components/analysis/company-analysis-skeleton';
|
||||
import { AnalysisToolbar } from '@/components/analysis/analysis-toolbar';
|
||||
import { BullBearPanel } from '@/components/analysis/bull-bear-panel';
|
||||
import { CompanyOverviewCard } from '@/components/analysis/company-overview-card';
|
||||
@@ -55,21 +56,28 @@ function AnalysisPageContent() {
|
||||
setTicker(normalized);
|
||||
}, [searchParams]);
|
||||
|
||||
const loadAnalysis = useCallback(async (symbol: string) => {
|
||||
const options = companyAnalysisQueryOptions(symbol);
|
||||
const loadAnalysis = useCallback(async (symbol: string, options?: { refresh?: boolean }) => {
|
||||
const queryOptions = companyAnalysisQueryOptions(symbol, options);
|
||||
|
||||
if (!queryClient.getQueryData(options.queryKey)) {
|
||||
if (!queryClient.getQueryData(queryOptions.queryKey)) {
|
||||
setLoading(true);
|
||||
}
|
||||
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await queryClient.fetchQuery(options);
|
||||
const response = await queryClient.fetchQuery(queryOptions);
|
||||
setAnalysis(response.analysis);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Unable to load company overview');
|
||||
setAnalysis(null);
|
||||
setAnalysis((current) => {
|
||||
const normalizedTicker = symbol.trim().toUpperCase();
|
||||
if (options?.refresh && current?.company.ticker === normalizedTicker) {
|
||||
return current;
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -116,7 +124,7 @@ function AnalysisPageContent() {
|
||||
onRefresh={() => {
|
||||
const normalizedTicker = activeTicker.trim().toUpperCase();
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.companyAnalysis(normalizedTicker) });
|
||||
void loadAnalysis(normalizedTicker);
|
||||
void loadAnalysis(normalizedTicker, { refresh: true });
|
||||
}}
|
||||
quickLinks={quickLinks}
|
||||
onLinkPrefetch={() => prefetchResearchTicker(activeTicker)}
|
||||
@@ -128,7 +136,9 @@ function AnalysisPageContent() {
|
||||
</Panel>
|
||||
) : null}
|
||||
|
||||
{analysis ? (
|
||||
{!analysis && loading ? (
|
||||
<CompanyAnalysisSkeleton />
|
||||
) : analysis ? (
|
||||
<>
|
||||
<section className="grid gap-6 xl:grid-cols-[minmax(320px,1fr)_minmax(0,2fr)]">
|
||||
<CompanyOverviewCard
|
||||
|
||||
Reference in New Issue
Block a user