mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
fix: command key order
This commit is contained in:
1 parent
bf77043c8e
commit
adbd2c7f53
5 files changed
+60
-54
No files matched your search
@@ -78,11 +78,11 @@ export const commandCenterKeyDownHandler = derived(
|
||||
[commandCenter, commandsEnabled],
|
||||
([{ commandMap }, enabled]) => {
|
||||
const commandsArr = Array.from(commandMap.values()).flat();
|
||||
const recentKeyCodes = new Set<number>();
|
||||
let recentKeyCodes: number[] = [];
|
||||
|
||||
return (event: KeyboardEvent) => {
|
||||
recentKeyCodes.add(event.keyCode);
|
||||
debounce(() => recentKeyCodes.clear(), 1000)();
|
||||
recentKeyCodes.push(event.keyCode);
|
||||
debounce(() => (recentKeyCodes = []), 1000)();
|
||||
|
||||
for (const command of commandsArr) {
|
||||
if (command.disabled || (!enabled && !command.forceEnable)) continue;
|
||||
@@ -94,9 +94,7 @@ export const commandCenterKeyDownHandler = derived(
|
||||
const isAltPressed = alt ? event.altKey : true;
|
||||
|
||||
const commandKeyCodes = keys.map((key) => key.toUpperCase().charCodeAt(0));
|
||||
const allKeysPressed = commandKeyCodes.every((keyCode) =>
|
||||
recentKeyCodes.has(keyCode)
|
||||
);
|
||||
const allKeysPressed = recentKeyCodes.join('').includes(commandKeyCodes.join(''));
|
||||
|
||||
if (allKeysPressed && isMetaPressed && isShiftPressed && isAltPressed) {
|
||||
event.preventDefault();
|
||||
|
||||
@@ -34,8 +34,7 @@
|
||||
callback: () => {
|
||||
goto('/console');
|
||||
},
|
||||
keys: ['h'],
|
||||
alt: true
|
||||
keys: ['g', 'h']
|
||||
}
|
||||
]);
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
<span>
|
||||
{command.label}
|
||||
</span>
|
||||
<div class="u-flex u-gap-4">
|
||||
<div class="u-flex u-gap-4 u-cross-center">
|
||||
{#if command.ctrl}
|
||||
<kbd class="kbd"> {isMac() ? '⌘' : 'ctrl'} </kbd>
|
||||
{/if}
|
||||
@@ -75,10 +75,15 @@
|
||||
{#if command.alt}
|
||||
<kbd class="kbd"> {isMac() ? '⌥' : 'alt'} </kbd>
|
||||
{/if}
|
||||
{#each command.keys as key}
|
||||
{#each command.keys as key, i}
|
||||
{@const hasNext = command.keys.length - 1 !== i}
|
||||
|
||||
<kbd class="kbd">
|
||||
{key.toUpperCase()}
|
||||
</kbd>
|
||||
{#if hasNext}
|
||||
<span class="u-margin-inline-4" style:opacity={0.5}>then</span>
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
</li>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import { CardContainer, Empty, GridItem1, Heading, PaginationWithLimit } from '$lib/components';
|
||||
import { Pill } from '$lib/elements';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import { registerCommand } from '$lib/helpers/commandCenter';
|
||||
import { disableCommands, registerCommand } from '$lib/helpers/commandCenter';
|
||||
import { Container } from '$lib/layout';
|
||||
import CreateOrganization from '../createOrganization.svelte';
|
||||
import type { PageData } from './$types';
|
||||
@@ -63,6 +63,8 @@
|
||||
disabled: showCreate
|
||||
}
|
||||
]);
|
||||
|
||||
$: $disableCommands(showCreate);
|
||||
</script>
|
||||
|
||||
<Container>
|
||||
|
||||
@@ -7,51 +7,53 @@ import { derived, writable, type Readable } from 'svelte/store';
|
||||
|
||||
export const project = derived(page, ($page) => $page.data.project as Models.Project);
|
||||
|
||||
export const registerProjectCommand = derived([project, registerCommand], ([$project, $register]) => {
|
||||
return (c: Command[] = []) =>
|
||||
$register([
|
||||
...[
|
||||
{
|
||||
label: 'Go to Overview',
|
||||
keys: ['o'],
|
||||
callback: () => {
|
||||
goto(`/console/project-${$project.$id}`);
|
||||
}
|
||||
},
|
||||
export const registerProjectCommand = derived(
|
||||
[project, registerCommand],
|
||||
([$project, $register]) => {
|
||||
return (c: Command[] = []) => {
|
||||
const projectCommands: Command[] = [
|
||||
{
|
||||
label: 'Go to Overview',
|
||||
keys: ['g', 'o'],
|
||||
|
||||
{
|
||||
label: 'Go to Auth',
|
||||
callback: () => {
|
||||
goto(`/console/project-${$project.$id}/auth`);
|
||||
},
|
||||
keys: ['a']
|
||||
},
|
||||
{
|
||||
label: 'Go to Databases',
|
||||
callback: () => {
|
||||
goto(`/console/project-${$project.$id}/databases`);
|
||||
},
|
||||
keys: ['d']
|
||||
},
|
||||
{
|
||||
label: 'Go to Functions',
|
||||
callback: () => {
|
||||
goto(`/console/project-${$project.$id}/functions`);
|
||||
},
|
||||
keys: ['f']
|
||||
},
|
||||
{
|
||||
label: 'Go to Storage',
|
||||
callback: () => {
|
||||
goto(`/console/project-${$project.$id}/storage`);
|
||||
},
|
||||
keys: ['s']
|
||||
callback: () => {
|
||||
goto(`/console/project-${$project.$id}`);
|
||||
}
|
||||
],
|
||||
...(c ?? [])
|
||||
])
|
||||
|
||||
}) as Readable<(c?: Command[]) => void>;
|
||||
},
|
||||
|
||||
{
|
||||
label: 'Go to Auth',
|
||||
callback: () => {
|
||||
goto(`/console/project-${$project.$id}/auth`);
|
||||
},
|
||||
keys: ['g', 'a']
|
||||
},
|
||||
{
|
||||
label: 'Go to Databases',
|
||||
callback: () => {
|
||||
goto(`/console/project-${$project.$id}/databases`);
|
||||
},
|
||||
keys: ['g', 'd']
|
||||
},
|
||||
{
|
||||
label: 'Go to Functions',
|
||||
callback: () => {
|
||||
goto(`/console/project-${$project.$id}/functions`);
|
||||
},
|
||||
keys: ['g', 'f']
|
||||
},
|
||||
{
|
||||
label: 'Go to Storage',
|
||||
callback: () => {
|
||||
goto(`/console/project-${$project.$id}/storage`);
|
||||
},
|
||||
keys: ['g', 's']
|
||||
}
|
||||
];
|
||||
return $register([...projectCommands, ...(c ?? [])]);
|
||||
};
|
||||
}
|
||||
) as Readable<(c?: Command[]) => void>;
|
||||
|
||||
export const onboarding = derived(
|
||||
project,
|
||||
|
||||
Reference in new issue
Block a user