mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
improve kbd nav command center
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
export let clearOnCallback = true;
|
||||
|
||||
let selected = 0;
|
||||
let usingKeyboard = false;
|
||||
let contentEl: HTMLElement;
|
||||
|
||||
async function triggerOption(option: Option) {
|
||||
@@ -38,6 +39,7 @@
|
||||
|
||||
function handleKeyDown(event: KeyboardEvent) {
|
||||
if (!open) return;
|
||||
usingKeyboard = true;
|
||||
|
||||
let canceled = false;
|
||||
dispatch('keydown', {
|
||||
@@ -108,6 +110,8 @@
|
||||
|
||||
$: if (selected > options?.length - 1) {
|
||||
selected = options?.length - 1;
|
||||
} else if (usingKeyboard && selected < 0 && options?.length) {
|
||||
selected = 0;
|
||||
}
|
||||
|
||||
const commandCenterCtx = getCommandCenterCtx();
|
||||
@@ -188,12 +192,16 @@
|
||||
triggerOption(option);
|
||||
};
|
||||
|
||||
const getOptionFocusHandler = (option: IndexedOption) => () => {
|
||||
selected = option.index;
|
||||
};
|
||||
const getOptionFocusHandler =
|
||||
(option: IndexedOption, hover = false) =>
|
||||
() => {
|
||||
selected = option.index;
|
||||
usingKeyboard = hover ? false : usingKeyboard;
|
||||
};
|
||||
|
||||
const getOptionBlurHandler = () => () => {
|
||||
selected = -1;
|
||||
usingKeyboard = false;
|
||||
};
|
||||
|
||||
const castOption = (option: IndexedOption) => option as Option;
|
||||
@@ -290,7 +298,7 @@
|
||||
<button
|
||||
class="option"
|
||||
on:click={getOptionClickHandler(item)}
|
||||
on:mouseover={getOptionFocusHandler(item)}
|
||||
on:mouseover={getOptionFocusHandler(item, true)}
|
||||
on:mouseleave={getOptionBlurHandler()}
|
||||
on:focus={getOptionFocusHandler(item)}>
|
||||
<slot name="option" option={castOption(item)}>
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { page } from '$app/stores';
|
||||
import { registerCommands, updateCommandGroupRanks } from '$lib/commandCenter';
|
||||
import { project } from '../store';
|
||||
import { openCreateDomainWizard } from './domains/+page.svelte';
|
||||
import { openWebhooksWizard } from './webhooks/+page.svelte';
|
||||
|
||||
@@ -24,59 +22,6 @@
|
||||
openWebhooksWizard();
|
||||
},
|
||||
group: 'webhooks'
|
||||
},
|
||||
{
|
||||
label: 'Go to settings overview',
|
||||
|
||||
keys: ['g', 'o'],
|
||||
callback: () => {
|
||||
goto(`/console/project-${$project.$id}/settings`);
|
||||
},
|
||||
disabled: $page.url.pathname.endsWith('settings'),
|
||||
group: 'navigation',
|
||||
rank: 40
|
||||
},
|
||||
{
|
||||
label: 'Go to custom domains',
|
||||
|
||||
keys: ['g', 'd'],
|
||||
callback: () => {
|
||||
goto(`/console/project-${$project.$id}/settings/domains`);
|
||||
},
|
||||
disabled: $page.url.pathname.includes('domains'),
|
||||
group: 'navigation',
|
||||
rank: 30
|
||||
},
|
||||
{
|
||||
label: 'Go to webhooks',
|
||||
keys: ['g', 'w'],
|
||||
callback: () => {
|
||||
goto(`/console/project-${$project.$id}/settings/webhooks`);
|
||||
},
|
||||
disabled: $page.url.pathname.includes('webhooks'),
|
||||
group: 'navigation',
|
||||
|
||||
rank: 20
|
||||
},
|
||||
{
|
||||
label: 'Go to migrations',
|
||||
keys: ['g', 'm'],
|
||||
callback: () => {
|
||||
goto(`/console/project-${$project.$id}/settings/migrations`);
|
||||
},
|
||||
disabled: $page.url.pathname.includes('migrations'),
|
||||
group: 'navigation',
|
||||
|
||||
rank: 10
|
||||
},
|
||||
{
|
||||
label: 'Go to SMTP settings',
|
||||
keys: ['g', 's'],
|
||||
callback: () => {
|
||||
goto(`/console/project-${$project.$id}/settings/smtp`);
|
||||
},
|
||||
disabled: $page.url.pathname.includes('smtp'),
|
||||
group: 'navigation'
|
||||
}
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user