From d38e349a92f2e0e1f1da436f2fa0d557fec1b8c3 Mon Sep 17 00:00:00 2001 From: Triston Armstrong Date: Sun, 6 Oct 2024 07:46:46 -0400 Subject: [PATCH] make resize note card work properly --- src/components/NoteCard.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/components/NoteCard.tsx b/src/components/NoteCard.tsx index b798717..10f3d19 100644 --- a/src/components/NoteCard.tsx +++ b/src/components/NoteCard.tsx @@ -1,4 +1,4 @@ -import { signal, useRef } from "kaioken" +import { signal, useCallback, useRef } from "kaioken" import { NotesSigal, focusedItem } from "../signals" import { useDebounce } from "../utils/useDebounce" import notes, { NoteCardType } from "../signals/notes" @@ -60,20 +60,29 @@ export function NoteCard({ key: itemKey, data: item }: NoteCard.NoteCardProps) { function _handleResizeMove(e: MouseEvent) { const { pageX, pageY } = e const [newX, newY] = [initialResizeX.current - pageX, initialResizeY.current - pageY] - NotesSigal.default.updateNoteProperty(itemKey, 'dimensions', { w: -newX + item.dimensions.w, h: -newY + item.dimensions.h }) + + const newW = -newX + item.dimensions.w + const newH = -newY + item.dimensions.h + const newDim = { w: newW, h: newH } + + NotesSigal.default.updateNoteProperty(itemKey, 'dimensions', newDim) + NotesSigal.default.notes.notify() } + function _handleResizeMouseDown(e: MouseEvent) { - if (pressed.value) return _handleResizeMouseUp() initialResizeX.current = e.pageX initialResizeY.current = e.pageY pressed.value = true window.addEventListener('mousemove', _handleResizeMove) + window.addEventListener('mouseup', _handleResizeMouseUp) } function _handleResizeMouseUp() { pressed.value = false + updateLocalStorage() window.removeEventListener('mousemove', _handleResizeMove) + window.removeEventListener('mouseup', _handleResizeMouseUp) } return ( @@ -116,7 +125,6 @@ export function NoteCard({ key: itemKey, data: item }: NoteCard.NoteCardProps) {