Add Stimulus controller for handling hotkeys

This commit is contained in:
Karina Kwiatek 2023-03-19 14:42:01 +01:00
parent f7b9d90e28
commit 655b822e54
20 changed files with 32 additions and 18 deletions

View File

@ -0,0 +1,12 @@
import { Controller } from "@hotwired/stimulus";
import { install, uninstall } from "@github/hotkey";
export default class extends Controller<HTMLElement> {
connect(): void {
install(this.element);
}
disconnect(): void {
uninstall(this.element);
}
}

View File

@ -8,6 +8,7 @@ import CollapseController from "retrospring/controllers/collapse_controller";
import ThemeController from "retrospring/controllers/theme_controller";
import CapabilitiesController from "retrospring/controllers/capabilities_controller";
import CropperController from "retrospring/controllers/cropper_controller";
import HotkeyController from "retrospring/controllers/hotkey_controller";
import InboxSharingController from "retrospring/controllers/inbox_sharing_controller";
import ToastController from "retrospring/controllers/toast_controller";
import PwaBadgeController from "retrospring/controllers/pwa_badge_controller";
@ -30,6 +31,7 @@ export default function (): void {
window['Stimulus'].register('collapse', CollapseController);
window['Stimulus'].register('cropper', CropperController);
window['Stimulus'].register('format-popup', FormatPopupController);
window['Stimulus'].register('hotkey', HotkeyController);
window['Stimulus'].register('inbox-sharing', InboxSharingController);
window['Stimulus'].register('pwa-badge', PwaBadgeController);
window['Stimulus'].register('navigation', NavigationController);

View File

@ -11,5 +11,5 @@
class: "btn btn-light",
method: :get,
params: { last_id: @inbox_last_id, author: @author }.compact,
data: { hotkey: "." },
data: { controller: :hotkey, hotkey: "." },
form: { data: { turbo_stream: true } }

View File

@ -8,5 +8,5 @@
class: "btn btn-light",
method: :get,
params: { last_id: @inbox_last_id, author: @author }.compact,
data: { hotkey: "." },
data: { controller: :hotkey, hotkey: "." },
form: { data: { turbo_stream: true } }

View File

@ -14,5 +14,5 @@
class: "btn btn-light",
method: :get,
params: { last_id: @inbox_last_id },
data: { hotkey: "." },
data: { controller: :hotkey, hotkey: "." },
form: { data: { turbo_stream: true } }

View File

@ -8,5 +8,5 @@
class: "btn btn-light",
method: :get,
params: { last_id: @inbox_last_id },
data: { hotkey: "." },
data: { controller: :hotkey, hotkey: "." },
form: { data: { turbo_stream: true } }

View File

@ -8,7 +8,7 @@
class: "btn btn-light",
method: :get,
params: { last_id: @reports_last_id },
data: { hotkey: "." },
data: { controller: :hotkey, hotkey: "." },
form: { data: { turbo_stream: true } }
- parent_layout "moderation"

View File

@ -8,5 +8,5 @@
class: "btn btn-light",
method: :get,
params: { last_id: @reports_last_id },
data: { hotkey: "." },
data: { controller: :hotkey, hotkey: "." },
form: { data: { turbo_stream: true } }

View File

@ -22,7 +22,7 @@
class: "btn btn-light",
method: :get,
params: { last_id: @notifications_last_id },
data: { hotkey: "." },
data: { controller: :hotkey, hotkey: "." },
form: { data: { turbo_stream: true } }
- provide(:title, generate_title(t(".title")))

View File

@ -11,5 +11,5 @@
class: "btn btn-light",
method: :get,
params: { last_id: @notifications_last_id },
data: { hotkey: "." },
data: { controller: :hotkey, hotkey: "." },
form: { data: { turbo_stream: true } }

View File

@ -14,7 +14,7 @@
class: "btn btn-light",
method: :get,
params: { last_id: @answers_last_id },
data: { hotkey: "." },
data: { controller: :hotkey, hotkey: "." },
form: { data: { turbo_stream: true } }
- if user_signed_in? && !current_user.answered?(@question) && current_user != @question.user && @question.user&.privacy_allow_stranger_answers

View File

@ -8,5 +8,5 @@
class: "btn btn-light",
method: :get,
params: { last_id: @answers_last_id },
data: { hotkey: "." },
data: { controller: :hotkey, hotkey: "." },
form: { data: { turbo_stream: true } }

View File

@ -10,7 +10,7 @@
class: "btn btn-light",
method: :get,
params: { last_id: @timeline_last_id },
data: { hotkey: "." },
data: { controller: :hotkey, hotkey: "." },
form: { data: { turbo_stream: true } }
- provide(:title, @title || APP_CONFIG["site_name"])

View File

@ -8,5 +8,5 @@
class: "btn btn-light",
method: :get,
params: { last_id: @timeline_last_id },
data: { hotkey: "." },
data: { controller: :hotkey, hotkey: "." },
form: { data: { turbo_stream: true } }

View File

@ -8,7 +8,7 @@
class: "btn btn-light",
method: :get,
params: { last_id: @questions_last_id },
data: { hotkey: "." },
data: { controller: :hotkey, hotkey: "." },
form: { data: { turbo_stream: true } }
- provide(:title, questions_title(@user))

View File

@ -8,5 +8,5 @@
class: "btn btn-light",
method: :get,
params: { last_id: @questions_last_id },
data: { hotkey: "." },
data: { controller: :hotkey, hotkey: "." },
form: { data: { turbo_stream: true } }

View File

@ -16,7 +16,7 @@
class: "btn btn-light",
method: :get,
params: { last_id: @answers_last_id },
data: { hotkey: "." },
data: { controller: :hotkey, hotkey: "." },
form: { data: { turbo_stream: true } }
:ruby

View File

@ -8,5 +8,5 @@
class: "btn btn-light",
method: :get,
params: { last_id: @answers_last_id },
data: { hotkey: "." },
data: { controller: :hotkey, hotkey: "." },
form: { data: { turbo_stream: true } }

View File

@ -9,7 +9,7 @@
class: "btn btn-light",
method: :get,
params: { last_id: @relationships_last_id },
data: { hotkey: "." },
data: { controller: :hotkey, hotkey: "." },
form: { data: { turbo_stream: true } }
- provide(:title, t(".title.#{type}", user: @user.profile.safe_name))

View File

@ -9,5 +9,5 @@
class: "btn btn-light",
method: :get,
params: { last_id: @relationships_last_id },
data: { hotkey: "." },
data: { controller: :hotkey, hotkey: "." },
form: { data: { turbo_stream: true } }