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

Fix issues with profile setting dialog #49

Merged
merged 1 commit into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions _sass/_cim.scss
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,8 @@ body.colorscheme-dark .infobox {
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 30vw; // Fallback
width: 30dvw;
width: 50vw; // Fallback
width: 50dvw;
padding: 10px;
border: 1px solid #cccccc;
border-radius: 5px;
Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@
<input type="text" id="profile_name_setting" class="entry">
</div>
<div class="entry-row">
<label for="profile_icon_selector">Icon:</label>
<label for="profile_icon_selector">Icon:</label><br/>

<input type="radio" name="profile_icon_selector"
value="fa-user" id="npis-user">
Expand Down Expand Up @@ -346,7 +346,7 @@
<label for="npis-taxi"><i class="fa fa-solid fa-taxi"></i></label>
</div>
<div class="entry-row">
<label for="show_chord_name_mode">Show chord names:</label>
<label for="show_chord_name_mode">Show chord names:</label><br/>
<select class="selector" name="show_chord_name_mode" id="show-chord-name-mode-selector">
<option value="always">Always</option>
<option value="black_only">Black chords only</option>
Expand Down
40 changes: 29 additions & 11 deletions js/cim.js
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,15 @@ function populate_profile_pulldown() {
}

function get_current_profile() {
return STATE["profiles"][STATE["current_profile"]];
let current_profile = STATE["current_profile"];
if (!STATE["profiles"].hasOwnProperty(current_profile)) {
// If we're in an illegal state where we are stuck as a deleted
// profile, fall back to being the guest profile.
current_profile = _GUEST_USER_ID;
STATE["current_profile"] = current_profile;
set_current_profile(STATE[current_profile]);
}
return STATE["profiles"][current_profile];
}

function select_new_profile(elem) {
Expand All @@ -965,9 +973,10 @@ function select_new_profile(elem) {
function open_profile_adder() {
console.log("Creating new profile");

toggle_profile_visibility();
toggle_profile_settings_visibility(false);
clear_profile_dialog();
let profile_container = document.getElementById("profile-info-container");
profile_container.classList.add("visible");

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

let target_number_elem = document.getElementById("target_number_setting");
target_number_elem.value = _DEFAULT_TARGET_NUMBER;

toggle_profile_visibility();
}

function close_profile_adder() {
console.log("Closing profile adder");
let profile_container = document.getElementById("profile-info-container");
profile_container.classList.remove("visible");
toggle_profile_settings_visibility();
clear_profile_dialog();
}

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

Expand Down Expand Up @@ -1235,6 +1242,12 @@ function set_chord_display_mode(chord_mode) {
}
}


function set_current_profile_by_id(profile_id) {
let profile = STATE["profiles"][profile_id];
return set_current_profile(profile);
}

function set_current_profile(profile) {
if (profile.id !== get_current_profile().id) {
// Reset the stats and retrieve any existing sessions
Expand Down Expand Up @@ -1288,11 +1301,16 @@ function toggle_stats_history_visibility() {
toggle_visibility(document.getElementById("stats-history-container"));
}

function toggle_profile_settings_visibility() {
function toggle_profile_settings_visibility(populate=true) {
const ibox = document.getElementById("profile-info-container");
populate_profile_settings();

toggle_visibility(ibox);
if (ibox.classList.contains("visible")) {
ibox.classList.remove("visible");
} else {
if (populate) {
populate_profile_settings();
}
ibox.classList.add("visible");
}
}

function toggle_theme_mode() {
Expand Down