Skip to content

Commit

Permalink
Asynchronously load saved workspaces to the corresponding list
Browse files Browse the repository at this point in the history
  • Loading branch information
simosathan9 committed Sep 14, 2024
1 parent 81ee626 commit 2f8572c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion public/js/el.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Blockly.Msg['LN_MESSAGE'] = 'Σύνδεση αρχείων';
Blockly.Msg['LN_SYMBOLIC_LINK'] = 'Δημιουργία συμβολικού συνδέσμου %1';
Blockly.Msg['LN_SOURCE'] = 'Αρχείο προέλευσης';
Blockly.Msg['LN_TARGET'] = 'Αρχείο προορισμού';
Blockly.Msg['LN_FORCE'] = 'Αναγκαστική αντικατάσταση %1';
Blockly.Msg['LN_FORCE'] = 'Επιβολή αντικατάστασης %1';
Blockly.Msg['LN_INTERACTIVE'] = 'Προτροπή πριν από την αντικατάσταση %1';
Blockly.Msg['LN_VERBOSE'] = 'Εμφάνιση των αρχείων κατά την επεξεργασία %1';
Blockly.Msg['LN_TOOLTIP'] =
Expand Down
36 changes: 36 additions & 0 deletions public/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,41 @@ function loadAutoSavedWorkspace() {
});
}

// Function to update the saved workspaces dropdown
async function updateWorkspaces(userId) {
try {
// Fetch the user's workspaces from the server
const response = await fetch(`/getUserWorkspaces?userId=${userId}`);
const data = await response.json();
const workspaces = data.workspaces;
const savedWorkspacesSelect = document.getElementById('savedWorkspaces');

// Clear any existing options in the dropdown
savedWorkspacesSelect.innerHTML = '';

// Add a default option
const defaultOption = document.createElement('option');
defaultOption.value = '';
defaultOption.text = 'Select a workspace';
savedWorkspacesSelect.appendChild(defaultOption);

// Populate dropdown with the user's saved workspaces
workspaces.forEach((workspace) => {
if (workspace.workspaceName !== '__autosave__') {
const option = document.createElement('option');
option.value = workspace.id; // use the workspace ID as the option value
option.text = workspace.workspaceName; // display the workspace name
savedWorkspacesSelect.appendChild(option);
}
});

// Optionally, show a success message or silently update
console.log('Workspaces updated successfully.');
} catch (error) {
console.error('Error updating workspaces:', error);
}
}

document.addEventListener('DOMContentLoaded', () => {
fetch('/auth-token')
.then((response) => response.json())
Expand Down Expand Up @@ -253,6 +288,7 @@ document.addEventListener('DOMContentLoaded', () => {
console.error('Error saving workspace:', result.error);
alert('Failed to save workspace. Please try again.');
} else {
updateWorkspaces(user.id); // Reload the current page
alert('Workspace saved successfully.');
}
})
Expand Down

0 comments on commit 2f8572c

Please sign in to comment.