refactor: if/else conditions (#1822)

* refactor: shortcuts if/else

* fix: merge conflict
This commit is contained in:
Dakshesh Jain 2023-08-10 13:12:17 +05:30 committed by GitHub
parent 1c6cdb8328
commit 9ce85cdf21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -78,38 +78,39 @@ export const CommandPalette: React.FC = () => {
const handleKeyDown = useCallback( const handleKeyDown = useCallback(
(e: KeyboardEvent) => { (e: KeyboardEvent) => {
const singleShortcutKeys = ["p", "v", "d", "h", "q", "m"]; // if on input, textarea or editor, don't do anything
const { key, ctrlKey, metaKey, altKey, shiftKey } = e;
if (!key) return;
const keyPressed = key.toLowerCase();
if ( if (
!(e.target instanceof HTMLTextAreaElement) && e.target instanceof HTMLTextAreaElement ||
!(e.target instanceof HTMLInputElement) && e.target instanceof HTMLInputElement ||
!(e.target as Element).classList?.contains("remirror-editor") (e.target as Element).classList?.contains("remirror-editor")
) { )
if ((ctrlKey || metaKey) && keyPressed === "k") { return;
const { key, ctrlKey, metaKey, altKey, shiftKey } = e;
if (!key) return;
const keyPressed = key.toLowerCase();
const cmdClicked = ctrlKey || metaKey;
if (cmdClicked) {
if (keyPressed === "k") {
e.preventDefault(); e.preventDefault();
setIsPaletteOpen(true); setIsPaletteOpen(true);
} else if ((ctrlKey || metaKey) && keyPressed === "c") { } else if (keyPressed === "c" && altKey) {
if (altKey) {
e.preventDefault();
copyIssueUrlToClipboard();
}
} else if (keyPressed === "c") {
e.preventDefault(); e.preventDefault();
setIsIssueModalOpen(true); copyIssueUrlToClipboard();
} else if ((ctrlKey || metaKey) && keyPressed === "b") { } else if (keyPressed === "b") {
e.preventDefault(); e.preventDefault();
// toggleCollapsed(); toggleCollapsed();
store.theme.setSidebarCollapsed(!store?.theme?.sidebarCollapsed); } else if (keyPressed === "backspace") {
} else if (key === "Delete") {
e.preventDefault(); e.preventDefault();
setIsBulkDeleteIssuesModalOpen(true); setIsBulkDeleteIssuesModalOpen(true);
} else if ( }
singleShortcutKeys.includes(keyPressed) && } else {
(ctrlKey || metaKey || altKey || shiftKey) if (keyPressed === "c") {
) { setIsIssueModalOpen(true);
e.preventDefault();
} else if (keyPressed === "p") { } else if (keyPressed === "p") {
setIsProjectModalOpen(true); setIsProjectModalOpen(true);
} else if (keyPressed === "v") { } else if (keyPressed === "v") {
@ -125,7 +126,7 @@ export const CommandPalette: React.FC = () => {
} }
} }
}, },
[copyIssueUrlToClipboard] [copyIssueUrlToClipboard, toggleCollapsed]
); );
useEffect(() => { useEffect(() => {