Merge pull request #900 from TGlide/fix-command-center

Command Center key improvements
This commit is contained in:
Christy Jacob authored and GitHub committed 2024-02-29 23:38:17 +05:30
commit 217b27a189
3 files changed
+36 -8

No files matched your search

+21 -4
View File
@@ -5,6 +5,7 @@ import { onMount } from 'svelte';
import { derived, writable } from 'svelte/store';
import { nanoid } from 'nanoid/non-secure';
import { trackEvent } from '$lib/actions/analytics';
import { omit } from '$lib/helpers/omit';
const groups = [
'ungrouped',
@@ -73,7 +74,23 @@ export const disabledMap = writable<Map<string, boolean>>(new Map());
// Derived stores
export const commands = derived(commandMap, ($commandMap) => {
return Array.from($commandMap.values()).flat();
const res: Command[] = [];
const keys = new Set<string>();
const allCommands = Array.from($commandMap.values()).flat().toReversed();
for (const command of allCommands) {
if (isKeyedCommand(command) && !command.disabled) {
const keysString = command.keys.join('+');
if (keys.has(keysString)) {
res.push(omit(command, 'keys'));
continue;
}
keys.add(keysString);
}
res.push(command);
}
return res;
});
const commandsEnabled = derived(disabledMap, ($disabledMap) => {
@@ -113,9 +130,9 @@ function hasDisputing(command: KeyedCommand, allCommands: Command[]) {
}
export const commandCenterKeyDownHandler = derived(
[commandMap, commandsEnabled, wizard],
([$commandMap, enabled, $wizard]) => {
const commandsArr = Array.from($commandMap.values()).flat();
[commands, commandsEnabled, wizard],
([$commands, enabled, $wizard]) => {
const commandsArr = $commands;
let recentKeyCodes: number[] = [];
let validCommands: KeyedCommand[] = [];
+7
View File
@@ -0,0 +1,7 @@
export function omit<T, K extends keyof T>(obj: T, ...keys: K[]): Omit<T, K> {
const ret = { ...obj };
for (const key of keys) {
delete ret[key];
}
return ret;
}
@@ -1,7 +1,12 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import { addSubPanel, registerCommands, registerSearchers, updateCommandGroupRanks } from '$lib/commandCenter';
import {
addSubPanel,
registerCommands,
registerSearchers,
updateCommandGroupRanks
} from '$lib/commandCenter';
import { CreateMessagePanel } from '$lib/commandCenter/panels';
import { messagesSearcher } from '$lib/commandCenter/searchers/messages';
import { providersSearcher } from '$lib/commandCenter/searchers/providers';
@@ -27,7 +32,7 @@
disabled:
$page.url.pathname.endsWith('topics') || $page.url.pathname.includes('message-'),
group: 'messaging',
rank: 1,
rank: 1
},
{
label: 'Go to Providers',
@@ -38,8 +43,7 @@
disabled:
$page.url.pathname.endsWith('providers') || $page.url.pathname.includes('message-'),
group: 'messaging',
rank: 2,
forceEnable: true
rank: 2
}
]);