show trending error only if no cached content

This commit is contained in:
Martti Malmi 2023-12-27 22:31:57 +02:00
parent 789476c677
commit 3e52bb755e
4 changed files with 10 additions and 7 deletions

View File

@ -2,6 +2,7 @@ import { useLocale } from "@/IntlProvider";
import NostrBandApi from "@/External/NostrBand"; import NostrBandApi from "@/External/NostrBand";
import { FormattedMessage } from "react-intl"; import { FormattedMessage } from "react-intl";
import useCachedFetch from "@/Hooks/useCachedFetch"; import useCachedFetch from "@/Hooks/useCachedFetch";
import {ErrorOrOffline} from "@/Element/ErrorOrOffline";
export function TrendingHashTagsLine(props: { onClick: (tag: string) => void }) { export function TrendingHashTagsLine(props: { onClick: (tag: string) => void }) {
const { lang } = useLocale(); const { lang } = useLocale();
@ -11,7 +12,9 @@ export function TrendingHashTagsLine(props: { onClick: (tag: string) => void })
const { data: hashtags, isLoading, error } = useCachedFetch(trendingHashtagsUrl, storageKey, data => data.hashtags); const { data: hashtags, isLoading, error } = useCachedFetch(trendingHashtagsUrl, storageKey, data => data.hashtags);
if (isLoading || error || !hashtags || hashtags.length === 0) return null; if (error && !hashtags) return <ErrorOrOffline error={error} className="p" />;
if (isLoading || hashtags.length === 0) return null;
return ( return (
<div className="flex flex-col g4"> <div className="flex flex-col g4">

View File

@ -28,7 +28,7 @@ export default function TrendingHashtags({
isLoading, isLoading,
} = useCachedFetch(trendingHashtagsUrl, storageKey, data => data.hashtags.slice(0, count)); } = useCachedFetch(trendingHashtagsUrl, storageKey, data => data.hashtags.slice(0, count));
if (error) return <ErrorOrOffline error={error} onRetry={() => {}} className="p" />; if (error && !hashtags) return <ErrorOrOffline error={error} onRetry={() => {}} className="p" />;
if (isLoading) return <PageSpinner />; if (isLoading) return <PageSpinner />;
return ( return (

View File

@ -19,7 +19,7 @@ import useCachedFetch from "@/Hooks/useCachedFetch";
export default function TrendingNotes({ count = Infinity, small = false }) { export default function TrendingNotes({ count = Infinity, small = false }) {
const api = new NostrBandApi(); const api = new NostrBandApi();
const { lang } = useLocale(); const { lang } = useLocale();
const trendingNotesUrl = api.trendingNotesUrl(lang); // Get the URL for trending notes const trendingNotesUrl = api.trendingNotesUrl(lang);
const storageKey = `nostr-band-${trendingNotesUrl}`; const storageKey = `nostr-band-${trendingNotesUrl}`;
const { const {
@ -29,7 +29,7 @@ export default function TrendingNotes({ count = Infinity, small = false }) {
} = useCachedFetch( } = useCachedFetch(
trendingNotesUrl, trendingNotesUrl,
storageKey, storageKey,
data => data.notes.map(a => a.event), // Process the data as needed data => data.notes.map(a => a.event),
); );
const login = useLogin(); const login = useLogin();
@ -39,7 +39,7 @@ export default function TrendingNotes({ count = Infinity, small = false }) {
const related = useReactions("trending", trendingNotesData?.map(a => NostrLink.fromEvent(a)) ?? [], undefined, true); const related = useReactions("trending", trendingNotesData?.map(a => NostrLink.fromEvent(a)) ?? [], undefined, true);
const [modalThread, setModalThread] = useState<NostrLink | undefined>(undefined); const [modalThread, setModalThread] = useState<NostrLink | undefined>(undefined);
if (error) return <ErrorOrOffline error={error} className="p" />; if (error && !trendingNotesData) return <ErrorOrOffline error={error} className="p" />;
if (isLoading) return <PageSpinner />; if (isLoading) return <PageSpinner />;
const filteredAndLimitedPosts = trendingNotesData const filteredAndLimitedPosts = trendingNotesData

View File

@ -17,11 +17,11 @@ export default function TrendingUsers({ title, count = Infinity }: { title?: Rea
error, error,
} = useCachedFetch(trendingProfilesUrl, storageKey, data => data.profiles.map(a => a.pubkey)); } = useCachedFetch(trendingProfilesUrl, storageKey, data => data.profiles.map(a => a.pubkey));
if (error) { if (error && !trendingUsersData) {
return <ErrorOrOffline error={error} onRetry={() => {}} className="p" />; return <ErrorOrOffline error={error} onRetry={() => {}} className="p" />;
} }
if (isLoading || !trendingUsersData) { if (isLoading) {
return <PageSpinner />; return <PageSpinner />;
} }