|
1 | 1 | <script>
|
2 |
| - import "./Tailwindcss.svelte"; |
3 |
| - import ContactCard from "./ContactCard.svelte"; |
| 2 | + import { fly } from "svelte/transition"; |
4 | 3 | import vCard from "vcf";
|
5 | 4 | import cntl from "cntl";
|
| 5 | +
|
| 6 | + import "./Tailwindcss.svelte"; |
| 7 | + import ContactCard from "./ContactCard.svelte"; |
6 | 8 | import UploadIcon from "./UploadIcon.svelte";
|
7 | 9 | import DownloadIcon from "./DownloadIcon.svelte";
|
8 |
| - import { fly } from "svelte/transition"; |
9 | 10 |
|
10 | 11 | const fReader = new FileReader();
|
11 | 12 | /**@type {vCard[]} */
|
|
53 | 54 | contacts[cIndex] = c
|
54 | 55 | });
|
55 | 56 | if(contacts.length > 1) {
|
56 |
| - console.log(contacts.map(c => c.toString()).join("\r\n")) |
57 | 57 | const updatedContacts = contacts.map(c => c.toString()).join("\r\n")
|
58 | 58 | updateFileUrl = "data:text/plain;charset=utf-8," + encodeURIComponent(updatedContacts)
|
59 | 59 | }
|
|
62 | 62 | }
|
63 | 63 | }
|
64 | 64 |
|
| 65 | + const setSample = async () => { |
| 66 | + try { |
| 67 | + const res = await fetch('/contacts.vcf') |
| 68 | + const sampleStr = await res.text() |
| 69 | + contacts = vCard.parse(sampleStr) |
| 70 | + } catch(error) { |
| 71 | + console.error(error) |
| 72 | + } |
| 73 | + } |
| 74 | +
|
65 | 75 | fReader.onload = (e) => {
|
66 | 76 | if (e.target.readyState != 2) return;
|
67 | 77 | try {
|
|
101 | 111 | type="file"
|
102 | 112 | class="hidden"
|
103 | 113 | on:change={(e) => fReader.readAsText(e.target.files[0])}
|
104 |
| - accept=".vcf" /> |
| 114 | + accept=".vcf,text/vcard" /> |
105 | 115 | </label>
|
106 | 116 | </div>
|
107 | 117 | <p class="block text-sm py-4">
|
108 | 118 | Only contacts without photos will be loaded.
|
109 | 119 | </p>
|
| 120 | + <hr class="mb-5 shadow-sm"/> |
| 121 | + <div> |
| 122 | + <button |
| 123 | + name="sample" |
| 124 | + class="hover:underline hover:text-red-600 text-sm focus:outline-none" |
| 125 | + title="Load a sample vcard" |
| 126 | + on:click={setSample} |
| 127 | + > |
| 128 | + ↘️ Use sample contacts |
| 129 | + </button> |
| 130 | + </div> |
110 | 131 | </div>
|
111 | 132 | {/if}
|
112 | 133 | <div
|
|
128 | 149 | hover:scale-110 hover:shadow-2xl fixed
|
129 | 150 | fab focus:outline-none`}
|
130 | 151 | href={updateFileUrl}
|
| 152 | + title="Download updated vCard file." |
131 | 153 | download="newcontacts.vcf">
|
132 | 154 | <DownloadIcon />
|
133 | 155 | </a>
|
|
0 commit comments