Bladeren bron

Add functionality to copy link

Lee Morgan 1 week geleden
bovenliggende
commit
f3ee976a3b
1 gewijzigde bestanden met toevoegingen van 8 en 3 verwijderingen
  1. 8 3
      src/routes/recipe/[recipeId]/+page.svelte

+ 8 - 3
src/routes/recipe/[recipeId]/+page.svelte

@@ -18,6 +18,11 @@
         notify("warning", "Recipe mode off.")
     }
 
+    const copyLink = ()=>{
+        navigator.clipboard.writeText(`https://${location.hostname}/recipe/${data.recipe.id}`);
+        notify("success", "Link copied to clipboard");
+    }
+
     onMount(()=>{
         const stop = attachVisibilityReacquire(()=>on);
 
@@ -78,9 +83,9 @@
             >Share</button>
             {#if shareOpen}
                 <div class="shareMenu" role="menu">
-                    <button type="button" role="menuitem">Copy link</button>
-                    <button type="button" role="menuitem">Print</button>
-                    <button type="button" role="menuitem">Download</button>
+                    <button role="menuitem" onclick={copyLink}>Copy link</button>
+                    <button role="menuitem">Print</button>
+                    <button role="menuitem">Download</button>
                 </div>
             {/if}
         </div>