diff --git a/src/components/NoteCard.tsx b/src/components/NoteCard.tsx index ff18c7b..776042e 100644 --- a/src/components/NoteCard.tsx +++ b/src/components/NoteCard.tsx @@ -1,4 +1,4 @@ -import { signal, useRef } from "kaioken" +import { signal, useCallback, useEffect, useRef } from "kaioken" import { NotesSigal, focusedItem } from "../signals" import { useDebounce } from "../utils/useDebounce" import notes, { NoteCardType } from "../signals/notes" @@ -10,6 +10,7 @@ import { Divider } from "./Divider" import { ExportIcon } from "./icons/ExportIcon" import { createFileAndExport } from "../utils/createFileAndExport" import { ContextMenuPortal } from "./ContextMenuPortal" +import { HelpIcon } from "./icons/HelpIcon" namespace NoteCard { export interface NoteCardProps { @@ -28,6 +29,7 @@ export function NoteCard({ key: itemKey, data: item }: NoteCard.NoteCardProps) { const initialResizeX = useRef(0) const initialResizeY = useRef(0) const openContextMenu = signal(false) + const showHelp = signal(false) const { debounce } = useDebounce() @@ -111,10 +113,14 @@ export function NoteCard({ key: itemKey, data: item }: NoteCard.NoteCardProps) { focusedItem.value = itemKey } - function _handleExportClick(_e: MouseEvent) { + function _exportFile() { createFileAndExport("Note", item.contents, "text/markdown") } + function _handleExportClick(_e: MouseEvent) { + _exportFile() + } + function _handleMouseClick(e: MouseEvent) { e.preventDefault() openContextMenu.value = !openContextMenu.value @@ -124,6 +130,49 @@ export function NoteCard({ key: itemKey, data: item }: NoteCard.NoteCardProps) { openContextMenu.value = false } + function _handleHelpHover() { + if (showHelp.value) return + showHelp.value = true + } + + function _handleHelpOut() { + if (!showHelp.value) return + showHelp.value = false + } + + const _handleKeyDown = useCallback((e: KeyboardEvent) => { + if (!e.ctrlKey) return + + // TODO: add support for other os + // TODO: add modal popup + + switch (e.key) { + case 'Delete': + e.preventDefault() + _handleClose(e) + break + case 'Backspace': + e.preventDefault() + _handleClose(e) + break + case 'e': + e.preventDefault() + _exportFile() + break + default: + break + } + }, [itemKey, item.position, NotesSigal.default]) + + useEffect(() => { + if (focusedItem.value !== itemKey) return + window.addEventListener('keydown', _handleKeyDown) + return () => { + window.removeEventListener('keydown', _handleKeyDown) + } + + }, [focusedItem.value, itemKey]) + const cardPositionStyle = { zIndex: `${focusedItem.value == itemKey ? LayerEnum.CARD_ELEVATED : LayerEnum.CARD}`, width: `${item.dimensions.w}px`, @@ -137,68 +186,89 @@ export function NoteCard({ key: itemKey, data: item }: NoteCard.NoteCardProps) { } return ( -
-
- {/* Header Bar */} -
-
- -
-
- + <> +
+
+ {/* Header Bar */} +
+
+ + {/* Save indicator*/} +
+
+
+ +
- + - + -
-
- -
- - {/* Content Body */} - - -
- - -
-
-
- {item.title}
-
+
-
-
    -
  • - -
  • -
  • - -
  • -
+ {/* Content Body */} + + +
+ + +
+
+
+ {item.title} +
+
+ +
+ +
+
    +
  • + +
  • +
  • + +
  • +
+
+
+
+
+ + {/* HOTKEY PAPER */} + {showHelp.value && +
+
+ ctrl + del = delete + ctrl + back = delete + ctrl + e = export
-
-
- + } + ) } @@ -228,3 +298,4 @@ function ExpandIcon({ cb }: { ) } + diff --git a/src/components/icons/HelpIcon.tsx b/src/components/icons/HelpIcon.tsx new file mode 100644 index 0000000..17b18f7 --- /dev/null +++ b/src/components/icons/HelpIcon.tsx @@ -0,0 +1,35 @@ +namespace HelpIcon { + export interface Props { + onMouseOver?: () => void + onMouseOut?: () => void + } +} +export function HelpIcon({ onMouseOver, onMouseOut }: HelpIcon.Props) { + + return ( + + + + + ) +}