The Intelligent Edit.
Explore thought-provoking narratives and verified community insights on business, technology, and modern living curated by ACCESCO.
Start Exploring
Explore
${post.category}— ${dateStr}
${post.title}
${post.content.substring(0, 140)}...
${post.blog_likes[0]?.count || 0} ${post.blog_comments[0]?.count || 0}
`;
}).join('');
}
window.publishPost = async () => {
const btn = document.getElementById('publishBtn');
const title = document.getElementById('postTitle').value.trim();
const content = document.getElementById('postContent').value.trim();
if (!title || !content) return alert("Headline and story are required.");
btn.disabled = true; btn.innerText = "Synchronizing...";
let image_url = document.getElementById('imageUrlInput').value.trim();
try {
if (imgSourceMode === 'local' && selectedFile) {
const name = `${Date.now()}-${selectedFile.name.replace(/[^a-zA-Z0-9.]/g, '_')}`;
const { data: stData, error: stError } = await supabase.storage.from('blog-images').upload(name, selectedFile);
if (stError) {
const reader = new FileReader();
image_url = await new Promise(res => { reader.onload = e => res(e.target.result); reader.readAsDataURL(selectedFile); });
} else { image_url = supabase.storage.from('blog-images').getPublicUrl(name).data.publicUrl; }
}
const { error: dbError } = await supabase.from('blogs').insert({
title, content, category: document.getElementById('postCategory').value, image_url, author_name: 'Explorer'
});
if (dbError) throw dbError;
closeWriteModal(); await loadBlogs(true);
} catch (e) { alert("Publication failed. Check Supabase connection."); }
btn.disabled = false; btn.innerText = "Publish to ACCESCO";
};
window.openStory = async (id) => {
activePostId = id; const story = cachedBlogs.find(b => b.id == id); if (!story) return;
const { data: comments } = await supabase.from('blog_comments').select('*').eq('blog_id', id).order('created_at', { ascending: false });
const dateStr = new Date(story.created_at).toLocaleDateString('en-IN', { day:'numeric', month: 'long', year: 'numeric' });
document.getElementById('readCat').innerText = story.category; document.getElementById('readTitle').innerText = story.title;
document.getElementById('readHero').src = story.image_url || 'https://images.unsplash.com/photo-1499750310107-5fef28a66643?w=800';
document.getElementById('readContent').innerText = story.content; document.getElementById('readDate').innerText = dateStr;
document.getElementById('readLikeCount').innerText = story.blog_likes[0]?.count || 0; document.getElementById('readCommCount').innerText = comments?.length || 0;
const liked = JSON.parse(localStorage.getItem('accesco_liked') || '[]');
document.getElementById('readerLikeBtn').classList.toggle('active', liked.includes(id));
document.getElementById('commentList').innerHTML = (comments || []).map(c => ``).join('') || 'No discussions yet.
';
document.getElementById('readerOverlay').style.display = 'block'; document.body.style.overflow = 'hidden';
};
window.handleCardShare = (id, title) => { event.stopPropagation(); const url = window.location.href; if (navigator.share) navigator.share({ title, url }); else { alert("Link copied!"); } };
window.handleShareActive = () => handleCardShare(activePostId, document.getElementById('readTitle').innerText);
window.handleReaderLike = async () => { let liked = JSON.parse(localStorage.getItem('accesco_liked') || '[]'); if (liked.includes(activePostId)) return; liked.push(activePostId); localStorage.setItem('accesco_liked', JSON.stringify(liked)); await supabase.from('blog_likes').insert({ blog_id: activePostId }); document.getElementById('readLikeCount').innerText = parseInt(document.getElementById('readLikeCount').innerText) + 1; document.getElementById('readerLikeBtn').classList.add('active'); loadBlogs(true); };
window.submitComment = async () => { const text = document.getElementById('commText').value.trim(); if (!text) return; await supabase.from('blog_comments').insert({ blog_id: activePostId, content: text }); document.getElementById('commText').value = ""; await loadBlogs(true); openStory(activePostId); };
window.filterBlogs = (cat) => { currentFilter = cat; document.getElementById('currentCategory').innerText = cat === 'All' ? "Explore" : cat; document.querySelectorAll('#navLinks li').forEach(li => li.classList.toggle('active', li.getAttribute('data-cat') === cat)); loadBlogs(false); };
window.openWriteModal = () => { document.getElementById('writeOverlay').style.display = 'block'; document.body.style.overflow = 'hidden'; };
window.closeWriteModal = () => { document.getElementById('writeOverlay').style.display = 'none'; document.getElementById('writePreview').style.display = 'none'; selectedFile = null; document.body.style.overflow = 'auto'; };
window.closeReader = () => { document.getElementById('readerOverlay').style.display = 'none'; document.body.style.overflow = 'auto'; };