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 { FormattedMessage } from "react-intl";
import useCachedFetch from "@/Hooks/useCachedFetch";
import {ErrorOrOffline} from "@/Element/ErrorOrOffline";
export function TrendingHashTagsLine(props: { onClick: (tag: string) => void }) {
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);
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 (
<div className="flex flex-col g4">

View File

@ -28,7 +28,7 @@ export default function TrendingHashtags({
isLoading,
} = 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 />;
return (

View File

@ -19,7 +19,7 @@ import useCachedFetch from "@/Hooks/useCachedFetch";
export default function TrendingNotes({ count = Infinity, small = false }) {
const api = new NostrBandApi();
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 {
@ -29,7 +29,7 @@ export default function TrendingNotes({ count = Infinity, small = false }) {
} = useCachedFetch(
trendingNotesUrl,
storageKey,
data => data.notes.map(a => a.event), // Process the data as needed
data => data.notes.map(a => a.event),
);
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 [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 />;
const filteredAndLimitedPosts = trendingNotesData

View File

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