Skip to content

Commit

Permalink
Merge pull request #496 from chesslablab/revert-495-issue/489-Customi…
Browse files Browse the repository at this point in the history
…zable-settings

Revert "Issue/489 customizable settings"
  • Loading branch information
programarivm authored Sep 25, 2024
2 parents 322ccc1 + cdeea31 commit 05d20c8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 21 deletions.
17 changes: 4 additions & 13 deletions assets/env.example.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
// Check out for possible settings values in templates/pages/settings/index.html.twig

const SETTINGS = {
'locale': 'en',
'theme': 'dark',
'format': 'inline',
'notation': 'fan',
'set': 'classical',
'ws': [
'wss://async.chesslablab.org'
]
};
const WEBSOCKET_SERVER = [
'wss://async.chesslablab.org'
];

export {
SETTINGS
WEBSOCKET_SERVER
};
2 changes: 1 addition & 1 deletion assets/js/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const ws = () => {
}
}

return env.SETTINGS.ws[Math.floor(Math.random() * env.SETTINGS.ws.length)];
return env.WEBSOCKET_SERVER[Math.floor(Math.random() * env.WEBSOCKET_SERVER.length)];
}

export {
Expand Down
41 changes: 34 additions & 7 deletions assets/js/pages/settings/SettingsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,46 @@ import * as env from '../../../env.js';

export class SettingsForm extends AbstractComponent {
mount() {
env.SETTINGS.ws.forEach(item => {
env.WEBSOCKET_SERVER.forEach(item => {
const option = document.createElement('option');
option.appendChild(document.createTextNode(new URL(item).hostname));
option.value = item;
this.el.querySelector('select[name="ws"]').append(option);
});

this.el.querySelector('select[name="locale"]').value = localStorage.getItem('locale') ?? env.SETTINGS.locale;
this.el.querySelector('select[name="theme"]').value = localStorage.getItem('theme') ?? env.SETTINGS.theme;
this.el.querySelector('select[name="format"]').value = localStorage.getItem('format') ?? env.SETTINGS.format;
this.el.querySelector('select[name="notation"]').value = localStorage.getItem('notation') ?? env.SETTINGS.notation;
this.el.querySelector('select[name="set"]').value = localStorage.getItem('set') ?? env.SETTINGS.set;
this.el.querySelector('select[name="ws"]').value = localStorage.getItem('ws') ?? env.SETTINGS.ws;
if (localStorage.getItem('locale')) {
this.el.querySelector('select[name="locale"]').value = localStorage.getItem('locale');
} else {
this.el.querySelector('select[name="locale"]').value = 'en';
}

if (localStorage.getItem('theme') === 'light') {
this.el.querySelector('select[name="theme"]').value = 'light';
} else {
this.el.querySelector('select[name="theme"]').value = 'dark';
}

if (localStorage.getItem('format') === 'table') {
this.el.querySelector('select[name="format"]').value = 'table';
} else {
this.el.querySelector('select[name="format"]').value = 'inline';
}

if (localStorage.getItem('notation') === 'san') {
this.el.querySelector('select[name="notation"]').value = 'san';
} else {
this.el.querySelector('select[name="notation"]').value = 'fan';
}

if (localStorage.getItem('set') === 'staunty') {
this.el.querySelector('select[name="set"]').value = 'staunty';
} else {
this.el.querySelector('select[name="set"]').value = 'classical';
}

if (localStorage.getItem('ws')) {
this.el.querySelector('select[name="ws"]').value = localStorage.getItem('ws');
}

this.el.addEventListener('submit', event => {
event.preventDefault();
Expand Down

0 comments on commit 05d20c8

Please sign in to comment.