refactor: simplify ContentLinkUrl rendering
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {ellipsize, displayUrl, postJson} from "@welshman/lib"
|
import {call, ellipsize, displayUrl, postJson} from "@welshman/lib"
|
||||||
import {isRelayUrl, getTagValue} from "@welshman/util"
|
import {isRelayUrl, getTagValue} from "@welshman/util"
|
||||||
import {Capacitor} from "@capacitor/core"
|
import {Capacitor} from "@capacitor/core"
|
||||||
import {preventDefault, stopPropagation} from "@lib/html"
|
import {preventDefault, stopPropagation} from "@lib/html"
|
||||||
|
import Link from "@lib/components/Link.svelte"
|
||||||
import ContentLinkDetail from "@app/components/ContentLinkDetail.svelte"
|
import ContentLinkDetail from "@app/components/ContentLinkDetail.svelte"
|
||||||
import ContentLinkUrl from "@app/components/ContentLinkUrl.svelte"
|
import ContentLinkUrl from "@app/components/ContentLinkUrl.svelte"
|
||||||
import ContentLinkBlockImage from "@app/components/ContentLinkBlockImage.svelte"
|
import ContentLinkBlockImage from "@app/components/ContentLinkBlockImage.svelte"
|
||||||
@@ -10,6 +11,7 @@
|
|||||||
import {
|
import {
|
||||||
dufflepud,
|
dufflepud,
|
||||||
IMAGE_CONTENT_TYPES,
|
IMAGE_CONTENT_TYPES,
|
||||||
|
PLATFORM_URL,
|
||||||
VIDEO_CONTENT_TYPES,
|
VIDEO_CONTENT_TYPES,
|
||||||
THUMBNAIL_URL,
|
THUMBNAIL_URL,
|
||||||
isRoomId,
|
isRoomId,
|
||||||
@@ -21,6 +23,11 @@
|
|||||||
|
|
||||||
const url = value.url.toString()
|
const url = value.url.toString()
|
||||||
const isRoomOrRelay = isRoomId(url) || isRelayUrl(url)
|
const isRoomOrRelay = isRoomId(url) || isRelayUrl(url)
|
||||||
|
const [href, external] = call(() => {
|
||||||
|
if (url.startsWith(PLATFORM_URL)) return [url.replace(PLATFORM_URL, ""), false]
|
||||||
|
|
||||||
|
return [url, true]
|
||||||
|
})
|
||||||
|
|
||||||
const fileType = getTagValue("file-type", event.tags) || ""
|
const fileType = getTagValue("file-type", event.tags) || ""
|
||||||
|
|
||||||
@@ -50,13 +57,9 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if isRoomOrRelay}
|
{#if isRoomOrRelay}
|
||||||
<ContentLinkUrl
|
<ContentLinkUrl {url} class="bg-alt my-2 block p-4 leading-normal whitespace-nowrap" />
|
||||||
{url}
|
|
||||||
class="bg-alt my-2 block p-4 leading-normal whitespace-nowrap"
|
|
||||||
showIcon
|
|
||||||
labelClass="ml-2" />
|
|
||||||
{:else}
|
{:else}
|
||||||
<ContentLinkUrl {url} class="my-2 block">
|
<Link {external} {href} class="my-2 block">
|
||||||
<div class="overflow-hidden rounded-box">
|
<div class="overflow-hidden rounded-box">
|
||||||
{#if url.match(/\.(mov|webm|mp4)$/) || VIDEO_CONTENT_TYPES.includes(fileType)}
|
{#if url.match(/\.(mov|webm|mp4)$/) || VIDEO_CONTENT_TYPES.includes(fileType)}
|
||||||
<video
|
<video
|
||||||
@@ -98,5 +101,5 @@
|
|||||||
{/await}
|
{/await}
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</ContentLinkUrl>
|
</Link>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -27,5 +27,5 @@
|
|||||||
{displayUrl(url)}
|
{displayUrl(url)}
|
||||||
</a>
|
</a>
|
||||||
{:else}
|
{:else}
|
||||||
<ContentLinkUrl {url} class="link-content whitespace-nowrap" showIcon />
|
<ContentLinkUrl {url} class="link-content whitespace-nowrap" />
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type {Snippet} from "svelte"
|
|
||||||
import {call, displayUrl} from "@welshman/lib"
|
import {call, displayUrl} from "@welshman/lib"
|
||||||
import {displayRelayUrl, isRelayUrl, normalizeRelayUrl} from "@welshman/util"
|
import {displayRelayUrl, isRelayUrl, normalizeRelayUrl} from "@welshman/util"
|
||||||
import LinkRound from "@assets/icons/link-round.svg?dataurl"
|
import LinkRound from "@assets/icons/link-round.svg?dataurl"
|
||||||
@@ -9,17 +8,11 @@
|
|||||||
import {makeRoomPath, makeSpacePath} from "@app/util/routes"
|
import {makeRoomPath, makeSpacePath} from "@app/util/routes"
|
||||||
|
|
||||||
const {
|
const {
|
||||||
children,
|
|
||||||
url,
|
url,
|
||||||
class: className = "",
|
class: className = "",
|
||||||
showIcon = false,
|
|
||||||
labelClass = "",
|
|
||||||
}: {
|
}: {
|
||||||
children?: Snippet
|
|
||||||
url: string
|
url: string
|
||||||
class?: string
|
class?: string
|
||||||
showIcon?: boolean
|
|
||||||
labelClass?: string
|
|
||||||
} = $props()
|
} = $props()
|
||||||
|
|
||||||
const roomReference = call(() => {
|
const roomReference = call(() => {
|
||||||
@@ -69,12 +62,6 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Link {external} {href} class={className}>
|
<Link {external} {href} class={className}>
|
||||||
{#if children}
|
<Icon icon={LinkRound} size={3} class="inline-block" />
|
||||||
{@render children()}
|
<span class="ml-2">{label}</span>
|
||||||
{:else if showIcon}
|
|
||||||
<Icon icon={LinkRound} size={3} class="inline-block" />
|
|
||||||
<span class={labelClass}>{label}</span>
|
|
||||||
{:else}
|
|
||||||
{label}
|
|
||||||
{/if}
|
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
Reference in New Issue
Block a user