From 5e7cbbb0a12a590f533ab2410791dc6d2f6773ea Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Fri, 22 Dec 2023 00:35:54 +0900
Subject: [PATCH] refs #4653 Add account switching shortcut
---
package.json | 1 +
renderer/components/layouts/account.tsx | 10 ++++++++++
yarn.lock | 5 +++++
3 files changed, 16 insertions(+)
diff --git a/package.json b/package.json
index 73b2b49e..43eced1a 100644
--- a/package.json
+++ b/package.json
@@ -25,6 +25,7 @@
"flowbite-react": "^0.7.0",
"megalodon": "^9.1.1",
"react-blurhash": "^0.3.0",
+ "react-hotkeys-hook": "^4.4.1",
"react-icons": "^4.11.0",
"react-intl": "^6.5.1",
"react-virtuoso": "^4.6.2",
diff --git a/renderer/components/layouts/account.tsx b/renderer/components/layouts/account.tsx
index 3496cb52..f2b263e7 100644
--- a/renderer/components/layouts/account.tsx
+++ b/renderer/components/layouts/account.tsx
@@ -9,6 +9,7 @@ import { FormattedMessage, useIntl } from 'react-intl'
import generateNotification from '@/utils/notification'
import generator, { Entity, WebSocketInterface } from 'megalodon'
import { Context } from '@/utils/i18n'
+import { useHotkeys } from 'react-hotkeys-hook'
type LayoutProps = {
children: React.ReactNode
@@ -24,6 +25,15 @@ export default function Layout({ children }: LayoutProps) {
const { formatMessage } = useIntl()
const streamings = useRef>([])
+ for (let i = 1; i < 9; i++) {
+ useHotkeys(`ctrl+${i}`, () => {
+ const acct = accounts[i - 1]
+ if (acct && acct.id) {
+ router.push(`/accounts/${acct.id}`)
+ }
+ })
+ }
+
useEffect(() => {
loadSettings()
const fn = async () => {
diff --git a/yarn.lock b/yarn.lock
index c5923736..d6635d65 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -7095,6 +7095,11 @@ react-dom@^18.2.0:
loose-envify "^1.1.0"
scheduler "^0.23.0"
+react-hotkeys-hook@^4.4.1:
+ version "4.4.1"
+ resolved "https://registry.yarnpkg.com/react-hotkeys-hook/-/react-hotkeys-hook-4.4.1.tgz#1f7a7a1c9c21d4fa3280bf340fcca8fd77d81994"
+ integrity sha512-sClBMBioFEgFGYLTWWRKvhxcCx1DRznd+wkFHwQZspnRBkHTgruKIHptlK/U/2DPX8BhHoRGzpMVWUXMmdZlmw==
+
react-icons@^4.11.0:
version "4.12.0"
resolved "https://registry.yarnpkg.com/react-icons/-/react-icons-4.12.0.tgz#54806159a966961bfd5cdb26e492f4dafd6a8d78"