Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick: Remove Unused JavaScript #475

Merged
merged 1 commit into from
Apr 7, 2022
Merged

Conversation

wesleyboar
Copy link
Member

@wesleyboar wesleyboar commented Apr 6, 2022

Overview

Remove cruft JavaScript files.

Related

none

Changes

  • Remove site.js and call to load it.
  • Remove nav_portal.js (long since deprecated and never loaded).

Testing

  1. Confirm that this console log does not appear:
    Core `site.js` has no logic.
  2. Confirm that site.js is not loaded.

Screenshots

No Console Log

No Site js Load

@wesleyboar wesleyboar requested review from rstijerina and duckonomy and removed request for duckonomy April 6, 2022 20:28
@wesleyboar wesleyboar changed the title chore(js): remove unused javascript Quick: Remove Unused JavaScript Apr 6, 2022
Copy link
Member Author

@wesleyboar wesleyboar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notes for reviewers.

Comment on lines -1 to -51
/* WARNING: This code is deprecated. It must be removed AFTER GH-195/FP-1015. */

/**
* Load JSON from an endpoint, and perform success-dependent actions
* @param {string} path - The path to an API endpoint
* @param {function} onSuccess - Callback for data retrieval success
* @param {function} onError - Callback for data retrieval success
*/
function getData(path, onSuccess, onError) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
if (typeof onSuccess === 'function') {
onSuccess(JSON.parse(xhr.responseText));
}
} else {
// NOTE: The original code did not ever log an error, thus `undefined`
onError(xhr, undefined);
}
}
};
xhr.open("GET", path, true);
xhr.send();
}

(function () {
/*
* Show (and populate) correct Portal navigation menu
* - If user is authenticated:
* - Populate username (to show that user is logged in)
* - Show portal nav dropdown (it is pre-hidden via classname)
* - If user is NOT authenticated:
* - Show portal login link (it is pre-hidden via classname)
*/
getData('/api/users/auth/',
function populateData(data) {
console.info('portal user data', data);

document.getElementById('portal-username').textContent = data.username;
// FAQ: Show the auth'd menu
document.getElementById('auth-menu').classList.remove('d-none');
},
function outputRequest(xhr, isFatal) {
if (isFatal) console.error(xhr);

// FAQ: Show the un-auth'd menu
document.getElementById('unauth-menu').classList.remove('d-none');
}
);
})();
Copy link
Member Author

@wesleyboar wesleyboar Apr 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explanation: This whole file is unused. Instead of manipulating duplicated HTML, we now load the server-side–prepared HTML directly into place.

Comment on lines -1 to -3
'use strict';

console.info('Core `site.js` has no logic.');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original Intent: Note to self that there is a site.js for site-wide JavaScript. But no site-wide JavaScript has since been needed.

@wesleyboar wesleyboar merged commit f34511f into main Apr 7, 2022
@wesleyboar wesleyboar deleted the quick/remove-site-js-and-cruft branch April 7, 2022 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants