Skip to content

Commit

Permalink
check for exsiting note, note saving improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Keating committed Aug 4, 2023
1 parent ec7f2e6 commit ff3651a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 25 deletions.
7 changes: 4 additions & 3 deletions src/lib/NoteDetail.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script>
// @ts-nocheck
import { addRxPlugin } from 'rxdb';
import { onMount } from 'svelte';
import { RxDBUpdatePlugin } from 'rxdb/plugins/update';
Expand All @@ -11,17 +13,16 @@
import Settings from './Settings.svelte';
let innerHeight;
let note;
onMount(async () => {
addRxPlugin(RxDBUpdatePlugin);
});
const handleDebounceSave = debounce(() => updateNote(), 1000);
const handleDebounceSave = debounce(() => updateNote(), 300);
const updateNote = async () => {
// @ts-ignore
await $selectedNote.incrementalModify((data) => {
await $selectedNote?.incrementalModify((data) => {
data.body = $bodyText;
data.updatedAt = new Date().getTime();
return data;
Expand Down
44 changes: 31 additions & 13 deletions src/lib/OmniBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
import IconXcircle from './IconXcircle.svelte';
import { omniMode, omniText, selectedNote, db } from './store';
import { omniMode, omniText, selectedNote, db, bodyText } from './store';
let omniInput, showMenu;
let omniInput;
onMount(() => omniInput.focus());
const clearSelection = (e) => {
if (e.keyCode === 27) {
omniText.set('');
bodyText.set('');
omniInput.focus();
}
};
Expand All @@ -24,18 +25,35 @@
const addNote = async () => {
const db$ = await db();
await db$.notes
.insert({
guid: uuidv4(),
name: $omniText,
createdAt: new Date().getTime(),
updatedAt: new Date().getTime(),
})
.then((note) => {
await db$.notes.findOne({ selector: { name: $omniText } }).exec().then((note) => {
omniMode.set('edit');
if (note) {
console.log('note found so lets edit it note: ', note);
selectedNote.set(note);
omniMode.set('edit');
})
.then(() => document.getElementById('body-editor').focus());
omniText.set(note.name);
bodyText.set(note.body);
return;
} else {
console.log('no note found so lets create one');
db$.notes
.insert({
guid: uuidv4(),
name: $omniText,
createdAt: new Date().getTime(),
updatedAt: new Date().getTime(),
})
.then((note) => {
selectedNote.set(note);
omniMode.set('edit');
bodyText.set('');
});
return;
}
}).then(
setTimeout(() => {
document.getElementById('body-editor')?.focus();
}, 50),
);
};
</script>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/StatusBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
>
<div class="flex-grow flex items-center">nvAux v0.1.5-20230719-032</div>
<div>
<button on:click={() => $fullScreen = !$fullScreen} style="margin-right: 10px; color: #ed0178" class="bg-transparent flex items-center outline-none">
<button on:click={() => $fullScreen = !$fullScreen} style="margin-right: 10px; color: {!$fullScreen ? '#ed0178' : '#818181'}" class="bg-transparent flex items-center outline-none transition-all">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-minimize">
{#if $fullScreen}
<path d="M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 1 2-2h3M3 16h3a2 2 0 0 1 2 2v3"></path>
Expand Down
19 changes: 12 additions & 7 deletions src/lib/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,19 @@ const _create = async () => {
db.notes.insert({
guid: '11111111-1111-1111-1111-111111111111',
name: '🚀 Welcome to nvAux!',
body: `Welcome and thank you for taking interest in nvAux!
body: `Welcome and thank you for using nvAux!
This is a web-based note-taking app inspired by nvALT. A few important things to note:
This is a web-based note-taking app inspired by nvALT where searching and creating notes is one in the same action. A few things to keep in-mind:
* All your notes are stored locally in your browser.
* Expect bugs, dead-ends, and missing features as it's still early in development.
* Do no trust your data here yet. Testing purposes only.
* 'Add to Home Screen' to feel more app-like.
* All your notes are stored within your browser, locally (and unencrypted for now).
* Do no trust your data here yet. Not production-ready. Thar be dragons.
* 'Add to Home Screen' on iOS Safari for a native app-like experience.
If you are interested in the development of nvAux the project is open-source and available on GitHub at https://github.com/matterofabstract/nvaux
You can download your notes at any time by clicking the 'Download Notes' button in the nvAux settings screen.
Don't forget to follow the project on 𝕏 at @nvAuxApp and let us know what you think!
`,
createdAt: new Date().getTime(),
updatedAt: new Date().getTime()
Expand All @@ -64,7 +69,7 @@ This is a web-based note-taking app inspired by nvALT. A few important things to
await db.notes.insert({
guid: '00000000-0000-0000-0000-000000000000',
name: '⚙️ nvAux Settings',
body: 'Set your nvAux Preferences here',
body: 'Adjust Your nvAux Preferences',
createdAt: new Date().getTime(),
updatedAt: new Date().getTime()
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ html, body { margin: 0; padding: 0; font-family: Verdana, Geneva, Tahoma, sans-s
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.w-full { width: 100%; }
.w-screen { width: 100vw; }
.transition-all { transition-property: all; transition-duration: 500ms; transition-timing-function: ease; }
.transition-all { transition-property: all; transition-duration: 300ms; transition-timing-function: ease; }

.btn { padding: 12px 20px; border-radius: 3px; font-size: 14px; }

Expand Down

0 comments on commit ff3651a

Please sign in to comment.