This repository has been archived on 2026-11-17. You can view files and clone it, but cannot push or open issues or pull requests.
gitgram-ai/gitgram/web/utils/lazyLoad.tsx
caelum0x 49b183818c Unify gitgram + aitimemachine into the monorepo (de-submodule) and merge vendored engines
Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as
opaque submodule gitlinks on GitHub) into fully-tracked first-party content.

AITM now merges its 7 vendored repos as first-party engines:
- memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts
- git: vendored C git (bundled binary) + gitnexus (in-process code intelligence)
- agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess)

Includes the full session's product build: Gitgram web/mobile/backend features,
AITM website/CLI/MCP, the unified memory layer, engine build tooling
(scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md),
and extensive test suites.

Build artifacts, node_modules, external/, and gemini-cli are gitignored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 14:14:09 +03:00

110 lines
2.9 KiB
TypeScript

'use client'
import { lazy, Suspense, ComponentType } from 'react'
import { Skeleton } from '@/components/ui/skeleton'
interface LazyLoadOptions {
fallback?: React.ReactNode
delay?: number
}
// Create a lazy-loaded component with built-in suspense
export function lazyLoad<T extends ComponentType<any>>(
importFn: () => Promise<{ default: T }>,
options?: LazyLoadOptions
) {
const LazyComponent = lazy(importFn)
return function LazyWrapper(props: React.ComponentProps<T>) {
const fallback = options?.fallback ?? (
<div className="flex items-center justify-center p-8">
<div className="w-6 h-6 border-2 border-primary border-t-transparent rounded-full animate-spin" />
</div>
)
return (
<Suspense fallback={fallback}>
<LazyComponent {...props} />
</Suspense>
)
}
}
// Common fallback components
export function PageLoadingFallback() {
return (
<div className="min-h-screen flex items-center justify-center">
<div className="flex flex-col items-center gap-4">
<div className="w-8 h-8 border-2 border-primary border-t-transparent rounded-full animate-spin" />
<p className="text-muted text-sm">Loading...</p>
</div>
</div>
)
}
export function ComponentLoadingFallback() {
return (
<div className="flex items-center justify-center p-8">
<div className="w-6 h-6 border-2 border-primary border-t-transparent rounded-full animate-spin" />
</div>
)
}
export function FeedLoadingFallback() {
return (
<div className="space-y-4 p-4">
{[1, 2, 3].map((i) => (
<div key={i} className="bg-card border border-border rounded-xl p-4 space-y-3">
<div className="flex items-center gap-3">
<Skeleton variant="circular" className="w-10 h-10" />
<div className="space-y-2">
<Skeleton className="w-32 h-3" />
<Skeleton className="w-24 h-2" />
</div>
</div>
<Skeleton className="w-full h-3" />
<Skeleton className="w-3/4 h-3" />
<Skeleton className="w-full h-48 rounded-lg" />
</div>
))}
</div>
)
}
// Intersection observer based lazy loading for images
export function LazyImage({
src,
alt,
className = '',
placeholder,
...props
}: React.ImgHTMLAttributes<HTMLImageElement> & {
placeholder?: string
}) {
return (
<img
src={src}
alt={alt}
loading="lazy"
decoding="async"
className={className}
{...props}
/>
)
}
// Preload critical images
export function preloadImage(src: string): Promise<void> {
return new Promise((resolve, reject) => {
const img = new Image()
img.onload = () => resolve()
img.onerror = reject
img.src = src
})
}
// Preload multiple images
export function preloadImages(srcs: string[]): Promise<void[]> {
return Promise.all(srcs.map(preloadImage))
}