From 95e11c70bcba5c6f4f84b1be7d6b10783fb0c717 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Wed, 5 Feb 2025 09:15:57 -0600 Subject: [PATCH] Add loading status to all entity links --- src/camera/PhotoCamera.tsx | 4 +- src/components/primitives/EntityLink.tsx | 90 +++++++++++++---------- src/components/primitives/LabeledIcon.tsx | 59 ++++++--------- 3 files changed, 78 insertions(+), 75 deletions(-) diff --git a/src/camera/PhotoCamera.tsx b/src/camera/PhotoCamera.tsx index c0bd744e..aa8413b9 100644 --- a/src/camera/PhotoCamera.tsx +++ b/src/camera/PhotoCamera.tsx @@ -9,7 +9,7 @@ import EntityLink, { export default function PhotoCamera({ camera, hideAppleIcon, - type = 'icon-first', + type, badged, contrast, prefetch, @@ -36,7 +36,7 @@ export default function PhotoCamera({ size={12} className="translate-x-[-1px]" />} - type={showAppleIcon && isCameraApple ? 'icon-first' : type} + type={type} badged={badged} contrast={contrast} prefetch={prefetch} diff --git a/src/components/primitives/EntityLink.tsx b/src/components/primitives/EntityLink.tsx index 231ed4ec..4a300aa3 100644 --- a/src/components/primitives/EntityLink.tsx +++ b/src/components/primitives/EntityLink.tsx @@ -1,7 +1,11 @@ +'use client'; + import { ReactNode } from 'react'; import LabeledIcon, { LabeledIconType } from './LabeledIcon'; import Badge from '../Badge'; import { clsx } from 'clsx/lite'; +import LinkWithStatus from '../LinkWithStatus'; +import Spinner from '../Spinner'; export interface EntityLinkExternalProps { type?: LabeledIconType @@ -18,7 +22,7 @@ export default function EntityLink({ type, badged, contrast = 'medium', - href, + href = '', // Make link optional for debugging purposes prefetch, title, hoverEntity, @@ -59,43 +63,53 @@ export default function EntityLink({ ; return ( - - - {badged - ? - {renderLabel()} - - : *]:truncate', - )}> - {renderLabel()} - } - - {hoverEntity !== undefined && - - {hoverEntity} - } + + + {({ isLoading }) => <> + + {badged + ? + {renderLabel()} + + : *]:truncate', + )}> + {renderLabel()} + } + + {!isLoading && hoverEntity !== undefined && + + {hoverEntity} + } + {isLoading && } + } + ); } diff --git a/src/components/primitives/LabeledIcon.tsx b/src/components/primitives/LabeledIcon.tsx index 271d9cb1..1486aae3 100644 --- a/src/components/primitives/LabeledIcon.tsx +++ b/src/components/primitives/LabeledIcon.tsx @@ -1,7 +1,6 @@ -import { ComponentProps, ReactNode } from 'react'; +import { ReactNode } from 'react'; import Icon from './Icon'; import { clsx } from 'clsx/lite'; -import Link from 'next/link'; export type LabeledIconType = 'icon-first' | @@ -15,8 +14,6 @@ export default function LabeledIcon({ className: classNameProp, children, iconWide, - href, - prefetch, debug, }: { icon?: ReactNode, @@ -25,36 +22,28 @@ export default function LabeledIcon({ children: ReactNode, iconWide?:boolean, debug?: boolean, -} & Partial>) { - const className = clsx( - 'inline-flex gap-x-1 md:gap-x-1.5 min-w-0', - classNameProp, - debug && 'border border-green-500 m-[-1px]', +}) { + return ( + + {icon && type !== 'text-only' && + + {icon} + } + {children && type !== 'icon-only' && + + {children} + } + ); - - const renderContent = () => <> - {icon && type !== 'text-only' && - - {icon} - } - {children && type !== 'icon-only' && - - {children} - } - ; - - return href - ? - {renderContent()} - - :
- {renderContent()} -
; }