Skip to content

Commit

Permalink
Add event listeners for each console setting
Browse files Browse the repository at this point in the history
This reduces the number of HTTP requests from 5 to 1.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Mar 29, 2024
1 parent 65c6f18 commit f9600dd
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions resources/js/src/modules/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,34 @@ var Console = {
Console.hideCard($(this).closest('.card'));
});

$('#pma_console_options').find('input[type=checkbox]').on('change', function () {
Config.update();
const consoleOptionsAlwaysExpandCheckbox = document.getElementById('consoleOptionsAlwaysExpandCheckbox') as HTMLInputElement;
consoleOptionsAlwaysExpandCheckbox?.addEventListener('change', function (): void {
Config.set('AlwaysExpand', !! consoleOptionsAlwaysExpandCheckbox.checked);
});

const consoleOptionsStartHistoryCheckbox = document.getElementById('consoleOptionsStartHistoryCheckbox') as HTMLInputElement;
consoleOptionsStartHistoryCheckbox?.addEventListener('change', function (): void {
Config.set('StartHistory', !! consoleOptionsStartHistoryCheckbox.checked);
});

const consoleOptionsCurrentQueryCheckbox = document.getElementById('consoleOptionsCurrentQueryCheckbox') as HTMLInputElement;
consoleOptionsCurrentQueryCheckbox?.addEventListener('change', function (): void {
Config.set('CurrentQuery', !! consoleOptionsCurrentQueryCheckbox.checked);
});

const consoleOptionsEnterExecutesCheckbox = document.getElementById('consoleOptionsEnterExecutesCheckbox') as HTMLInputElement;
consoleOptionsEnterExecutesCheckbox?.addEventListener('change', function (): void {
const isEnterExecutes = !! consoleOptionsEnterExecutesCheckbox.checked;
Config.set('EnterExecutes', isEnterExecutes);
ConsoleMessages.showInstructions(isEnterExecutes);
});

const consoleOptionsDarkThemeCheckbox = document.getElementById('consoleOptionsDarkThemeCheckbox') as HTMLInputElement;
consoleOptionsDarkThemeCheckbox?.addEventListener('change', function (): void {
const isDarkTheme = !! consoleOptionsDarkThemeCheckbox.checked;
Config.set('DarkTheme', isDarkTheme);
const consoleContent = document.getElementById('pma_console').querySelector('.content');
consoleContent.classList.toggle('console_dark_theme', isDarkTheme);
});

$('#pma_console_options').find('.button.default').on('click', function () {
Expand All @@ -159,10 +185,6 @@ var Console = {
Config.update();
});

$('#consoleOptionsEnterExecutesCheckbox').on('change', function () {
ConsoleMessages.showInstructions(Config.EnterExecutes);
});

$(document).on('ajaxComplete', function (event, xhr, ajaxOptions) {
if (ajaxOptions.dataType && ajaxOptions.dataType.indexOf('json') !== -1) {
return;
Expand Down

0 comments on commit f9600dd

Please sign in to comment.