|
|
|
@ -1,14 +1,12 @@
|
|
|
|
|
import { h, Component } from "preact"
|
|
|
|
|
import Notes, { IVault, ViewNote } from "../../../notes";
|
|
|
|
|
import { IVault, ViewNote } from "../../../notes";
|
|
|
|
|
import Trash from "feather-icons/dist/icons/trash-2.svg"
|
|
|
|
|
import X from "feather-icons/dist/icons/x.svg"
|
|
|
|
|
import Save from "feather-icons/dist/icons/save.svg"
|
|
|
|
|
|
|
|
|
|
import Navigation from "../../../navigation";
|
|
|
|
|
import { YesNoModal } from "../../modals/YesNoModal";
|
|
|
|
|
import LoadingModal from "../../modals/LoadingModal";
|
|
|
|
|
import Notifications, { MessageType } from "../../../notifications";
|
|
|
|
|
import Modal from "../../modals/Modal";
|
|
|
|
|
|
|
|
|
|
const minRows = 3;
|
|
|
|
|
export default class EntryComponent extends Component<{ vault: Promise<IVault>, id: string | undefined, note: string | undefined }, { title: string, changed: boolean }> {
|
|
|
|
@ -21,15 +19,23 @@ export default class EntryComponent extends Component<{ vault: Promise<IVault>,
|
|
|
|
|
|
|
|
|
|
private skip_save: boolean = false;
|
|
|
|
|
|
|
|
|
|
private inputElm: HTMLInputElement;
|
|
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = { changed: false, title: "" };
|
|
|
|
|
this.textAreaChange = this.textAreaChange.bind(this);
|
|
|
|
|
this.textAreaKeyPress = this.textAreaKeyPress.bind(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private toVault() {
|
|
|
|
|
history.back();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
this.inputElm.focus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async componentWillMount() {
|
|
|
|
|
this.text = "";
|
|
|
|
|
this.vault = undefined;
|
|
|
|
@ -39,8 +45,6 @@ export default class EntryComponent extends Component<{ vault: Promise<IVault>,
|
|
|
|
|
this.setState({ changed: false, title: "" });
|
|
|
|
|
try {
|
|
|
|
|
this.skip_save = false;
|
|
|
|
|
// this.loading = new LoadingModal();
|
|
|
|
|
// this.loading.show();
|
|
|
|
|
|
|
|
|
|
this.vault = await this.props.vault;
|
|
|
|
|
let note: ViewNote;
|
|
|
|
@ -57,7 +61,6 @@ export default class EntryComponent extends Component<{ vault: Promise<IVault>,
|
|
|
|
|
|
|
|
|
|
if (!note) {
|
|
|
|
|
Notifications.sendNotification("Note not found!", MessageType.ERROR);
|
|
|
|
|
// this.toVault()
|
|
|
|
|
} else {
|
|
|
|
|
this.note = note;
|
|
|
|
|
this.text = note.__value;
|
|
|
|
@ -65,14 +68,8 @@ export default class EntryComponent extends Component<{ vault: Promise<IVault>,
|
|
|
|
|
if (rows !== this.rows) {
|
|
|
|
|
this.rows = rows;
|
|
|
|
|
}
|
|
|
|
|
// async onKeypress(event) {
|
|
|
|
|
// event = event || window.event;
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
let [title] = this.text.split("\n", 1);
|
|
|
|
|
this.setState({ title, changed })
|
|
|
|
|
// if (this.loading)
|
|
|
|
|
// this.loading.close();
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
Notifications.sendError(err);
|
|
|
|
@ -108,11 +105,12 @@ export default class EntryComponent extends Component<{ vault: Promise<IVault>,
|
|
|
|
|
|
|
|
|
|
textAreaChange(evt: KeyboardEvent) {
|
|
|
|
|
if (evt.keyCode === 17 || evt.keyCode === 27) return; //No character, so not relevant for this function
|
|
|
|
|
if (!this.state.changed && this.textAreaKeyPress(evt)) this.setState({ changed: true })
|
|
|
|
|
|
|
|
|
|
let target = (evt.target as HTMLTextAreaElement)
|
|
|
|
|
let value = target.value;
|
|
|
|
|
|
|
|
|
|
this.text = value;
|
|
|
|
|
if (!this.state.changed && this.textAreaKeyPress(evt)) this.setState({ changed: true })
|
|
|
|
|
|
|
|
|
|
let [title] = value.split("\n", 1);
|
|
|
|
|
if (title !== this.state.title)
|
|
|
|
@ -138,6 +136,7 @@ export default class EntryComponent extends Component<{ vault: Promise<IVault>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
textAreaKeyPress(evt: KeyboardEvent) {
|
|
|
|
|
console.log(evt);
|
|
|
|
|
if ((evt.keyCode === 83 || evt.keyCode === 13) && evt.ctrlKey) {
|
|
|
|
|
evt.preventDefault()
|
|
|
|
|
this.save();
|
|
|
|
@ -161,39 +160,27 @@ export default class EntryComponent extends Component<{ vault: Promise<IVault>,
|
|
|
|
|
const delete_handler = async () => {
|
|
|
|
|
await this.vault.deleteNote(this.props.id);
|
|
|
|
|
this.toVault()
|
|
|
|
|
// async onKeypress(event) {
|
|
|
|
|
// event = event || window.event;
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log("Rerender")
|
|
|
|
|
|
|
|
|
|
return <div>
|
|
|
|
|
<header class="uk-background-primary">
|
|
|
|
|
{/* <div> */}
|
|
|
|
|
<a class="header-icon-button" onClick={() => this.exitHandler()}><X height={undefined} width={undefined} /></a>
|
|
|
|
|
{this.state.changed ? <a class="header-icon-button" style="margin-left: 0.5em;" onClick={() => save_handler()}><Save height={undefined} width={undefined} /></a> : undefined}
|
|
|
|
|
{/* </div> */}
|
|
|
|
|
<h3 style="display:inline" class="button header-title">{this.state.title}</h3>
|
|
|
|
|
<a class="header-icon-button" onClick={() => delete_handler()}><Trash height={undefined} width={undefined} /></a>
|
|
|
|
|
</header>
|
|
|
|
|
<div class="uk-container">
|
|
|
|
|
<textarea
|
|
|
|
|
// async onKeypress(event) {
|
|
|
|
|
// event = event || window.event;
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
autofocus
|
|
|
|
|
value={this.text}
|
|
|
|
|
rows={this.rows}
|
|
|
|
|
class="doc uk-textarea"
|
|
|
|
|
style="width:100%;"
|
|
|
|
|
onInput={evt => this.textAreaChange(evt as KeyboardEvent)}
|
|
|
|
|
onKeyDown={evt => this.textAreaKeyPress(evt)}
|
|
|
|
|
onChange={evt => this.textAreaChange(evt as KeyboardEvent)}
|
|
|
|
|
ref={elm => {
|
|
|
|
|
if (elm)
|
|
|
|
|
setTimeout(() => elm.focus(), 500)
|
|
|
|
|
}}
|
|
|
|
|
onInput={this.textAreaChange}
|
|
|
|
|
onKeyDown={this.textAreaKeyPress}
|
|
|
|
|
onChange={this.textAreaChange}
|
|
|
|
|
ref={elm => this.inputElm = elm}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|