shareDialog.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. const html = require('choo/html');
  2. module.exports = function(name, url) {
  3. const dialog = function(state, emit, close) {
  4. return html`
  5. <send-share-dialog
  6. class="flex flex-col items-center text-center p-4 max-w-sm m-auto"
  7. >
  8. <h1 class="text-3xl font-bold my-4">
  9. ${state.translate('notifyUploadEncryptDone')}
  10. </h1>
  11. <p
  12. class="font-normal leading-normal text-grey-80 word-break-all dark:text-grey-40"
  13. >
  14. ${state.translate('shareLinkDescription')}<br />
  15. ${name}
  16. </p>
  17. <input
  18. type="text"
  19. id="share-url"
  20. class="w-full my-4 border-default rounded-lg leading-loose h-12 px-2 py-1 dark:bg-grey-80"
  21. value="${url}"
  22. readonly="true"
  23. />
  24. <button
  25. class="btn rounded-lg w-full flex-shrink-0 focus:outline"
  26. onclick="${share}"
  27. title="${state.translate('shareLinkButton')}"
  28. >
  29. ${state.translate('shareLinkButton')}
  30. </button>
  31. <button
  32. class="link-primary my-4 font-medium cursor-pointer focus:outline"
  33. onclick="${close}"
  34. title="${state.translate('okButton')}"
  35. >
  36. ${state.translate('okButton')}
  37. </button>
  38. </send-share-dialog>
  39. `;
  40. async function share(event) {
  41. event.stopPropagation();
  42. try {
  43. await navigator.share({
  44. title: state.translate('-send-brand'),
  45. text: state.translate('shareMessage', { name }),
  46. url
  47. });
  48. } catch (e) {
  49. if (e.code === e.ABORT_ERR) {
  50. return;
  51. }
  52. console.error(e);
  53. }
  54. close();
  55. }
  56. };
  57. dialog.type = 'share';
  58. return dialog;
  59. };