|
|
|
@ -1,12 +1,16 @@
|
|
|
|
<script lang="ts">
|
|
|
|
<script lang="ts">
|
|
|
|
import * as Dialog from '$lib/components/ui/dialog'
|
|
|
|
import * as Dialog from '$lib/components/ui/dialog'
|
|
|
|
|
|
|
|
import * as Select from '$lib/components/ui/select'
|
|
|
|
import { Button, buttonVariants } from '$lib/components/ui/button'
|
|
|
|
import { Button, buttonVariants } from '$lib/components/ui/button'
|
|
|
|
import { Input } from '$lib/components/ui/input'
|
|
|
|
import { Input } from '$lib/components/ui/input'
|
|
|
|
import { Label } from '$lib/components/ui/label'
|
|
|
|
import { Label } from '$lib/components/ui/label'
|
|
|
|
import { Loader2, PlusCircle } from 'lucide-svelte'
|
|
|
|
import { Loader2, PlusCircle } from 'lucide-svelte'
|
|
|
|
import { invalidateAll } from '$app/navigation'
|
|
|
|
import { invalidateAll } from '$app/navigation'
|
|
|
|
import { toast } from 'svelte-sonner'
|
|
|
|
import { toast } from 'svelte-sonner'
|
|
|
|
|
|
|
|
import type { PageData } from '../$types'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let data: PageData
|
|
|
|
|
|
|
|
export let projects: typeof data.projects
|
|
|
|
export let dialogOpen: boolean
|
|
|
|
export let dialogOpen: boolean
|
|
|
|
let inputLink = ''
|
|
|
|
let inputLink = ''
|
|
|
|
let isLoading = false
|
|
|
|
let isLoading = false
|
|
|
|
@ -16,7 +20,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
const response = await fetch('/api/shortener', {
|
|
|
|
const response = await fetch('/api/shortener', {
|
|
|
|
method: 'post',
|
|
|
|
method: 'post',
|
|
|
|
body: JSON.stringify({ link: inputLink }),
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
|
|
|
link: inputLink,
|
|
|
|
|
|
|
|
projectId: shortenerCategory
|
|
|
|
|
|
|
|
? shortenerCategory.value
|
|
|
|
|
|
|
|
: undefined,
|
|
|
|
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const responseData = await response.json()
|
|
|
|
const responseData = await response.json()
|
|
|
|
@ -31,8 +40,9 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let inputTimer: any
|
|
|
|
let inputTimer: any
|
|
|
|
let data: any
|
|
|
|
let previewData: any
|
|
|
|
let isPreviewLoading: boolean = false
|
|
|
|
let isPreviewLoading: boolean = false
|
|
|
|
|
|
|
|
let shortenerCategory: any = undefined
|
|
|
|
|
|
|
|
|
|
|
|
const getMetadata = async () => {
|
|
|
|
const getMetadata = async () => {
|
|
|
|
isPreviewLoading = true
|
|
|
|
isPreviewLoading = true
|
|
|
|
@ -41,9 +51,9 @@
|
|
|
|
const response = await fetch(
|
|
|
|
const response = await fetch(
|
|
|
|
`/api/url/metadata?url=${inputLink}`,
|
|
|
|
`/api/url/metadata?url=${inputLink}`,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
data = await response.json()
|
|
|
|
previewData = await response.json()
|
|
|
|
isPreviewLoading = false
|
|
|
|
isPreviewLoading = false
|
|
|
|
console.log(data)
|
|
|
|
console.log(previewData)
|
|
|
|
}, 1000)
|
|
|
|
}, 1000)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|
@ -71,6 +81,22 @@
|
|
|
|
placeholder="https://example.com"
|
|
|
|
placeholder="https://example.com"
|
|
|
|
class="col-span-3" />
|
|
|
|
class="col-span-3" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="grid grid-cols-4 items-center gap-4">
|
|
|
|
|
|
|
|
<Label>Category</Label>
|
|
|
|
|
|
|
|
<Select.Root
|
|
|
|
|
|
|
|
bind:selected={shortenerCategory}
|
|
|
|
|
|
|
|
multiple={false}>
|
|
|
|
|
|
|
|
<Select.Trigger class="col-span-3">
|
|
|
|
|
|
|
|
<Select.Value placeholder="Select a Category" />
|
|
|
|
|
|
|
|
</Select.Trigger>
|
|
|
|
|
|
|
|
<Select.Content>
|
|
|
|
|
|
|
|
{#each projects as project}
|
|
|
|
|
|
|
|
<Select.Item value={project.id}
|
|
|
|
|
|
|
|
>{project.name}</Select.Item>
|
|
|
|
|
|
|
|
{/each}
|
|
|
|
|
|
|
|
</Select.Content>
|
|
|
|
|
|
|
|
</Select.Root>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<div class="grid grid-cols-4 items-center gap-4">
|
|
|
|
<div class="grid grid-cols-4 items-center gap-4">
|
|
|
|
<div class="font-bold">Preview</div>
|
|
|
|
<div class="font-bold">Preview</div>
|
|
|
|
<div class="col-span-4 flex flex-col justify-center border">
|
|
|
|
<div class="col-span-4 flex flex-col justify-center border">
|
|
|
|
@ -79,14 +105,14 @@
|
|
|
|
<div class="flex h-full items-center justify-center">
|
|
|
|
<div class="flex h-full items-center justify-center">
|
|
|
|
<Loader2 class="animate-spin" />
|
|
|
|
<Loader2 class="animate-spin" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{:else if data}
|
|
|
|
{:else if previewData}
|
|
|
|
<img
|
|
|
|
<img
|
|
|
|
src={data.image}
|
|
|
|
src={previewData.image}
|
|
|
|
alt=""
|
|
|
|
alt=""
|
|
|
|
class="h-64 w-full object-cover" />
|
|
|
|
class="h-64 w-full object-cover" />
|
|
|
|
<div
|
|
|
|
<div
|
|
|
|
class="bg-secondary absolute bottom-2 left-2 rounded-lg px-2">
|
|
|
|
class="absolute bottom-2 left-2 rounded-lg bg-secondary px-2">
|
|
|
|
{data.title}
|
|
|
|
{previewData.title}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|