feat: add several new shortcut keys for navigation (#2618)

zio/stable
TAKAHASHI Shuuji 2024-02-25 04:28:56 +09:00 committed by GitHub
parent 3584151fab
commit edcc8741bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 64 additions and 1 deletions

View File

@ -40,6 +40,10 @@ const shortcutItemGroups = computed<ShortcutItemGroup[]>(() => [
// description: t('magic_keys.groups.navigation.previous_status'), // description: t('magic_keys.groups.navigation.previous_status'),
// shortcut: { keys: ['k'], isSequence: false }, // shortcut: { keys: ['k'], isSequence: false },
// }, // },
{
description: t('magic_keys.groups.navigation.go_to_search'),
shortcut: { keys: ['/'], isSequence: false },
},
{ {
description: t('magic_keys.groups.navigation.go_to_home'), description: t('magic_keys.groups.navigation.go_to_home'),
shortcut: { keys: ['g', 'h'], isSequence: true }, shortcut: { keys: ['g', 'h'], isSequence: true },
@ -48,6 +52,42 @@ const shortcutItemGroups = computed<ShortcutItemGroup[]>(() => [
description: t('magic_keys.groups.navigation.go_to_notifications'), description: t('magic_keys.groups.navigation.go_to_notifications'),
shortcut: { keys: ['g', 'n'], isSequence: true }, shortcut: { keys: ['g', 'n'], isSequence: true },
}, },
{
description: t('magic_keys.groups.navigation.go_to_conversations'),
shortcut: { keys: ['g', 'c'], isSequence: true },
},
{
description: t('magic_keys.groups.navigation.go_to_favourites'),
shortcut: { keys: ['g', 'f'], isSequence: true },
},
{
description: t('magic_keys.groups.navigation.go_to_bookmarks'),
shortcut: { keys: ['g', 'b'], isSequence: true },
},
{
description: t('magic_keys.groups.navigation.go_to_explore'),
shortcut: { keys: ['g', 'e'], isSequence: true },
},
{
description: t('magic_keys.groups.navigation.go_to_local'),
shortcut: { keys: ['g', 'l'], isSequence: true },
},
{
description: t('magic_keys.groups.navigation.go_to_federated'),
shortcut: { keys: ['g', 't'], isSequence: true },
},
{
description: t('magic_keys.groups.navigation.go_to_lists'),
shortcut: { keys: ['g', 'i'], isSequence: true },
},
{
description: t('magic_keys.groups.navigation.go_to_settings'),
shortcut: { keys: ['g', 's'], isSequence: true },
},
{
description: t('magic_keys.groups.navigation.go_to_profile'),
shortcut: { keys: ['g', 'p'], isSequence: true },
},
], ],
}, },
{ {

View File

@ -226,7 +226,7 @@
"boost": "Boost", "boost": "Boost",
"command_mode": "Command mode", "command_mode": "Command mode",
"compose": "Compose", "compose": "Compose",
"favourite": "Favourite", "favourite": "Favorite",
"search": "Search", "search": "Search",
"show_new_items": "Show new items", "show_new_items": "Show new items",
"title": "Actions" "title": "Actions"
@ -235,8 +235,18 @@
"title": "Media" "title": "Media"
}, },
"navigation": { "navigation": {
"go_to_bookmarks": "Bookmarks",
"go_to_conversations": "Conversations",
"go_to_explore": "Explore",
"go_to_favourites": "Favorites",
"go_to_federated": "Federated",
"go_to_home": "Home", "go_to_home": "Home",
"go_to_lists": "Lists",
"go_to_local": "Local",
"go_to_notifications": "Notifications", "go_to_notifications": "Notifications",
"go_to_profile": "Profile",
"go_to_search": "Search",
"go_to_settings": "Settings",
"next_status": "Next post", "next_status": "Next post",
"previous_status": "Previous post", "previous_status": "Previous post",
"shortcut_help": "Shortcut help", "shortcut_help": "Shortcut help",

View File

@ -1,5 +1,6 @@
import type { RouteLocationRaw } from 'vue-router' import type { RouteLocationRaw } from 'vue-router'
import { useMagicSequence } from '~/composables/magickeys' import { useMagicSequence } from '~/composables/magickeys'
import { currentUser, getInstanceDomain } from '~/composables/users'
export default defineNuxtPlugin(({ $scrollToTop }) => { export default defineNuxtPlugin(({ $scrollToTop }) => {
const keys = useMagicKeys() const keys = useMagicKeys()
@ -35,8 +36,20 @@ export default defineNuxtPlugin(({ $scrollToTop }) => {
} }
whenever(logicAnd(isAuthenticated, notUsingInput, keys.c), defaultPublishDialog) whenever(logicAnd(isAuthenticated, notUsingInput, keys.c), defaultPublishDialog)
const instanceDomain = currentInstance.value ? getInstanceDomain(currentInstance.value) : 'm.webtoo.ls'
whenever(logicAnd(notUsingInput, useMagicSequence(['g', 'h'])), () => navigateTo('/home')) whenever(logicAnd(notUsingInput, useMagicSequence(['g', 'h'])), () => navigateTo('/home'))
whenever(logicAnd(isAuthenticated, notUsingInput, useMagicSequence(['g', 'n'])), () => navigateTo('/notifications')) whenever(logicAnd(isAuthenticated, notUsingInput, useMagicSequence(['g', 'n'])), () => navigateTo('/notifications'))
// TODO: always overridden by 'c' (compose) shortcut
whenever(logicAnd(isAuthenticated, notUsingInput, useMagicSequence(['g', 'c'])), () => navigateTo('/conversations'))
whenever(logicAnd(isAuthenticated, notUsingInput, useMagicSequence(['g', 'f'])), () => navigateTo('/favourites'))
whenever(logicAnd(isAuthenticated, notUsingInput, useMagicSequence(['g', 'b'])), () => navigateTo('/bookmarks'))
whenever(logicAnd(notUsingInput, useMagicSequence(['g', 'e'])), () => navigateTo(`/${instanceDomain}/explore`))
whenever(logicAnd(notUsingInput, useMagicSequence(['g', 'l'])), () => navigateTo(`/${instanceDomain}/public/local`))
whenever(logicAnd(notUsingInput, useMagicSequence(['g', 't'])), () => navigateTo(`/${instanceDomain}/public`))
whenever(logicAnd(isAuthenticated, notUsingInput, useMagicSequence(['g', 'i'])), () => navigateTo('/lists'))
whenever(logicAnd(notUsingInput, useMagicSequence(['g', 's'])), () => navigateTo('/settings'))
whenever(logicAnd(isAuthenticated, notUsingInput, useMagicSequence(['g', 'p'])), () => navigateTo(`/${instanceDomain}/@${currentUser.value?.account.username}`))
whenever(logicAnd(notUsingInput, keys['/']), () => navigateTo('/search'))
const toggleFavouriteActiveStatus = () => { const toggleFavouriteActiveStatus = () => {
// TODO: find a better solution than clicking buttons... // TODO: find a better solution than clicking buttons...