card: кнопка «Добавить в контакты» + надёжное открытие vCard на iOS
This commit is contained in:
@@ -55,15 +55,21 @@ export function CardPage() {
|
||||
if (b64 && b64.length < 60000) lines.push(`PHOTO;ENCODING=b;TYPE=${type}:${b64}`);
|
||||
}
|
||||
lines.push('END:VCARD');
|
||||
const vcard = lines.join('\r\n');
|
||||
try {
|
||||
const blob = new Blob([lines.join('\r\n')], { type: 'text/vcard;charset=utf-8' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url; a.download = `${card.slug}.vcf`;
|
||||
document.body.appendChild(a); a.click(); a.remove();
|
||||
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
||||
toast('Контакт сохранён ✓');
|
||||
} catch { toast('Откройте на телефоне для сохранения'); }
|
||||
const isIOS = /iP(hone|ad|od)/.test(navigator.userAgent);
|
||||
if (isIOS) {
|
||||
window.location.href = 'data:text/vcard;charset=utf-8,' + encodeURIComponent(vcard);
|
||||
} else {
|
||||
const blob = new Blob([vcard], { type: 'text/vcard;charset=utf-8' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url; a.download = `${card.slug}.vcf`;
|
||||
document.body.appendChild(a); a.click(); a.remove();
|
||||
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
||||
}
|
||||
toast('Открываю карточку контакта…');
|
||||
} catch { toast('Не удалось открыть'); }
|
||||
}
|
||||
function toast(msg: string) {
|
||||
const t = document.getElementById('cp-toast');
|
||||
@@ -120,7 +126,7 @@ export function CardPage() {
|
||||
|
||||
<button className="save reveal d5" onClick={saveContact}>
|
||||
<svg width="19" height="19" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2" /><circle cx="12" cy="7" r="4" /></svg>
|
||||
Сохранить контакт
|
||||
Добавить в контакты
|
||||
</button>
|
||||
|
||||
{card.product_title && (
|
||||
|
||||
Reference in New Issue
Block a user