From 2f8572cad1cdde1d26ae041b32db0095e1bec50b Mon Sep 17 00:00:00 2001 From: simosathan9 Date: Sat, 14 Sep 2024 16:14:45 +0300 Subject: [PATCH] Asynchronously load saved workspaces to the corresponding list --- public/js/el.js | 2 +- public/main.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/public/js/el.js b/public/js/el.js index fa8a125..fc93e9c 100644 --- a/public/js/el.js +++ b/public/js/el.js @@ -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'] = diff --git a/public/main.js b/public/main.js index 90f226a..2ba48f8 100644 --- a/public/main.js +++ b/public/main.js @@ -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()) @@ -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.'); } })