Skip to content

Commit

Permalink
Update key data
Browse files Browse the repository at this point in the history
  • Loading branch information
Xwilarg committed Dec 30, 2024
1 parent a6ade15 commit 2009291
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions web/src/main/song.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ export function spawnSongNode(json, curr, id, isMinimalist) {
editWarn.classList.remove("is-hidden");
editUrl.classList.add("is-warning");
editWarn.innerHTML = "Only changing the URL can affect<br>others songs sharing the album name";
} else if (editName.value === "") {
} else if (editName.value === "" && editUrl.value !== "") {
editWarn.classList.remove("is-hidden");
editUrl.classList.add("is-warning");
editWarn.innerHtml = "Changing the URL without adding<br>a name will assign a random one";
editWarn.innerHTML = "Changing the URL without adding<br>a name will assign a random one";
}

if (editName.value === "") { // User removed the name
Expand All @@ -81,14 +81,16 @@ export function spawnSongNode(json, curr, id, isMinimalist) {
namePlaceholder = crypto.randomUUID();
}
}
if (editKey.value !== "") haveChanges = true;
if (editKey.value !== "" && editKey.value !== curr.album) haveChanges = true;

editName.placeholder = namePlaceholder ?? "Name of the album";

// Generate a key in case user didn't add one
let key;
if (editName.value === "" && editUrl.value === "") {
key = "";
} else if (!haveChanges && curr.album) {
key = curr.album;
} else {
key = generateKey(curr.artist, editName.value === "" ? namePlaceholder : editName.value);
}
Expand All @@ -99,14 +101,21 @@ export function spawnSongNode(json, curr, id, isMinimalist) {
if (haveChanges && currKey in json.albums) {
keyWarn.classList.remove("is-hidden");
editKey.classList.add("is-warning");

editName.disabled = true;
editUrl.disabled = true;
} else {
keyWarn.classList.add("is-hidden");
editKey.classList.remove("is-warning");

editName.disabled = false;
editUrl.disabled = false;
}
}

editName.addEventListener("change", (_) => { onAlbumChange(); });
editUrl.addEventListener("change", (_) => { onAlbumChange(); });
editKey.addEventListener("change", (_) => { onAlbumChange(); });

node.querySelector(".song-edit").addEventListener("click", () => {
target.hidden = !target.hidden;
Expand All @@ -122,7 +131,7 @@ export function spawnSongNode(json, curr, id, isMinimalist) {
if (curr.album) {
form.getElementsByClassName("edit-album-name")[0].value = json.albums[curr.album].name ?? curr.album;
form.getElementsByClassName("edit-album-url")[0].value = json.albums[curr.album].source;
form.getElementsByClassName("edit-album-key")[0].value = curr.album;
form.getElementsByClassName("edit-album-key")[0].placeholder = curr.album;
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion web/templates/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<label class="label">Album key</label>
<div class="control">
<input class="input edit-album-key" type="text" name="AlbumKey"/>
<p class="help is-warning is-hidden edit-album-key-warn">This key is already used by<br>another song</p>
<p class="help is-warning is-hidden edit-album-key-warn">This key is already used by<br>This will overrides changes below</p>
</div>
</div>
<div class="field">
Expand Down

0 comments on commit 2009291

Please sign in to comment.