import { h, Component } from "preact"; import { IVault, ViewNote } from "../../../notes"; import { Trash2 as Trash, X, Save } from "preact-feather"; import Navigation from "../../../navigation"; import { YesNoModal } from "../../modals/YesNoModal"; import Notifications, { MessageType } from "../../../notifications"; import CodeMirror from "../../CodeMirror"; import { useEffect, useMemo, useState } from "preact/hooks"; import { usePromise } from "../../../hooks"; interface IEntryProps { vault: IVault; id?: string; note?: string; } export default function Entry(props: IEntryProps) { const [changed, setChanged] = useState(false); const [text, setText] = useState(""); const title = useMemo(() => text?.split("\n", 1)[0], [text]); const [loading, error, note] = usePromise(async () => { let note: ViewNote; if (props.id) { note = await props.vault.getNote(props.id); } else { note = props.vault.newNote(); if (props.note) { note.__value = props.note; setChanged(true); } } if (!note) { Notifications.sendNotification("Note not found!", MessageType.ERROR); history.back(); } else { setText(note.__value); } return note; }, [props.vault, props.id]); if (loading) { return