Skip to content

Commit

Permalink
Added project 1 refactored code - Jullia. (#21)
Browse files Browse the repository at this point in the history
* Added refactored code and fixed errors for lint.

---------

Co-authored-by: jullia andrei <[email protected]>
  • Loading branch information
jullia02 and jullia andrei authored Sep 24, 2024
1 parent 03aed02 commit 4c14ce8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
Binary file added dump.rdb
Binary file not shown.
51 changes: 32 additions & 19 deletions public/src/client/account/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,40 @@ define('forum/account/settings', [
}

function saveSettings(settings) {
api.put(`/users/${ajaxify.data.uid}/settings`, { settings }).then((newSettings) => {
alerts.success('[[success:settings-saved]]');
let languageChanged = false;
for (const key in newSettings) {
if (newSettings.hasOwnProperty(key)) {
if (key === 'userLang' && config.userLang !== newSettings.userLang) {
languageChanged = true;
}
if (key === 'bootswatchSkin') {
savedSkin = newSettings.bootswatchSkin;
config.bootswatchSkin = savedSkin === 'noskin' ? '' : savedSkin;
} else if (config.hasOwnProperty(key)) {
config[key] = newSettings[key];
}
}
}
console.log('Logging Jullia Montejo');
api.put(`/users/${ajaxify.data.uid}/settings`, { settings }).then(handleNewSettings);
}

// Alerts the user that the settings have been saved and updates the configuration.
function handleNewSettings(newSettings) {
alerts.success('[[success:settings-saved]]');
processNewSettings(newSettings);
}

if (languageChanged && parseInt(app.user.uid, 10) === parseInt(ajaxify.data.theirid, 10)) {
window.location.reload();
// Processes the new settings and updates the configuration accordingly.
function processNewSettings(newSettings) {
for (const key in newSettings) {
if (newSettings.hasOwnProperty(key)) {
checkAndUpdateConfig(key, newSettings);
}
});
}
}

// Updates the configuration based on the provided key and new settings.
function checkAndUpdateConfig(key, newSettings) {
if (key === 'userLang' && config.userLang !== newSettings.userLang) {
window.location.reload();
} else if (key === 'bootswatchSkin') {
updateSkin(newSettings.bootswatchSkin);
} else if (config.hasOwnProperty(key)) {
config[key] = newSettings[key];
}
}

// Updates the saved skin with the new skin.
function updateSkin(skin) {
savedSkin = skin;
config.bootswatchSkin = skin === 'noskin' ? '' : skin;
}

function toggleCustomRoute() {
Expand Down

0 comments on commit 4c14ce8

Please sign in to comment.