diff --git a/script.js b/script.js
index 6dd6b94..4aa5986 100644
--- a/script.js
+++ b/script.js
@@ -127,6 +127,8 @@ async function toggleLike(id) {
} else {
APP.userLikes = APP.userLikes.filter(x => x !== id);
}
+ // Persist to localStorage so likes survive session expiry
+ saveLocalLikes(APP.userLikes);
// Update all like buttons for this post (card + modal)
document.querySelectorAll(`[data-like-id="${id}"]`).forEach(btn => {
@@ -247,7 +249,10 @@ async function openPost(id) {
const stps = p.steps?.length
? `
${p.steps.map(s => `- ${s}
`).join('')}
`
: `${t('no_steps')}
`;
- bodyHTML = `${t('modal_ingredients')}
${ings}${t('modal_steps')}
${stps}`;
+ const copyBtn = p.ingredients?.length
+ ? ``
+ : '';
+ bodyHTML = `${t('modal_ingredients')}
${copyBtn}${ings}${t('modal_steps')}
${stps}`;
} else {
bodyHTML = `${p.body || p.desc}
`;
}
@@ -557,6 +562,29 @@ function handleSubmit(e) {
// ===========================
// INIT
+// ===========================
+// COPY INGREDIENTS
+// ===========================
+function copyIngredients(postId) {
+ const p = APP.posts.find(x => x.id === postId);
+ if (!p?.ingredients?.length) return;
+ const text = p.title + '\n\nOstoslista:\n' + p.ingredients.map(i => '• ' + i).join('\n');
+ navigator.clipboard.writeText(text).then(() => {
+ const btn = document.querySelector('.copy-list-btn');
+ if (btn) { btn.textContent = '✅ Kopioitu!'; setTimeout(() => { btn.textContent = '📋 Kopioi ostoslista'; }, 2000); }
+ }).catch(() => {});
+}
+
+// ===========================
+// LOCAL LIKES PERSISTENCE
+// ===========================
+function getLocalLikes() {
+ try { return JSON.parse(localStorage.getItem('tykkaafi_likes') || '[]'); } catch { return []; }
+}
+function saveLocalLikes(arr) {
+ try { localStorage.setItem('tykkaafi_likes', JSON.stringify(arr)); } catch {}
+}
+
// ===========================
async function init() {
try {
@@ -568,7 +596,10 @@ async function init() {
APP.posts = postsData.posts || [];
APP.categories = catsData.categories || [];
APP.likes = likesData.likes || {};
- APP.userLikes = likesData.userLikes || [];
+ // Merge server session likes with localStorage — remember likes across sessions
+ const serverLikes = likesData.userLikes || [];
+ const localLikes = getLocalLikes();
+ APP.userLikes = [...new Set([...serverLikes, ...localLikes])];
} catch (e) {
console.error('API virhe:', e);
}