|
3 | 3 | import nextDynamic from 'next/dynamic' |
4 | 4 | import type { ComponentType } from 'react' |
5 | 5 | import type { TToolSlug } from '../constants/tools' |
6 | | - |
7 | | -function ToolSkeleton() { |
8 | | - return ( |
9 | | - <div |
10 | | - role="status" |
11 | | - aria-label="Loading tool" |
12 | | - className="flex min-h-[70vh] flex-col gap-3" |
13 | | - > |
14 | | - <div className="h-8 w-64 shrink-0 animate-pulse bg-muted/60" /> |
15 | | - <div className="h-28 shrink-0 animate-pulse bg-muted/60" /> |
16 | | - <div className="grow animate-pulse bg-muted/60" /> |
17 | | - </div> |
18 | | - ) |
19 | | -} |
| 6 | +import { TOOL_SKELETONS } from './tool-skeletons' |
20 | 7 |
|
21 | 8 | type TLoader = () => Promise<{ default: ComponentType }> |
22 | 9 |
|
23 | | -function lazyTool(loader: TLoader, ssr = false) { |
24 | | - return nextDynamic(loader, { ssr, loading: ToolSkeleton }) |
| 10 | +function lazyTool(slug: TToolSlug, loader: TLoader) { |
| 11 | + const Fallback = TOOL_SKELETONS[slug] |
| 12 | + return nextDynamic(loader, { ssr: true, loading: () => <Fallback /> }) |
25 | 13 | } |
26 | 14 |
|
27 | 15 | const TOOL_COMPONENTS: Record<TToolSlug, ComponentType> = { |
28 | | - 'find-replace': lazyTool(() => import('../find-replace')), |
29 | | - 'diff-checker': lazyTool(() => import('../diff-checker'), true), |
30 | | - 'link-extractor': lazyTool(() => import('../link-extractor'), true), |
31 | | - 'json-tool': lazyTool(() => import('../json-tool'), true), |
32 | | - 'svg-converter': lazyTool(() => import('../svg-converter'), true), |
33 | | - hemelsbreed: lazyTool(() => import('../hemelsbreed')), |
34 | | - 'coordinate-marker': lazyTool(() => import('../coordinate-marker')), |
35 | | - 'my-location': lazyTool(() => import('../my-location')), |
36 | | - 'sendable-video': lazyTool(() => import('../sendable-video')), |
37 | | - 'gif-to-video': lazyTool(() => import('../gif-to-video')), |
38 | | - 'video-to-gif': lazyTool(() => import('../video-to-gif')) |
| 16 | + 'find-replace': lazyTool('find-replace', () => import('../find-replace')), |
| 17 | + 'diff-checker': lazyTool('diff-checker', () => import('../diff-checker')), |
| 18 | + 'link-extractor': lazyTool('link-extractor', () => import('../link-extractor')), |
| 19 | + 'json-tool': lazyTool('json-tool', () => import('../json-tool')), |
| 20 | + 'svg-converter': lazyTool('svg-converter', () => import('../svg-converter')), |
| 21 | + hemelsbreed: lazyTool('hemelsbreed', () => import('../hemelsbreed')), |
| 22 | + 'coordinate-marker': lazyTool('coordinate-marker', () => import('../coordinate-marker')), |
| 23 | + 'my-location': lazyTool('my-location', () => import('../my-location')), |
| 24 | + 'sendable-video': lazyTool('sendable-video', () => import('../sendable-video')), |
| 25 | + 'gif-to-video': lazyTool('gif-to-video', () => import('../gif-to-video')), |
| 26 | + 'video-to-gif': lazyTool('video-to-gif', () => import('../video-to-gif')) |
39 | 27 | } |
40 | 28 |
|
41 | 29 | type Props = { |
|
0 commit comments