pinafore/src/routes/_components/NavShortcuts.html

62 lines
2.1 KiB
HTML

<Shortcut key="g t" on:pressed="goto('/federated')"/>
<Shortcut key="g f" on:pressed="goto('/favorites')"/>
<Shortcut key="g l" on:pressed="goto('/local')"/>
<Shortcut key="g h" on:pressed="goto('/')"/>
<Shortcut key="g n" on:pressed="goto('/notifications')"/>
<Shortcut key="g c" on:pressed="goto('/community')"/>
<Shortcut key="g d" on:pressed="goto('/direct')"/>
<Shortcut key="s" on:pressed="goto('/search')"/>
<Shortcut key="h|?" on:pressed="showShortcutHelpDialog()"/>
<Shortcut key="c|7" on:pressed="showComposeDialog()"/>
{#if !$leftRightChangesFocus}
<Shortcut key="ArrowLeft" on:pressed="goLeftOrRight(true)" />
<Shortcut key="ArrowRight" on:pressed="goLeftOrRight(false)" />
{/if}
{#each $navPages as navPage, i}
<Shortcut key={(i + 1).toString()} on:pressed="goto(navPage.href)" />
{/each}
<script>
import Shortcut from './shortcut/Shortcut'
import { goto } from '../../../__sapper__/client'
import { importShowShortcutHelpDialog } from './dialog/asyncDialogs/importShowShortcutHelpDialog'
import { importShowComposeDialog } from './dialog/asyncDialogs/importShowComposeDialog'
import { store } from '../_store/store'
export default {
store: () => store,
components: {
Shortcut
},
methods: {
oncreate () {
console.log('nav shortcuts')
},
goto,
async showShortcutHelpDialog () {
const showShortcutHelpDialog = await importShowShortcutHelpDialog()
showShortcutHelpDialog()
},
async showComposeDialog () {
const showComposeDialog = await importShowComposeDialog()
showComposeDialog()
},
goLeftOrRight (left) {
let { currentPage, navPages } = this.store.get()
if (currentPage === 'notifications/mentions') { // special case
currentPage = 'notifications'
}
const idx = navPages.findIndex(_ => _.name === currentPage)
if (idx === -1) {
return
}
if (left && idx > 0) {
goto(navPages[idx - 1].href)
} else if (!left && idx < navPages.length - 1) {
goto(navPages[idx + 1].href)
}
}
}
}
</script>