diff --git a/src/App.tsx b/src/App.tsx index 6a916bc..6b7b592 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,21 +1,5 @@ -import { useRef, useState } from "kaioken" +import InfiniteCanvas from "./components/InfinateCanvas" export function App() { - const [text, setText] = useState('') - const inputRef = useRef(null) - - function _handleTextInputChange(e: Event) { - setText((e.target as HTMLInputElement).value) - if (inputRef.current) inputRef.current.value = "" - } - - return ( -
-

{text}

-
-
- Text here -
- ) + return } - diff --git a/src/components/CardSelector.tsx b/src/components/CardSelector.tsx new file mode 100644 index 0000000..7259753 --- /dev/null +++ b/src/components/CardSelector.tsx @@ -0,0 +1,95 @@ +import { useRef } from "kaioken" +import { NotesSigal } from "../signals" + +export function CardSelector() { + const containerRef = useRef(null) + + return ( +
+ + +
+ ) +} + +function StickyNote() { + function _handleClick(e: MouseEvent) { + + NotesSigal.default.addNote({ + type: "note", + title: "New Note", + contents: "", + position: { + x: e.pageX - 100, + y: e.pageY + (window.innerHeight / 2) - 100 + }, + dimensions: { + w: 200, + h: 200 + } + }) + } + + return ( + + ) + +} + +function Image() { + function _handleClick() { + alert("created image") + } + + return ( + + ) +} diff --git a/src/components/InfinateCanvas.tsx b/src/components/InfinateCanvas.tsx new file mode 100644 index 0000000..d1b29c3 --- /dev/null +++ b/src/components/InfinateCanvas.tsx @@ -0,0 +1,61 @@ +import { useState, useRef, useEffect } from "kaioken" +import { CardSelector } from "./CardSelector" +import { NotesSigal } from "../signals" +import { NoteCard } from "./NoteCard" +import notes from "../signals/notes" + +export default function InfiniteCanvas() { + const [dimensions, setDimensions] = useState({ width: 3000, height: 3000 }) + const containerRef = useRef(null) + + + useEffect(() => { + window.scrollTo({ + left: (dimensions.width / 2) - (window.innerWidth / 2), + top: (dimensions.height / 2) - (window.innerHeight / 2) + }) + + const updateDimensions = () => { + setDimensions((prevDimensions) => ({ + width: Math.max(prevDimensions.width, window.innerWidth), + height: Math.max(prevDimensions.height, window.innerHeight), + })) + } + + updateDimensions() + window.addEventListener("resize", updateDimensions) + notes.loadLocalStorage() + + + return () => { + window.removeEventListener("resize", updateDimensions) + } + }, []) + + return ( + <> + + +
+
+ {Object.keys(NotesSigal.default.notes.value).map((itemKey: string) => { + const item = NotesSigal.default.notes.value[itemKey] + return ( + + ) + })} +
+
+ + ) +} diff --git a/src/components/NoteCard.tsx b/src/components/NoteCard.tsx new file mode 100644 index 0000000..4878f70 --- /dev/null +++ b/src/components/NoteCard.tsx @@ -0,0 +1,101 @@ +import { signal, useRef } from "kaioken" +import { NotesSigal, focusedItem } from "../signals" +import { Card } from "../types" +import { useDebounce } from "../utils/useDebounce" +import notes from "../signals/notes" +import { save } from "@tauri-apps/api/dialog" + +namespace NoteCard { + export interface NoteCardProps { + key: Card['id'] + data: Card + } +} + +export function NoteCard({ key: itemKey, data: item }: NoteCard.NoteCardProps) { + const saved = signal(true) + const pressed = signal(false) + const newX = useRef(0) + const newY = useRef(0) + const offsetX = useRef(0) + const offsetY = useRef(0) + const { debounce } = useDebounce() + + function updateLocalStorage(time?: number) { + debounce(() => { + console.log(itemKey, "updated storage") + localStorage.setItem("notes", JSON.stringify(notes.notes.value)) + }, time) + } + + function _handleMouseMove(e: MouseEvent) { + e.preventDefault() + if (!pressed.value) return + + newX.current = e.pageX - offsetX.current + newY.current = e.pageY - offsetY.current + const newPos = { x: newX.current, y: newY.current } + + NotesSigal.default.updateNoteProperty(itemKey, 'position', newPos) + updateLocalStorage() + } + + function _handleMouseUp(e: MouseEvent) { + e.preventDefault() + pressed.value = false + window.removeEventListener('mousemove', _handleMouseMove) + window.removeEventListener('mouseup', _handleMouseUp) + } + + function _handleMouseDown(e: MouseEvent) { + e.preventDefault() + offsetX.current = e.offsetX + offsetY.current = e.offsetY + pressed.value = true + window.addEventListener('mousemove', _handleMouseMove) + window.addEventListener('mouseup', _handleMouseUp) + } + + + + return ( +
focusedItem.value = itemKey} + className="select-none transition flex flex-col justify-stretch shadow-lg rounded border border-[#3c3c3c] absolute" + style={{ + zIndex: focusedItem.value == itemKey ? '999' : '0', + width: `${item.dimensions.w}px`, + height: `${item.dimensions.h}px`, + top: `${item.position.y}px`, + left: `${item.position.x}px`, + backgroundColor: '#181818', + }} + > +
+
+
+ +
+
+