-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.vue
60 lines (54 loc) · 1.68 KB
/
app.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<template >
<Head>
<Title>urlshort.gdwr.me</Title>
<Meta name="description" content="Url shortener" />
</Head>
<div class="w-screen h-screen dark:bg-gray-900">
<LightSwitch />
<UNotifications />
<main class="flex flex-col">
<div class="flex flex-col mx-auto my-80">
<h1 class="text-primary text-4xl p-8 underline md:text-6xl"> urlshort.gdwr.me </h1>
<UButtonGroup size="xl" orientation="horizontal" class="mx-auto">
<UInput placeholder="Enter your url here!" v-model="url" />
<UTooltip text="Create shortend URL" >
<UButton icon="i-heroicons-plus" color="gray" @click="createUrl()" />
</UTooltip>
</UButtonGroup>
<ShortensCounter />
</div>
</main>
<footer class="flex">
<a class="m-auto link underline text-primary" href="https://github.com/gdwr/urlshort"> See the source </a>
</footer>
</div>
</template>
<script setup lang="ts">
const url = ref("");
const toast = useToast();
async function createUrl() {
var response = await $fetch<{url: string}>("/api/shorten", {
method: "POST",
body: JSON.stringify({
url: url.value,
}),
onResponseError: async (context) => {
var body = await context.response._data;
var errors = body.error;
toast.add({
title: 'Error!',
color: 'red',
description: errors[0].message,
});
},
});
toast.add({
title: 'Url Shortened!',
color: 'green',
actions: [
{label: 'Copy', click: () => navigator.clipboard.writeText(response.url) },
{label: 'Goto', click: () => window.open(response.url, '_blank') },
]
});
}
</script>