Skip to content

Commit c63e93e

Browse files
authored
improvement(sim-links): show each link's destination favicon (#9489)
Sim link rows show the destination site's favicon via the shared faviconUrl helper, falling back to a globe when none loads.
1 parent 854e095 commit c63e93e

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}

‎apps/sim/app/o/[organizationId]/links/sim-links.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff 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'
1717
import { createLogger } from '@sim/logger'
1818
import { formatRelativeTime } from '@sim/utils/formatting'
1919
import { useQueryStates } from 'nuqs'
@@ -26,6 +26,7 @@ import {
2626
useOrganizationPageFilters,
2727
} from '@/app/o/[organizationId]/components/organization-page'
2828
import { simLinkViewParsers } from '@/app/o/[organizationId]/links/search-params'
29+
import { SimLinkIcon } from '@/app/o/[organizationId]/links/sim-link-icon'
2930
import { SimLinkModal } from '@/app/o/[organizationId]/links/sim-link-modal'
3031
import { SimLinksEmptyState } from '@/app/workspace/[workspaceId]/components/resource/components/resource-empty-state'
3132
import {
@@ -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} />}

0 commit comments

Comments
 (0)