@ai-growth/nextjs
Version:
Seamlessly integrate Sanity CMS with Next.js applications for automated blog routing and rendering
126 lines • 4.9 kB
TypeScript
/**
* @fileoverview Fallback Content Components & Context
*
* This module provides components and context for handling fallback content
* when primary content fails to load. Includes caching, error handling,
* and graceful degradation.
*/
import { ReactNode } from 'react';
export interface FallbackContentItem {
/** Unique identifier for the content */
id: string;
/** Type of content (e.g., 'article', 'page', 'product') */
type: string;
/** Title/name of the content */
title: string;
/** Brief description or excerpt */
description?: string;
/** Fallback content data */
data: any;
/** When this fallback was cached */
cachedAt: Date;
/** When this fallback expires */
expiresAt?: Date;
/** Priority level for displaying fallbacks */
priority?: 'high' | 'medium' | 'low';
}
export interface FallbackContentOptions {
/** Content type to filter by */
contentType?: string;
/** Maximum age of cached content in milliseconds */
maxAge?: number;
/** Whether to include expired content as last resort */
includeExpired?: boolean;
/** Priority filter */
priority?: 'high' | 'medium' | 'low';
}
export interface UserFriendlyErrorMessage {
/** Main error heading */
title: string;
/** Detailed explanation */
message: string;
/** Suggested actions for the user */
suggestions?: string[];
/** Whether to show retry button */
showRetry?: boolean;
/** Whether to show refresh button */
showRefresh?: boolean;
/** Icon to display */
icon?: 'warning' | 'error' | 'offline' | 'loading';
}
export interface FallbackContentContextValue {
/** Store fallback content */
storeFallbackContent: (item: FallbackContentItem) => void;
/** Retrieve fallback content */
getFallbackContent: (id: string, options?: FallbackContentOptions) => FallbackContentItem | null;
/** Get multiple fallback items by type */
getFallbacksByType: (type: string, options?: FallbackContentOptions) => FallbackContentItem[];
/** Clear fallback content */
clearFallbackContent: (id?: string) => void;
/** Check if fallback content exists */
hasFallbackContent: (id: string) => boolean;
/** Get storage info */
getStorageInfo: () => {
count: number;
size: number;
};
}
export declare function getErrorMessage(error: Error, _context?: any): UserFriendlyErrorMessage;
export interface FallbackContentProviderProps {
children: ReactNode;
/** Maximum storage size in bytes */
maxStorageSize?: number;
/** Maximum number of stored items */
maxItems?: number;
/** Default expiry time for fallback content in milliseconds */
defaultExpiryTime?: number;
}
export declare function FallbackContentProvider({ children, maxStorageSize: _maxStorageSize, maxItems, defaultExpiryTime, }: FallbackContentProviderProps): import("react/jsx-runtime").JSX.Element;
export declare function useFallbackContent(): FallbackContentContextValue;
export interface FallbackContentProps {
/** Error that triggered the fallback */
error?: Error;
/** Content ID to look for fallback data */
contentId?: string;
/** Content type for fallback lookup */
contentType?: string;
/** Custom fallback content */
fallbackData?: any;
/** Retry function */
onRetry?: () => void;
/** Refresh function */
onRefresh?: () => void;
/** Custom error message */
customErrorMessage?: UserFriendlyErrorMessage;
/** Additional CSS classes */
className?: string;
}
export declare function FallbackContent({ error, contentId, contentType, fallbackData, onRetry, onRefresh, customErrorMessage, className, }: FallbackContentProps): import("react/jsx-runtime").JSX.Element;
export interface ContentFallbackProps {
/** Content type (article, page, etc.) */
contentType: string;
/** Number of fallback items to show */
count?: number;
/** Custom error message */
error?: Error;
/** Retry function */
onRetry?: () => void;
/** Additional CSS classes */
className?: string;
}
export declare function ContentFallback({ contentType, count, error, onRetry, className, }: ContentFallbackProps): import("react/jsx-runtime").JSX.Element;
export interface PartialContentFallbackProps {
/** Partial data that was successfully loaded */
partialData: any;
/** Error that prevented full load */
error: Error;
/** Retry function */
onRetry?: () => void;
/** Field names that are missing */
missingFields?: string[];
/** Additional CSS classes */
className?: string;
}
export declare function PartialContentFallback({ partialData, error: _error, onRetry, missingFields, className, }: PartialContentFallbackProps): import("react/jsx-runtime").JSX.Element;
export default FallbackContent;
//# sourceMappingURL=FallbackContent.d.ts.map