From 1b27da85e70158f6847960a7f1130c4acc6293a1 Mon Sep 17 00:00:00 2001 From: Subhamoy Biswas Date: Fri, 2 Feb 2024 01:09:33 +0530 Subject: [PATCH] (refactor): made keybinding links fully dynamic --- htdocs/assets/js/keybinding-config.js | 26 +++++++++++++++++++++++--- htdocs/core/query_functions.php | 2 +- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/htdocs/assets/js/keybinding-config.js b/htdocs/assets/js/keybinding-config.js index cc81cbd..5b8962a 100644 --- a/htdocs/assets/js/keybinding-config.js +++ b/htdocs/assets/js/keybinding-config.js @@ -3,6 +3,26 @@ let pressedKeys = {}; +function getJsonDataset(element) { + return new Promise((resolve, reject) => { + $.getJSON('assets/dataset.json', function(datasetData) { + resolve(datasetData[element]); + }).fail(function(jqxhr, textStatus, error) { + reject(error); + }); + }); +} + +async function redirectToURL(item) { + try { + const url = await getJsonDataset(item); + window.open(url, '_blank'); + location.reload(); + } catch (error) { + console.error('Error:', error); + } +} + document.addEventListener('keydown', function(event) { pressedKeys[event.key] = true; @@ -19,13 +39,13 @@ document.addEventListener('keydown', function(event) { window.location.href = basePath + "/contact"; } else if (pressedKeys['q'] && pressedKeys['e']) { - window.location.href = "mailto:hey@neosubhamoy.com"; + redirectToURL('email'); } else if (pressedKeys['q'] && pressedKeys['m']) { - window.location.href = "#"; + redirectToURL('chat'); } else if (pressedKeys['q'] && pressedKeys['s']) { - window.location.href = "#"; + redirectToURL('sources'); } }); diff --git a/htdocs/core/query_functions.php b/htdocs/core/query_functions.php index 323b78b..882428d 100644 --- a/htdocs/core/query_functions.php +++ b/htdocs/core/query_functions.php @@ -61,7 +61,7 @@ function fetch_page_title($conn, $page_name) { } } -//function to fetch page title +//function to fetch quick actions link function fetch_quick_action_link($conn, $action_name) { $sql = "SELECT link FROM quick_actions WHERE name = '$action_name'"; $result = $conn -> query($sql);