From c2ef0a95787a15d75b4fffc56a61926b5a9bd75e Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 1 May 2024 14:31:26 +0100 Subject: [PATCH] chore: Clarify usage of window fields in Settings app Solves these eslint issues: /puter/src/UI/Settings/UITabAccount.js 34:13 error 'user' is not defined no-undef 47:99 error 'user' is not defined no-undef 55:12 error 'user' is not defined no-undef 59:105 error 'user' is not defined no-undef /puter/src/UI/Settings/UITabLanguage.js 35:37 error 'listSupportedLanguages' is not defined no-undef /puter/src/UI/Settings/UITabUsage.js 45:18 error 'api_origin' is not defined no-undef 50:46 error 'auth_token' is not defined no-undef 54:21 error 'logout' is not defined no-undef 96:18 error 'api_origin' is not defined no-undef 101:46 error 'auth_token' is not defined no-undef 105:21 error 'logout' is not defined no-undef 116:51 error 'byte_format' is not defined no-undef 123:41 error 'byte_format' is not defined no-undef 124:45 error 'byte_format' is not defined no-undef /puter/src/UI/Settings/UIWindowChangeEmail.js 96:18 error 'api_origin' is not defined no-undef 100:44 error 'auth_token' is not defined no-undef /puter/src/UI/Settings/UIWindowFinalizeUserDeletion.js 29:12 error 'user' is not defined no-undef 97:16 error 'user' is not defined no-undef 115:22 error 'api_origin' is not defined no-undef 120:50 error 'auth_token' is not defined no-undef 127:25 error 'logout' is not defined no-undef 139:25 error 'logout' is not defined no-undef /puter/src/UI/Settings/UIWindowSettings.js 48:162 error 'icons' is not defined no-undef 86:13 error Duplicate key 'height' no-dupe-keys --- src/UI/Settings/UITabAccount.js | 8 ++++---- src/UI/Settings/UITabLanguage.js | 2 +- src/UI/Settings/UITabUsage.js | 18 +++++++++--------- src/UI/Settings/UIWindowChangeEmail.js | 4 ++-- .../Settings/UIWindowFinalizeUserDeletion.js | 12 ++++++------ src/UI/Settings/UIWindowSettings.js | 3 +-- 6 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/UI/Settings/UITabAccount.js b/src/UI/Settings/UITabAccount.js index 4ed08ea00..d05442065 100644 --- a/src/UI/Settings/UITabAccount.js +++ b/src/UI/Settings/UITabAccount.js @@ -31,7 +31,7 @@ export default { let h = `

${i18n('account')}

`; // change password button - if(!user.is_temp){ + if(!window.user.is_temp){ h += `
`; h += `${i18n('password')}`; h += `
`; @@ -44,7 +44,7 @@ export default { h += `
`; h += `
`; h += `${i18n('username')}`; - h += `${html_encode(user.username)}`; + h += `${html_encode(window.user.username)}`; h += `
`; h += `
`; h += ``; @@ -52,11 +52,11 @@ export default { h += `
`; // change email button - if(user.email){ + if(window.user.email){ h += `
`; h += `
`; h += `${i18n('email')}`; - h += `${html_encode(user.email)}`; + h += `${html_encode(window.user.email)}`; h += `
`; h += `
`; h += ``; diff --git a/src/UI/Settings/UITabLanguage.js b/src/UI/Settings/UITabLanguage.js index 5bb09a68b..c65f611be 100644 --- a/src/UI/Settings/UITabLanguage.js +++ b/src/UI/Settings/UITabLanguage.js @@ -32,7 +32,7 @@ export default {
`; // list of languages - const available_languages = listSupportedLanguages(); + const available_languages = window.listSupportedLanguages(); h += `
`; for (let lang of available_languages) { h += `
${html_encode(lang.name)}
`; diff --git a/src/UI/Settings/UITabUsage.js b/src/UI/Settings/UITabUsage.js index 976475cfb..ba72bd618 100644 --- a/src/UI/Settings/UITabUsage.js +++ b/src/UI/Settings/UITabUsage.js @@ -42,16 +42,16 @@ export default { }, init: ($el_window) => { $.ajax({ - url: api_origin + "/drivers/usage", + url: window.api_origin + "/drivers/usage", type: 'GET', async: true, contentType: "application/json", headers: { - "Authorization": "Bearer " + auth_token + "Authorization": "Bearer " + window.auth_token }, statusCode: { 401: function () { - logout(); + window.logout(); }, }, success: function (res) { @@ -93,16 +93,16 @@ export default { // df $.ajax({ - url: api_origin + "/df", + url: window.api_origin + "/df", type: 'GET', async: true, contentType: "application/json", headers: { - "Authorization": "Bearer " + auth_token + "Authorization": "Bearer " + window.auth_token }, statusCode: { 401: function () { - logout(); + window.logout(); }, }, success: function (res) { @@ -113,15 +113,15 @@ export default { let host_usage_percentage = 0; if ( res.host_used ) { - $('#storage-puter-used').html(byte_format(res.used)); + $('#storage-puter-used').html(window.byte_format(res.used)); $('#storage-puter-used-w').show(); general_used = res.host_used; host_usage_percentage = ((res.host_used - res.used) / res.capacity * 100).toFixed(0); } - $('#storage-used').html(byte_format(general_used)); - $('#storage-capacity').html(byte_format(res.capacity)); + $('#storage-used').html(window.byte_format(general_used)); + $('#storage-capacity').html(window.byte_format(res.capacity)); $('#storage-used-percent').html( usage_percentage + '%' + (host_usage_percentage > 0 diff --git a/src/UI/Settings/UIWindowChangeEmail.js b/src/UI/Settings/UIWindowChangeEmail.js index 61f6a2882..1b28c0aee 100644 --- a/src/UI/Settings/UIWindowChangeEmail.js +++ b/src/UI/Settings/UIWindowChangeEmail.js @@ -93,11 +93,11 @@ async function UIWindowChangeEmail(options){ $(el_window).find('.new-email').attr('disabled', true); $.ajax({ - url: api_origin + "/change_email/start", + url: window.api_origin + "/change_email/start", type: 'POST', async: true, headers: { - "Authorization": "Bearer "+auth_token + "Authorization": "Bearer "+window.auth_token }, contentType: "application/json", data: JSON.stringify({ diff --git a/src/UI/Settings/UIWindowFinalizeUserDeletion.js b/src/UI/Settings/UIWindowFinalizeUserDeletion.js index 505a6270f..e4511f4e5 100644 --- a/src/UI/Settings/UIWindowFinalizeUserDeletion.js +++ b/src/UI/Settings/UIWindowFinalizeUserDeletion.js @@ -26,7 +26,7 @@ async function UIWindowFinalizeUserDeletion(options){ let h = ''; // if user is temporary, ask them to type in 'confirm' to delete their account - if(user.is_temp){ + if(window.user.is_temp){ h += `
`; h += `
×
`; h += ``; @@ -94,7 +94,7 @@ async function UIWindowFinalizeUserDeletion(options){ $(el_window).find('.proceed-with-user-deletion').on('click', function(){ $(el_window).find('.error-message').hide(); // if user is temporary, check if they typed 'confirm' - if(user.is_temp){ + if(window.user.is_temp){ if($(el_window).find('.confirm-temporary-user-deletion').val() !== 'confirm'){ $(el_window).find('.error-message').html(i18n('type_confirm_to_delete_account'), false); $(el_window).find('.error-message').show(); @@ -112,19 +112,19 @@ async function UIWindowFinalizeUserDeletion(options){ // delete user $.ajax({ - url: api_origin + "/delete-own-user", + url: window.api_origin + "/delete-own-user", type: 'POST', async: true, contentType: "application/json", headers: { - "Authorization": "Bearer " + auth_token + "Authorization": "Bearer " + window.auth_token }, data: JSON.stringify({ password: $(el_window).find('.confirm-user-deletion-password').val(), }), statusCode: { 401: function () { - logout(); + window.logout(); }, 400: function(){ $(el_window).find('.error-message').html(i18n('incorrect_password')); @@ -136,7 +136,7 @@ async function UIWindowFinalizeUserDeletion(options){ // mark user as deleted window.user.deleted = true; // log user out - logout(); + window.logout(); } else{ $(el_window).find('.error-message').html(html_encode(data.error)); diff --git a/src/UI/Settings/UIWindowSettings.js b/src/UI/Settings/UIWindowSettings.js index 2a720372e..28300f231 100644 --- a/src/UI/Settings/UIWindowSettings.js +++ b/src/UI/Settings/UIWindowSettings.js @@ -45,7 +45,7 @@ async function UIWindowSettings(options){ // side bar h += `
`; tabs.forEach((tab, i) => { - h += `
${i18n(tab.title_i18n_key)}
`; + h += `
${i18n(tab.title_i18n_key)}
`; }); h += `
`; @@ -82,7 +82,6 @@ async function UIWindowSettings(options){ allow_user_select: true, backdrop: false, width: 800, - height: 500, height: 'auto', dominant: true, show_in_taskbar: false,