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

feat: add wiki shortcut #291

Merged
merged 1 commit into from
Dec 1, 2023
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
11 changes: 5 additions & 6 deletions public/js/components/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const kAllowedHotKeys = new Set([
const kDefaultHotKeys = {
home: "H",
network: "N",
settings: "S"
settings: "S",
wiki: "W"
}

export class Settings {
Expand Down Expand Up @@ -108,16 +109,14 @@ export class Settings {

updateHotKeys() {
const hotkeys = {};
const hotkeysInputs = [...this.dom.shortcutsSection.querySelectorAll(".hotkey")];
const hotkeysInputs = this.dom.shortcutsSection.querySelectorAll(".hotkey");

for (const input of hotkeysInputs) {
const viewName = input.getAttribute("id");
const hotkey = input.value;
hotkeys[viewName] = hotkey;
const hotkeyName = input.getAttribute("id");
hotkeys[hotkeyName] = input.value;
}

this.updateNavigationHotKey(hotkeys);

localStorage.setItem("hotkeys", JSON.stringify(hotkeys));
}

Expand Down
8 changes: 8 additions & 0 deletions public/js/components/wiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export class Wiki {
this.openButton.addEventListener("click", () => {
this[this.isOpen ? "close" : "open"]();
});

document.addEventListener("keydown", (event) => {
const hotkeys = JSON.parse(localStorage.getItem("hotkeys"));

if (event.key.toUpperCase() === hotkeys.wiki) {
this[this.isOpen ? "close" : "open"]();
}
});
}

get isOpen() {
Expand Down
8 changes: 6 additions & 2 deletions views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,15 @@ <h2><i class="icon-keyboard"></i>Shortcuts</h2>
</div>
<div>
<input readonly id="network" class="hotkey">
<label for="home">Goto Network view</label>
<label for="network">Goto Network view</label>
</div>
<div>
<input readonly id="settings" class="hotkey">
<label for="home">Goto Settings view</label>
<label for="settings">Goto Settings view</label>
</div>
<div>
<input readonly id="wiki" class="hotkey">
<label for="wiki">Open/Close wiki</label>
</div>
</div>
</div>
Expand Down
Loading