Added code to createurl component

This commit is contained in:
Nicolai Ort 2021-08-21 17:05:36 +02:00
parent 3a82caad95
commit 59a411bab5
Signed by: niggl
GPG Key ID: 13AFA55AF62F269F
1 changed files with 122 additions and 110 deletions

View File

@ -1,111 +1,123 @@
<script> <script>
import Apiclient from "./Apiclient"; import Apiclient from './Apiclient';
$: targetUrl = '';
$: targetUrl = ''; $: customShortcode = '';
$: customShortcode = ''; $: shortcode = '';
$: shortcode = ''; $: error = '';
$: error = '';
function createUrl() {
function createUrl() { console.log('here');
console.log("here") Apiclient.createUrl(targetUrl, shortcode).then((res) => {
Apiclient.createUrl(targetUrl, shortcode).then((res)=>{ console.log(res);
console.log(res) if (res.status != 200) {
if(res.status != 200){ error = res.data;
error = res.data; } else {
} shortcode = res.data.shortcode;
else{ }
shortcode = res.data.shortcode; });
} }
});
} function resetInput() {
error = '';
function reset() { shortcode = '';
error = ''; customShortcode = '';
shortcode = ''; targetUrl = '';
customShortcode = ''; }
targetUrl = ''; </script>
}
</script> <h2 class="text-center text-2xl font-bold text-gray-800 dark:text-gray-100 pb-3">Create new url</h2>
{#if error != ''}
<h2 class="text-center text-2xl font-bold text-gray-800 dark:text-gray-100 pb-3">Create new url</h2> <div class="rounded-md bg-red-100 p-4 hidden" id="error_container">
{#if error != ""} <div class="flex">
<div class="rounded-md bg-red-100 p-4 hidden" id="error_container"> <div class="flex-shrink-0">
<div class="flex"> <svg
<div class="flex-shrink-0"> xmlns="http://www.w3.org/2000/svg"
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-red-600" viewBox="0 0 20 20" class="h-5 w-5 text-red-600"
fill="currentColor"> viewBox="0 0 20 20"
<path fill-rule="evenodd" fill="currentColor"
d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z" >
clip-rule="evenodd" /> <path
</svg> fill-rule="evenodd"
</div> d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z"
<div class="ml-3"> clip-rule="evenodd"
<p class="text-sm font-medium text-red-800" id="error_text"> />
{error} </svg>
</p> </div>
</div> <div class="ml-3">
<div class="ml-auto pl-3"> <p class="text-sm font-medium text-red-800" id="error_text">
<div class="-mx-1.5 -my-1.5"> {error}
<button </p>
on:click={()=>{ </div>
error=''; <div class="ml-auto pl-3">
}} <div class="-mx-1.5 -my-1.5">
class="inline-flex bg-red-100 rounded-md p-1.5 text-red-500 hover:bg-red-100 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-red-50 focus:ring-red-600"> <button
<span class="sr-only">Dismiss</span> on:click={() => {
<svg class="h-5 w-5" x-description="Heroicon name: x" xmlns="http://www.w3.org/2000/svg" error = '';
viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"> }}
<path fill-rule="evenodd" class="inline-flex bg-red-100 rounded-md p-1.5 text-red-500 hover:bg-red-100 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-red-50 focus:ring-red-600"
d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" >
clip-rule="evenodd"></path> <span class="sr-only">Dismiss</span>
</svg> <svg
</button> class="h-5 w-5"
</div> x-description="Heroicon name: x"
</div> xmlns="http://www.w3.org/2000/svg"
</div> viewBox="0 0 20 20"
</div> fill="currentColor"
{/if} aria-hidden="true"
{#if shortcode == ''} >
<div> <path
<div class="mx-auto lg:w-1/3 w-full mt-1 flex rounded-md shadow-sm"> fill-rule="evenodd"
<input d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
type="url" clip-rule="evenodd"
required />
class="flex-1 min-w-0 block border rounded-lg px-3 py-2 focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm border-gray-300 bg-gray-50 dark:bg-gray-800 dark:text-gray-200 dark:border-gray-600" </svg>
placeholder="https://target.url" </button>
/> </div>
</div> </div>
<div class="mt-1 flex rounded-md shadow-sm mx-auto lg:w-1/3 w-full"> </div>
<span </div>
class="inline-flex items-center px-3 rounded-l-md border border-r-0 border-gray-300 bg-gray-50 dark:bg-gray-900 dark:text-gray-300 text-gray-500 sm:text-sm dark:border-gray-600" {/if}
> {#if shortcode == ''}
https://kauf.es/ <div>
</span> <div class="mx-auto lg:w-1/3 w-full mt-1 flex rounded-md shadow-sm">
<input <input
type="text" type="url"
class="flex-1 min-w-0 block w-full px-3 py-2 border-t border-b border-r rounded-none rounded-r-md focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm border-gray-300 dark:bg-gray-800 dark:text-gray-200 dark:border-gray-600" required
placeholder="custom_code" class="flex-1 min-w-0 block border rounded-lg px-3 py-2 focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm border-gray-300 bg-gray-50 dark:bg-gray-800 dark:text-gray-200 dark:border-gray-600"
/> placeholder="https://target.url"
</div> />
</div> </div>
{:else} <div class="mt-1 flex rounded-md shadow-sm mx-auto lg:w-1/3 w-full">
<!-- TODO: --> <span
{/if} class="inline-flex items-center px-3 rounded-l-md border border-r-0 border-gray-300 bg-gray-50 dark:bg-gray-900 dark:text-gray-300 text-gray-500 sm:text-sm dark:border-gray-600"
<div class="mt-3 mx-auto text-center lg:w-1/3 w-full"> >
{#if shortcode == ''} https://kauf.es/
<button </span>
on:click={createUrl} <input
class="px-4 py-2 font-medium tracking-wide text-white capitalize transition-colors duration-200 transform bg-blue-600 rounded-md dark:bg-gray-900 hover:bg-blue-500 dark:hover:bg-gray-700 focus:outline-none focus:bg-blue-500 dark:focus:bg-gray-700" type="text"
> class="flex-1 min-w-0 block w-full px-3 py-2 border-t border-b border-r rounded-none rounded-r-md focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm border-gray-300 dark:bg-gray-800 dark:text-gray-200 dark:border-gray-600"
Create shorturl placeholder="custom_code"
</button> />
{:else} </div>
<button </div>
on:click={reset} {:else}
class="px-4 py-2 font-medium tracking-wide text-white capitalize transition-colors duration-200 transform bg-blue-600 rounded-md dark:bg-gray-900 hover:bg-blue-500 dark:hover:bg-gray-700 focus:outline-none focus:bg-blue-500 dark:focus:bg-gray-700" <!-- TODO: -->
> {/if}
Add another url <div class="mt-3 mx-auto text-center lg:w-1/3 w-full">
</button> {#if shortcode == ''}
{/if} <button
</div> on:click={createUrl}
class="px-4 py-2 font-medium tracking-wide text-white capitalize transition-colors duration-200 transform bg-blue-600 rounded-md dark:bg-gray-900 hover:bg-blue-500 dark:hover:bg-gray-700 focus:outline-none focus:bg-blue-500 dark:focus:bg-gray-700"
>
Create shorturl
</button>
{:else}
<button
on:click={resetInput}
class="px-4 py-2 font-medium tracking-wide text-white capitalize transition-colors duration-200 transform bg-blue-600 rounded-md dark:bg-gray-900 hover:bg-blue-500 dark:hover:bg-gray-700 focus:outline-none focus:bg-blue-500 dark:focus:bg-gray-700"
>
Add another url
</button>
{/if}
</div>