Skip to content

Commit 567811b

Browse files
committed
Fix issues with profile setting dialog
1. More gracefully handle the situation where we get into an illegal state where the profile ID corresponds to a deleted or otherwise non-existent profile. 2. Switch the profile adder / settings adjuster dialogue away from being an infobox, so now the only way to toggle it is with the X or one of the buttons. 3. Make it so that you fall back to the guest profile when a profile is deleted. 4. Various fixes related to visibility of the profile settings adder / adjuster in different scenarios.
1 parent fe7d4da commit 567811b

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

_sass/_cim.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,8 @@ body.colorscheme-dark .infobox {
560560
left: 50%;
561561
top: 50%;
562562
transform: translate(-50%, -50%);
563-
width: 30vw; // Fallback
564-
width: 30dvw;
563+
width: 50vw; // Fallback
564+
width: 50dvw;
565565
padding: 10px;
566566
border: 1px solid #cccccc;
567567
border-radius: 5px;

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@
315315
<input type="text" id="profile_name_setting" class="entry">
316316
</div>
317317
<div class="entry-row">
318-
<label for="profile_icon_selector">Icon:</label>
318+
<label for="profile_icon_selector">Icon:</label><br/>
319319

320320
<input type="radio" name="profile_icon_selector"
321321
value="fa-user" id="npis-user">
@@ -346,7 +346,7 @@
346346
<label for="npis-taxi"><i class="fa fa-solid fa-taxi"></i></label>
347347
</div>
348348
<div class="entry-row">
349-
<label for="show_chord_name_mode">Show chord names:</label>
349+
<label for="show_chord_name_mode">Show chord names:</label><br/>
350350
<select class="selector" name="show_chord_name_mode" id="show-chord-name-mode-selector">
351351
<option value="always">Always</option>
352352
<option value="black_only">Black chords only</option>

js/cim.js

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,15 @@ function populate_profile_pulldown() {
953953
}
954954

955955
function get_current_profile() {
956-
return STATE["profiles"][STATE["current_profile"]];
956+
let current_profile = STATE["current_profile"];
957+
if (!STATE["profiles"].hasOwnProperty(current_profile)) {
958+
// If we're in an illegal state where we are stuck as a deleted
959+
// profile, fall back to being the guest profile.
960+
current_profile = _GUEST_USER_ID;
961+
STATE["current_profile"] = current_profile;
962+
set_current_profile(STATE[current_profile]);
963+
}
964+
return STATE["profiles"][current_profile];
957965
}
958966

959967
function select_new_profile(elem) {
@@ -965,9 +973,10 @@ function select_new_profile(elem) {
965973
function open_profile_adder() {
966974
console.log("Creating new profile");
967975

976+
toggle_profile_visibility();
977+
toggle_profile_settings_visibility(false);
968978
clear_profile_dialog();
969979
let profile_container = document.getElementById("profile-info-container");
970-
profile_container.classList.add("visible");
971980

972981
for (var elem of profile_container.querySelectorAll("button.add-button")) {
973982
elem.classList.add("visible");
@@ -977,14 +986,11 @@ function open_profile_adder() {
977986

978987
let target_number_elem = document.getElementById("target_number_setting");
979988
target_number_elem.value = _DEFAULT_TARGET_NUMBER;
980-
981-
toggle_profile_visibility();
982989
}
983990

984991
function close_profile_adder() {
985992
console.log("Closing profile adder");
986-
let profile_container = document.getElementById("profile-info-container");
987-
profile_container.classList.remove("visible");
993+
toggle_profile_settings_visibility();
988994
clear_profile_dialog();
989995
}
990996

@@ -1106,7 +1112,6 @@ function populate_profile_settings() {
11061112
const is_guest = (profile.id === _GUEST_USER_ID);
11071113
clear_profile_dialog();
11081114
let profile_dialog = document.getElementById("profile-info-container");
1109-
profile_dialog.classList.add("visible");
11101115
for (let elem of profile_dialog.querySelectorAll("button.settings-button")) {
11111116
elem.classList.add("visible");
11121117
}
@@ -1189,6 +1194,8 @@ function delete_profile() {
11891194
alert("Deleting the guest user is not allowed.");
11901195
return;
11911196
} else if (confirm("Are you sure you want to delete the profile " + STATE.profiles[profile_id].name + "?")) {
1197+
// Set the current profile to the guest profile
1198+
set_current_profile_by_id(_GUEST_USER_ID);
11921199
delete STATE.profiles[profile_id];
11931200
}
11941201

@@ -1235,6 +1242,12 @@ function set_chord_display_mode(chord_mode) {
12351242
}
12361243
}
12371244

1245+
1246+
function set_current_profile_by_id(profile_id) {
1247+
let profile = STATE["profiles"][profile_id];
1248+
return set_current_profile(profile);
1249+
}
1250+
12381251
function set_current_profile(profile) {
12391252
if (profile.id !== get_current_profile().id) {
12401253
// Reset the stats and retrieve any existing sessions
@@ -1288,11 +1301,16 @@ function toggle_stats_history_visibility() {
12881301
toggle_visibility(document.getElementById("stats-history-container"));
12891302
}
12901303

1291-
function toggle_profile_settings_visibility() {
1304+
function toggle_profile_settings_visibility(populate=true) {
12921305
const ibox = document.getElementById("profile-info-container");
1293-
populate_profile_settings();
1294-
1295-
toggle_visibility(ibox);
1306+
if (ibox.classList.contains("visible")) {
1307+
ibox.classList.remove("visible");
1308+
} else {
1309+
if (populate) {
1310+
populate_profile_settings();
1311+
}
1312+
ibox.classList.add("visible");
1313+
}
12961314
}
12971315

12981316
function toggle_theme_mode() {

0 commit comments

Comments
 (0)