// filename: Member Dashboard (Page Code)
import wixData from 'wix-data';
import wixUsers from 'wix-users';
$w.onReady(function () {
// Load member info and progress
loadMemberData();
});
async function loadMemberData() {
// Get current logged-in user
const user = wixUsers.currentUser;
if (!user.loggedIn) {
// Redirect to login if not logged in
wixLocation.to('/login');
return;
}
const userEmail = await user.getEmail();
const userName = await user.loggedIn ? (await wixUsers.currentUser.getProp('name')) : 'Student';
// Display welcome message
$w('#welcomeText').text = `Welcome back, ${userName}!`;
// Load progress for each module
const modules = [
{ name: 'Fundamentals of Electricity', btnId: '#launchBtn1', progressId: '#progressBar1' },
{ name: 'Fundamentals of Maintenance', btnId: '#launchBtn2', progressId: '#progressBar2' },
{ name: 'Avionics Systems', btnId: '#launchBtn3', progressId: '#progressBar3' }
];
for (let module of modules) {
const progress = await getModuleProgress(userEmail, module.name);
// Update progress bar
if ($w(module.progressId)) {
$w(module.progressId).targetValue = progress.percent;
$w(module.progressId).value = progress.percent;
}
// Update button text based on progress
const btnText = progress.percent === 0 ? '▶ Start Module' :
progress.percent === 100 ? '✓ Review Module' :
`⟳ Continue (${progress.percent}%)`;
$w(module.btnId).label = btnText;
// Set button click handler
$w(module.btnId).onClick(() => {
navigateToModule(module.name);
});
}
}
async function getModuleProgress(email, moduleName) {
try {
const results = await wixData.query('StudentProgress')
.eq('studentEmail', email)
.eq('moduleName', moduleName)
.find();
if (results.items.length > 0) {
return {
percent: results.items[0].progressPercent || 0,
lastActive: results.items[0].lastActive
};
}
} catch (error) {
console.error('Error loading progress:', error);
}
return { percent: 0, lastActive: null };
}
function navigateToModule(moduleName) {
// Map module names to page URLs
const modulePages = {
'Fundamentals of Electricity': '/module-electricity',
'Fundamentals of Maintenance': '/module-maintenance',
'Avionics Systems': '/module-systems'
};
const pageUrl = modulePages[moduleName];
if (pageUrl) {
wixLocation.to(pageUrl);
}
}
top of page
bottom of page