Skip to content

Commit

Permalink
Simplify main function again
Browse files Browse the repository at this point in the history
  • Loading branch information
agatemosu committed Jan 1, 2025
1 parent 0c9f38b commit ad49587
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,28 +114,29 @@ function gatherAll() {

// #region Setup

function setUpSortable() {
function main() {
/** @type {HTMLElement} */
const imagesBar = document.querySelector("#images-bar");
Sortable.create(imagesBar, { group: TierRow.sortableGroup });
}

function setUpEvents() {
const newTierButton = document.querySelector("#new-tier");
const selectImagesButton = document.querySelector("#select-images");
const gatherAllButton = document.querySelector("#gather-all");
/** @type {[string, EventListener][]} */
const eventMap = [
["#new-tier", addNewTier],
["#select-images", selectImages],
["#gather-all", gatherAll],
];

newTierButton.addEventListener("click", addNewTier);
selectImagesButton.addEventListener("click", selectImages);
gatherAllButton.addEventListener("click", gatherAll);
for (const [selector, handler] of eventMap) {
const element = document.querySelector(selector);
element.addEventListener("click", handler);
}

const checkboxes = document.querySelectorAll(".dynamic-style");
for (const checkbox of checkboxes) {
checkbox.addEventListener("change", dynamicStyle);
}
}

setUpSortable();
setUpEvents();
main();

// #endregion

0 comments on commit ad49587

Please sign in to comment.