aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/qr/create/+page.svelte
blob: 74316ba958e72bdb2acfad281b28b879060df450 (plain) (blame)
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
61
62
63
64
<script>
  import { run, preventDefault } from 'svelte/legacy';

  import { goto } from "$app/navigation";
  import { browser } from "$app/environment";
  import { t } from "$lib/translations";
  import Icon from "$comp/Icon.svelte";
  let el = $state(), text = $state(), pasted = $state();

  let keypress = (e) =>
    e.key === "Enter" ? e.preventDefault() || el.click() : (pasted = false);

  let paste = async () => {
    text = await navigator.clipboard.readText();
    pasted = true;
  };

  let submit = () => goto(`/qr/${encodeURIComponent(text)}`);

  run(() => {
    if (browser && pasted && text) el.click() && (pasted = false);
  });
</script>

<div class="container px-4 max-w-lg mx-auto space-y-5 mt-20">
  <h1 class="px-3 md:px-0 text-center text-3xl md:text-4xl font-semibold">
    Create QR
  </h1>

  <form onsubmit={preventDefault(submit)} class="space-y-2 text-xl">
    <div class="mb-2">
      <textarea
        use:focus
        name="text"
        placeholder="Enter some text or a URL to put in a QR"
        onkeypress={keypress}
        class="w-full p-4 border rounded-xl h-32 text-xl"
        bind:value={text}
        onpaste={() => (pasted = true)}
        autocapitalize="none"
></textarea>
    </div>

    <div class="flex gap-2">
      <button
        type="button"
        class="flex border rounded-2xl px-6 py-5 font-bold hover:opacity-80 w-full bg-primary justify-center gap-2"
        onclick={paste}
      >
        <Icon icon="paste" style="w-8 my-auto" />
        <div class="my-auto">{$t("user.send.paste")}</div>
      </button>

      <button
        bind:this={el}
        type="submit"
        class="flex bg-black text-white border rounded-2xl px-6 py-5 w-full font-bold gap-2 justify-center"
      >
        <Icon icon="send" style="w-8 my-auto invert" />
        <div class="my-auto">{$t("user.dashboard.go")}</div>
      </button>
    </div>
  </form>
</div>