diff --git a/static/css/components/recipe-card.css b/static/css/components/recipe-card.css index ef821cb8..7e359bc8 100644 --- a/static/css/components/recipe-card.css +++ b/static/css/components/recipe-card.css @@ -44,7 +44,7 @@ .recipe-indicator { position: absolute; - top: 8px; + top: 6px; left: 8px; width: 24px; height: 24px; diff --git a/static/js/components/RecipeCard.js b/static/js/components/RecipeCard.js index 6488fbd1..dbf2c9f0 100644 --- a/static/js/components/RecipeCard.js +++ b/static/js/components/RecipeCard.js @@ -78,8 +78,7 @@ class RecipeCard { // Share button click event - prevent propagation to card card.querySelector('.fa-share-alt')?.addEventListener('click', (e) => { e.stopPropagation(); - // TODO: Implement share functionality - showToast('Share functionality will be implemented later', 'info'); + this.shareRecipe(); }); // Copy button click event - prevent propagation to card @@ -232,6 +231,34 @@ class RecipeCard { deleteBtn.disabled = false; }); } + + shareRecipe() { + try { + // Get the image URL + const imageUrl = this.recipe.file_url || + (this.recipe.file_path ? `/loras_static/root1/preview/${this.recipe.file_path.split('/').pop()}` : + '/loras_static/images/no-preview.png'); + + // Create a temporary anchor element + const downloadLink = document.createElement('a'); + downloadLink.href = imageUrl; + + // Set the download attribute with the recipe title as filename + const fileExtension = imageUrl.split('.').pop(); + const safeFileName = this.recipe.title.replace(/[^a-z0-9]/gi, '_').toLowerCase(); + downloadLink.download = `recipe_${safeFileName}.${fileExtension}`; + + // Append to body, click and remove + document.body.appendChild(downloadLink); + downloadLink.click(); + document.body.removeChild(downloadLink); + + showToast('Recipe image download started', 'success'); + } catch (error) { + console.error('Error sharing recipe:', error); + showToast('Error downloading recipe image', 'error'); + } + } } export { RecipeCard }; \ No newline at end of file