1
0

Remove shortcuts again, just trigger command pallete

This commit is contained in:
Zef Hemel
2022-06-20 18:30:45 +02:00
parent 4ada18a213
commit 94d0e31b30
8 changed files with 29 additions and 110 deletions
+8 -39
View File
@@ -1,5 +1,6 @@
import { useEffect, useState } from "react";
import { ShortcutItem, Notification } from "../types";
import { faRunning } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { Notification } from "../types";
function prettyName(s: string | undefined): string {
if (!s) {
@@ -12,33 +13,19 @@ export function TopBar({
pageName,
unsavedChanges,
notifications,
shortcutItems,
onClick,
onActionClick,
lhs,
rhs,
}: {
pageName?: string;
unsavedChanges: boolean;
notifications: Notification[];
shortcutItems: ShortcutItem[];
onClick: () => void;
onActionClick: () => void;
lhs?: React.ReactNode;
rhs?: React.ReactNode;
}) {
const [menuExpanded, setMenuExpanded] = useState(false);
useEffect(() => {
function closer() {
setMenuExpanded(false);
}
document.addEventListener("click", closer);
return () => {
document.removeEventListener("click", closer);
};
}, []);
return (
<div id="top" onClick={onClick}>
{lhs}
@@ -59,31 +46,13 @@ export function TopBar({
<div className="actions">
<button
onClick={(e) => {
setMenuExpanded(!menuExpanded);
// setMenuExpanded(!menuExpanded);
onActionClick();
e.stopPropagation();
}}
>
...
<FontAwesomeIcon icon={faRunning} />
</button>
{menuExpanded && (
<ul>
{shortcutItems.map((actionButton, idx) => (
<li key={idx}>
<a
href="#"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
setMenuExpanded(false);
actionButton.run();
}}
>
{actionButton.label}
</a>
</li>
))}
</ul>
)}
</div>
</div>
</div>