From 412ae1c7406fce2b75ae20d04d6d1286b3c0a76c Mon Sep 17 00:00:00 2001 From: Triston Armstrong Date: Wed, 9 Oct 2024 00:22:53 -0400 Subject: [PATCH] refactor a bit for readability --- src/components/NoteCard.tsx | 47 +++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/src/components/NoteCard.tsx b/src/components/NoteCard.tsx index 7979d98..bd22e71 100644 --- a/src/components/NoteCard.tsx +++ b/src/components/NoteCard.tsx @@ -30,6 +30,7 @@ export function NoteCard({ key: itemKey, data: item }: NoteCard.NoteCardProps) { function updateLocalStorage(time?: number) { debounce(() => { localStorage.setItem("notes", JSON.stringify(notes.notes.value)) + saved.value = true }, time) } @@ -93,37 +94,47 @@ export function NoteCard({ key: itemKey, data: item }: NoteCard.NoteCardProps) { NotesSigal.default.updateNoteProperty(itemKey, 'contents', e.content) NotesSigal.default.notes.notify() updateLocalStorage() + saved.value = false + } + + function _handleClose(_e: Event) { + NotesSigal.default.removeNote(item.id) + NotesSigal.default.notes.notify() + updateLocalStorage() + } + + function _handleFocusCard() { + focusedItem.value = itemKey + } + + const cardPositionStyle = { + zIndex: `${focusedItem.value == itemKey ? LayerEnum.CARD_ELEVATED : LayerEnum.CARD}`, + width: `${item.dimensions.w}px`, + height: `${item.dimensions.h}px`, + top: `${item.position.y}px`, + left: `${item.position.x}px`, + } + + const saveIndicatorStyle = { + opacity: saved.value ? '0' : '100' } return (
focusedItem.value = itemKey} + onmousedown={_handleFocusCard} + style={cardPositionStyle} className="overflow-hidden text-[#333] dark:bg-[#1a1a1a] dark:border-[#1c1c1c] bg-[#eee] select-none transition flex flex-col justify-stretch shadow-md rounded border border-[#ddd] absolute" - style={{ - zIndex: `${focusedItem.value == itemKey ? LayerEnum.CARD_ELEVATED : LayerEnum.CARD}`, - width: `${item.dimensions.w}px`, - height: `${item.dimensions.h}px`, - top: `${item.position.y}px`, - left: `${item.position.x}px`, - }} >
-
- +
+
+
- -