Skip to content

Commit b0fc068

Browse files
committed
easy peezy
1 parent faa6167 commit b0fc068

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed

public/contacts.vcf

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
BEGIN:VCARD
2+
VERSION:3.0
3+
FN:Alan Poe
4+
N:;Alan Poe;;;
5+
CATEGORIES:myContacts
6+
END:VCARD
7+
BEGIN:VCARD
8+
VERSION:3.0
9+
FN:Jane Doe
10+
N:Doe;Jane;;;
11+
CATEGORIES:myContacts
12+
END:VCARD
13+
BEGIN:VCARD
14+
VERSION:3.0
15+
FN:John Smith
16+
N:Smith;John;;;
17+
CATEGORIES:myContacts
18+
END:VCARD

src/App.svelte

+27-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<script>
2-
import "./Tailwindcss.svelte";
3-
import ContactCard from "./ContactCard.svelte";
2+
import { fly } from "svelte/transition";
43
import vCard from "vcf";
54
import cntl from "cntl";
5+
6+
import "./Tailwindcss.svelte";
7+
import ContactCard from "./ContactCard.svelte";
68
import UploadIcon from "./UploadIcon.svelte";
79
import DownloadIcon from "./DownloadIcon.svelte";
8-
import { fly } from "svelte/transition";
910
1011
const fReader = new FileReader();
1112
/**@type {vCard[]} */
@@ -53,7 +54,6 @@
5354
contacts[cIndex] = c
5455
});
5556
if(contacts.length > 1) {
56-
console.log(contacts.map(c => c.toString()).join("\r\n"))
5757
const updatedContacts = contacts.map(c => c.toString()).join("\r\n")
5858
updateFileUrl = "data:text/plain;charset=utf-8," + encodeURIComponent(updatedContacts)
5959
}
@@ -62,6 +62,16 @@
6262
}
6363
}
6464
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+
6575
fReader.onload = (e) => {
6676
if (e.target.readyState != 2) return;
6777
try {
@@ -101,12 +111,23 @@
101111
type="file"
102112
class="hidden"
103113
on:change={(e) => fReader.readAsText(e.target.files[0])}
104-
accept=".vcf" />
114+
accept=".vcf,text/vcard" />
105115
</label>
106116
</div>
107117
<p class="block text-sm py-4">
108118
Only contacts without photos will be loaded.
109119
</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>
110131
</div>
111132
{/if}
112133
<div
@@ -128,6 +149,7 @@
128149
hover:scale-110 hover:shadow-2xl fixed
129150
fab focus:outline-none`}
130151
href={updateFileUrl}
152+
title="Download updated vCard file."
131153
download="newcontacts.vcf">
132154
<DownloadIcon />
133155
</a>

src/ContactCard.svelte

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<script>
22
import "a-avataaar";
3-
import { blur } from "svelte/transition";
3+
import Canvg from "canvg";
44
import cntl from "cntl";
5+
import { blur } from "svelte/transition";
56
import { onMount, createEventDispatcher } from "svelte";
7+
68
import { updateSVgWithStyle } from "./utils";
7-
import Canvg from "canvg";
89
import DownloadIcon from "./DownloadIcon.svelte";
910
1011
const dispatch = createEventDispatcher();

0 commit comments

Comments
 (0)