Support Independent Journalism
If you found this story valuable, consider supporting TheWkly to help us continue delivering quality news.
// Function to create a roadmap using our consolidated approach
function createRoadmap(storyId) {
// Show a loading indicator
const loadingHtml = `
Creating your roadmap...
This may take a moment
`;
document.body.insertAdjacentHTML('beforeend', loadingHtml);
// Make the API call to create the roadmap using the enhanced unified approach
fetch(`/api/roadmaps/create/${storyId}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': 'Ijg2ODE5MmZhNjc3OGIxOTk5NWEzM2RjZmE0ZTFkODAyOTc1N2YzNmYi.abEq0A.7ctvyz5T85C017TXWV33mjj8Vr4'
}
})
.then(response => response.json())
.then(data => {
// Remove the loading indicator
document.getElementById('loading-overlay').remove();
if (data.success) {
// Show success message
const successHtml = `
Roadmap Created!
Your learning path has been successfully created.
`;
document.body.insertAdjacentHTML('beforeend', successHtml);
} else {
// Show error message
const errorHtml = `
Error
${data.message || 'An error occurred while creating the roadmap.'}
Close
`;
document.body.insertAdjacentHTML('beforeend', errorHtml);
}
})
.catch(error => {
// Remove the loading indicator
document.getElementById('loading-overlay').remove();
// Show error message
const errorHtml = `
Error
An unexpected error occurred. Please try again later.
Close
`;
document.body.insertAdjacentHTML('beforeend', errorHtml);
console.error('Error creating roadmap:', error);
});
}
document.addEventListener('DOMContentLoaded', function() {
// Auto-mark as read after 10 seconds
// Function to load related roadmaps
function loadRelatedRoadmaps() {
// Load related roadmaps for this story
console.log('Loading related roadmaps for story ID: 3670');
fetch('/api/stories/3670/related-roadmaps')
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
})
.then(data => {
console.log('Related roadmaps API response:', data);
const container = document.getElementById('roadmaps-container');
if (!container) {
console.error('Roadmaps container not found in DOM');
return;
}
// Clear the loading indicator
container.innerHTML = '';
if (data.roadmaps && data.roadmaps.length > 0) {
console.log(`Found ${data.roadmaps.length} roadmaps to display`);
// Render each roadmap card
data.roadmaps.forEach(roadmap => {
console.log(`Processing roadmap ID ${roadmap.id}: ${roadmap.title}`);
const card = document.createElement('div');
card.className = 'p-4 bg-white rounded-lg border border-blue-200 hover:shadow-md transition-shadow';
let iconType = 'map';
if (roadmap.type === 'career') iconType = 'briefcase';
else if (roadmap.type === 'personal') iconType = 'user';
else if (roadmap.type === 'learning') iconType = 'graduation-cap';
else if (roadmap.type === 'financial') iconType = 'chart-line';
card.innerHTML = `
${roadmap.title}
${roadmap.description || 'Interactive step-by-step guide'}
${roadmap.step_count ? ` ${roadmap.step_count} steps ` : ''}
${roadmap.created_by ? ` ${roadmap.created_by} ` : ''}
`;
container.appendChild(card);
});
} else {
console.log('No roadmaps found for this story');
// Show "no roadmaps" message with different content for logged in vs not logged in users
const isLoggedIn = false;
if (isLoggedIn) {
container.innerHTML = `
No roadmaps found for this story yet.
Be the first to create one!
`;
} else {
container.innerHTML = `
Create your own roadmaps!
Sign up to create interactive step-by-step guides for this story and others.
`;
}
}
})
.catch(error => {
console.error('Error loading roadmaps:', error);
const container = document.getElementById('roadmaps-container');
if (container) {
container.innerHTML = `
Unable to load roadmaps at this time.
Error: ${error.message}
`;
}
});
}
// Load roadmaps when page loads
loadRelatedRoadmaps();
// Check for "roadmap_created" or "roadmap_updated" URL parameter and reload roadmaps if present
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('roadmap_created') || urlParams.has('roadmap_updated')) {
// Small delay to ensure the UI is ready
setTimeout(loadRelatedRoadmaps, 500);
}
// Add event listeners to roadmap creation links to append return parameters
document.querySelectorAll('a[href*="create_roadmap_from_story"], a[href*="create-roadmap-from-plan"]').forEach(link => {
link.addEventListener('click', function(e) {
// Store the current URL to return to this page
const returnUrl = window.location.href.split('?')[0] + '?roadmap_created=true';
// Store in sessionStorage
sessionStorage.setItem('roadmapReturnUrl', returnUrl);
});
});
// Handle reaction buttons
const reactionButtons = document.querySelectorAll('.reaction-btn');
reactionButtons.forEach(button => {
button.addEventListener('click', function() {
const reaction = this.dataset.reaction;
const storyId = this.dataset.storyId;
// Send reaction to server
fetch(`/api/stories/${storyId}/reactions`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': 'Ijg2ODE5MmZhNjc3OGIxOTk5NWEzM2RjZmE0ZTFkODAyOTc1N2YzNmYi.abEq0A.7ctvyz5T85C017TXWV33mjj8Vr4'
},
body: JSON.stringify({
reaction_type: reaction
})
})
.then(response => response.json())
.then(data => {
if (data.success) {
// Toggle active state
if (data.added) {
this.classList.add('border-blue-500', 'bg-blue-50', 'text-blue-700');
} else {
this.classList.remove('border-blue-500', 'bg-blue-50', 'text-blue-700');
}
// Update count if available
const countElement = this.querySelector('.reaction-count');
if (data.count > 0) {
if (countElement) {
countElement.textContent = `(${data.count})`;
} else {
const countSpan = document.createElement('span');
countSpan.className = 'reaction-count';
countSpan.textContent = `(${data.count})`;
const textElement = this.querySelector('span:not(.text-lg)');
textElement.appendChild(countSpan);
}
} else if (countElement) {
countElement.remove();
}
}
})
.catch(error => {
console.error('Error updating reaction:', error);
});
});
});
});
TheWkly
The most relevant news delivered in a concise format, so you can stay informed without being overwhelmed.
Subscribe
Get the latest news delivered right to your inbox.
Subscribe Now
© 2026 TheWkly. All rights reserved.
We use cookies to analyze site traffic and improve your experience. By clicking Accept, you consent to our use of analytics cookies.
Privacy Policy
Decline
Accept