fixed shortener card on links page not showing correct url for shortener with custom project domain

main
TZGyn 1 year ago
parent df4e8f290c
commit 3ccf678010
Signed by: TZGyn
GPG Key ID: 122EAF77AE81FD4A

@ -8,7 +8,7 @@
import { Badge } from '$lib/components/ui/badge' import { Badge } from '$lib/components/ui/badge'
import { ScrollArea } from '$lib/components/ui/scroll-area' import { ScrollArea } from '$lib/components/ui/scroll-area'
import { Separator } from '$lib/components/ui/separator' import { Separator } from '$lib/components/ui/separator'
import type { Shortener } from '$lib/db/types' import type { Project, Shortener } from '$lib/db/types'
import { import {
BarChart, BarChart,
EditIcon, EditIcon,
@ -28,6 +28,7 @@
projectName: string | null projectName: string | null
projectUuid: string | null projectUuid: string | null
visitorCount: number visitorCount: number
project: Project | null
} }
export let shortener_url: string export let shortener_url: string
@ -80,11 +81,15 @@
} }
const hostDomain = 'https://' + shortener.link.split('/')[2] const hostDomain = 'https://' + shortener.link.split('/')[2]
const shortenerUrl = shortener.project?.enable_custom_domain
? shortener.project.custom_domain || shortener_url
: shortener_url
</script> </script>
<Card.Root> <Card.Root>
<Card.Header> <Card.Header>
<Card.Title class="flex gap-4 justify-between items-center"> <Card.Title class="flex items-center justify-between gap-4">
<Avatar.Root class="overflow-visible"> <Avatar.Root class="overflow-visible">
<Avatar.Image <Avatar.Image
src={hostDomain + '/favicon.ico'} src={hostDomain + '/favicon.ico'}
@ -94,11 +99,11 @@
</Avatar.Fallback> </Avatar.Fallback>
</Avatar.Root> </Avatar.Root>
<div class="flex flex-col flex-grow gap-2 items-start"> <div class="flex flex-grow flex-col items-start gap-2">
<Tooltip.Root> <Tooltip.Root>
<Tooltip.Trigger> <Tooltip.Trigger>
<div <div
class="whitespace-nowrap max-w-[250px] overflow-x-clip overflow-ellipsis"> class="max-w-[250px] overflow-x-clip overflow-ellipsis whitespace-nowrap">
{shortener.link} {shortener.link}
</div> </div>
</Tooltip.Trigger> </Tooltip.Trigger>
@ -108,12 +113,12 @@
</Tooltip.Root> </Tooltip.Root>
<div <div
class="flex gap-2 items-center text-sm text-muted-foreground"> class="flex items-center gap-2 text-sm text-muted-foreground">
<a <a
href={'https://' + shortener_url + '/' + shortener.code} href={'https://' + shortenerUrl + '/' + shortener.code}
target="_blank" target="_blank"
class="hover:underline"> class="hover:underline">
{shortener_url + '/' + shortener.code} {shortenerUrl + '/' + shortener.code}
</a> </a>
<ExternalLink size={16} /> <ExternalLink size={16} />
</div> </div>
@ -129,13 +134,13 @@
href={`/links/${shortener.code}/edit`} href={`/links/${shortener.code}/edit`}
on:click|preventDefault={() => on:click|preventDefault={() =>
showEditModal(shortener.code)}> showEditModal(shortener.code)}>
<DropdownMenu.Item class="flex gap-2 items-center"> <DropdownMenu.Item class="flex items-center gap-2">
<EditIcon size={16} />Edit <EditIcon size={16} />Edit
</DropdownMenu.Item> </DropdownMenu.Item>
</a> </a>
<DropdownMenu.Item <DropdownMenu.Item
on:click={() => openDeleteDialog(shortener.code)} on:click={() => openDeleteDialog(shortener.code)}
class="flex gap-2 items-center text-destructive data-[highlighted]:bg-destructive"> class="flex items-center gap-2 text-destructive data-[highlighted]:bg-destructive">
<TrashIcon size={16} /> <TrashIcon size={16} />
Delete Delete
</DropdownMenu.Item> </DropdownMenu.Item>
@ -145,11 +150,11 @@
</Card.Title> </Card.Title>
</Card.Header> </Card.Header>
<Card.Content> <Card.Content>
<div class="flex justify-between items-center"> <div class="flex items-center justify-between">
<div class="flex gap-2"> <div class="flex gap-2">
<Button <Button
href={`/links/${shortener.code}`} href={`/links/${shortener.code}`}
class="flex gap-1 justify-center items-center h-8 text-sm rounded bg-secondary"> class="flex h-8 items-center justify-center gap-1 rounded bg-secondary text-sm">
<BarChart size={20} /> <BarChart size={20} />
<div> <div>
{shortener.visitorCount} visits {shortener.visitorCount} visits
@ -178,8 +183,9 @@
{#if shortener.android} {#if shortener.android}
<Tooltip.Root> <Tooltip.Root>
<Tooltip.Trigger> <Tooltip.Trigger>
<Badge variant="outline" class="flex gap-2" <Badge variant="outline" class="flex gap-2">
>Android</Badge> Android
</Badge>
</Tooltip.Trigger> </Tooltip.Trigger>
<Tooltip.Content> <Tooltip.Content>
<p>{shortener.android_link}</p> <p>{shortener.android_link}</p>
@ -194,13 +200,13 @@
<Badge variant="outline" class="flex gap-2"> <Badge variant="outline" class="flex gap-2">
{#if shortener.active} {#if shortener.active}
<span <span
class="inline-flex relative w-2 h-2 bg-green-400 rounded-full" class="relative inline-flex h-2 w-2 rounded-full bg-green-400">
></span> </span>
Active Active
{:else} {:else}
<span <span
class="inline-flex relative w-2 h-2 bg-gray-600 rounded-full" class="relative inline-flex h-2 w-2 rounded-full bg-gray-600">
></span> </span>
Inactive Inactive
{/if} {/if}
</Badge> </Badge>

@ -65,11 +65,13 @@ export const load = (async (event) => {
} }
const shortenerColumns = getTableColumns(shortener) const shortenerColumns = getTableColumns(shortener)
const projectColumns = getTableColumns(project)
const shorteners = db const shorteners = db
.select({ .select({
...shortenerColumns, ...shortenerColumns,
projectName: project.name, projectName: project.name,
projectUuid: project.uuid, projectUuid: project.uuid,
project: { ...projectColumns },
visitorCount: sql<number>`count(${visitor.id})`, visitorCount: sql<number>`count(${visitor.id})`,
}) })
.from(shortener) .from(shortener)

@ -339,9 +339,7 @@
{#each shorteners as shortener} {#each shorteners as shortener}
<ShortenerCard <ShortenerCard
{shortener} {shortener}
projects={data.projects} shortener_url={data.shortener_url} />
shortener_url={data.shortener_url}
settings={data.settings} />
{/each} {/each}
</div> </div>
</ScrollArea> </ScrollArea>

Loading…
Cancel
Save