File tree Expand file tree Collapse file tree
apps/sim/app/o/[organizationId]/links Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ 'use client'
2+
3+ import { useState } from 'react'
4+ import { Globe } from '@sim/emcn/icons'
5+ import { faviconUrl } from '@/lib/core/utils/favicon'
6+ import { simLinkOrigin } from '@/lib/sim-links/validation'
7+
8+ interface SimLinkIconProps {
9+ /** The link's destination; a variable link's `{*}` never changes its host. */
10+ url : string
11+ }
12+
13+ /** The destination site's favicon, or a globe when the site has none. */
14+ export function SimLinkIcon ( { url } : SimLinkIconProps ) {
15+ const [ failedHostname , setFailedHostname ] = useState < string | null > ( null )
16+ const origin = simLinkOrigin ( url )
17+ const hostname = origin ? new URL ( origin ) . hostname : null
18+ if ( ! hostname || failedHostname === hostname ) return < Globe />
19+ return (
20+ < img
21+ src = { faviconUrl ( hostname , 64 ) }
22+ alt = ''
23+ referrerPolicy = 'no-referrer'
24+ className = 'rounded-sm'
25+ onError = { ( ) => setFailedHostname ( hostname ) }
26+ />
27+ )
28+ }
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ import {
1313 DropdownMenuTrigger ,
1414 writeTextToClipboard ,
1515} from '@sim/emcn'
16- import { Link , MoreHorizontal , Plus } from '@sim/emcn/icons'
16+ import { MoreHorizontal , Plus } from '@sim/emcn/icons'
1717import { createLogger } from '@sim/logger'
1818import { formatRelativeTime } from '@sim/utils/formatting'
1919import { useQueryStates } from 'nuqs'
@@ -26,6 +26,7 @@ import {
2626 useOrganizationPageFilters ,
2727} from '@/app/o/[organizationId]/components/organization-page'
2828import { simLinkViewParsers } from '@/app/o/[organizationId]/links/search-params'
29+ import { SimLinkIcon } from '@/app/o/[organizationId]/links/sim-link-icon'
2930import { SimLinkModal } from '@/app/o/[organizationId]/links/sim-link-modal'
3031import { SimLinksEmptyState } from '@/app/workspace/[workspaceId]/components/resource/components/resource-empty-state'
3132import {
@@ -127,7 +128,7 @@ export function SimLinks({ organizationId }: SimLinksProps) {
127128 return (
128129 < SettingsResourceRow
129130 key = { link . id }
130- icon = { < Link /> }
131+ icon = { < SimLinkIcon url = { link . url } /> }
131132 title = { `sim/${ link . name } ` }
132133 description = { link . description ? `${ link . description } · ${ link . url } ` : link . url }
133134 badge = { < SimLinkDetails link = { link } /> }
You can’t perform that action at this time.
0 commit comments