fix: sync after changing notes
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
|||||||
NoteMutator,
|
NoteMutator,
|
||||||
ContentType,
|
ContentType,
|
||||||
SNTag,
|
SNTag,
|
||||||
|
SNItem,
|
||||||
} from '@standardnotes/snjs';
|
} from '@standardnotes/snjs';
|
||||||
import {
|
import {
|
||||||
makeObservable,
|
makeObservable,
|
||||||
@@ -22,7 +23,10 @@ export class NotesState {
|
|||||||
lastSelectedNote: SNNote | undefined;
|
lastSelectedNote: SNNote | undefined;
|
||||||
selectedNotes: Record<UuidString, SNNote> = {};
|
selectedNotes: Record<UuidString, SNNote> = {};
|
||||||
contextMenuOpen = false;
|
contextMenuOpen = false;
|
||||||
contextMenuPosition: { top?: number; left: number, bottom?: number } = { top: 0, left: 0 };
|
contextMenuPosition: { top?: number; left: number; bottom?: number } = {
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
};
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private application: WebApplication,
|
private application: WebApplication,
|
||||||
@@ -164,33 +168,42 @@ export class NotesState {
|
|||||||
this.contextMenuOpen = open;
|
this.contextMenuOpen = open;
|
||||||
}
|
}
|
||||||
|
|
||||||
setContextMenuPosition(position: { top?: number; left: number, bottom?: number }): void {
|
setContextMenuPosition(position: {
|
||||||
|
top?: number;
|
||||||
|
left: number;
|
||||||
|
bottom?: number;
|
||||||
|
}): void {
|
||||||
this.contextMenuPosition = position;
|
this.contextMenuPosition = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
setHideSelectedNotePreviews(hide: boolean): void {
|
async changeSelectedNotes(
|
||||||
this.application.changeItems<NoteMutator>(
|
mutate: (mutator: NoteMutator) => void
|
||||||
|
): Promise<void> {
|
||||||
|
await this.application.changeItems(
|
||||||
Object.keys(this.selectedNotes),
|
Object.keys(this.selectedNotes),
|
||||||
|
mutate,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
this.application.sync();
|
||||||
|
}
|
||||||
|
|
||||||
|
setHideSelectedNotePreviews(hide: boolean): void {
|
||||||
|
this.changeSelectedNotes(
|
||||||
(mutator) => {
|
(mutator) => {
|
||||||
mutator.hidePreview = hide;
|
mutator.hidePreview = hide;
|
||||||
},
|
},
|
||||||
false
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
setLockSelectedNotes(lock: boolean): void {
|
setLockSelectedNotes(lock: boolean): void {
|
||||||
this.application.changeItems<NoteMutator>(
|
this.changeSelectedNotes(
|
||||||
Object.keys(this.selectedNotes),
|
|
||||||
(mutator) => {
|
(mutator) => {
|
||||||
mutator.locked = lock;
|
mutator.locked = lock;
|
||||||
},
|
},
|
||||||
false
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async setTrashSelectedNotes(
|
async setTrashSelectedNotes(trashed: boolean): Promise<void> {
|
||||||
trashed: boolean
|
|
||||||
): Promise<void> {
|
|
||||||
if (trashed) {
|
if (trashed) {
|
||||||
const notesDeleted = await this.deleteNotes(false);
|
const notesDeleted = await this.deleteNotes(false);
|
||||||
if (notesDeleted) {
|
if (notesDeleted) {
|
||||||
@@ -200,12 +213,10 @@ export class NotesState {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.application.changeItems<NoteMutator>(
|
this.changeSelectedNotes(
|
||||||
Object.keys(this.selectedNotes),
|
|
||||||
(mutator) => {
|
(mutator) => {
|
||||||
mutator.trashed = trashed;
|
mutator.trashed = trashed;
|
||||||
},
|
},
|
||||||
false
|
|
||||||
);
|
);
|
||||||
this.unselectNotes();
|
this.unselectNotes();
|
||||||
this.contextMenuOpen = false;
|
this.contextMenuOpen = false;
|
||||||
@@ -251,12 +262,10 @@ export class NotesState {
|
|||||||
await this.application.deleteItem(note);
|
await this.application.deleteItem(note);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.application.changeItems<NoteMutator>(
|
this.changeSelectedNotes(
|
||||||
Object.keys(this.selectedNotes),
|
|
||||||
(mutator) => {
|
(mutator) => {
|
||||||
mutator.trashed = true;
|
mutator.trashed = true;
|
||||||
},
|
},
|
||||||
false
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -266,12 +275,10 @@ export class NotesState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setPinSelectedNotes(pinned: boolean): void {
|
setPinSelectedNotes(pinned: boolean): void {
|
||||||
this.application.changeItems<NoteMutator>(
|
this.changeSelectedNotes(
|
||||||
Object.keys(this.selectedNotes),
|
|
||||||
(mutator) => {
|
(mutator) => {
|
||||||
mutator.pinned = pinned;
|
mutator.pinned = pinned;
|
||||||
},
|
},
|
||||||
false
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,12 +289,13 @@ export class NotesState {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.application.changeItems<NoteMutator>(
|
|
||||||
Object.keys(this.selectedNotes),
|
this.changeSelectedNotes(
|
||||||
(mutator) => {
|
(mutator) => {
|
||||||
mutator.archived = archived;
|
mutator.archived = archived;
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.selectedNotes = {};
|
this.selectedNotes = {};
|
||||||
this.contextMenuOpen = false;
|
this.contextMenuOpen = false;
|
||||||
@@ -299,9 +307,7 @@ export class NotesState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async addTagToSelectedNotes(tag: SNTag): Promise<void> {
|
async addTagToSelectedNotes(tag: SNTag): Promise<void> {
|
||||||
const selectedNotes = Object.values(
|
const selectedNotes = Object.values(this.selectedNotes);
|
||||||
this.application.getAppState().notes.selectedNotes
|
|
||||||
);
|
|
||||||
await this.application.changeItem(tag.uuid, (mutator) => {
|
await this.application.changeItem(tag.uuid, (mutator) => {
|
||||||
for (const note of selectedNotes) {
|
for (const note of selectedNotes) {
|
||||||
mutator.addItemAsRelationship(note);
|
mutator.addItemAsRelationship(note);
|
||||||
@@ -311,9 +317,7 @@ export class NotesState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async removeTagFromSelectedNotes(tag: SNTag): Promise<void> {
|
async removeTagFromSelectedNotes(tag: SNTag): Promise<void> {
|
||||||
const selectedNotes = Object.values(
|
const selectedNotes = Object.values(this.selectedNotes);
|
||||||
this.application.getAppState().notes.selectedNotes
|
|
||||||
);
|
|
||||||
await this.application.changeItem(tag.uuid, (mutator) => {
|
await this.application.changeItem(tag.uuid, (mutator) => {
|
||||||
for (const note of selectedNotes) {
|
for (const note of selectedNotes) {
|
||||||
mutator.removeItemAsRelationship(note);
|
mutator.removeItemAsRelationship(note);
|
||||||
@@ -323,9 +327,7 @@ export class NotesState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isTagInSelectedNotes(tag: SNTag): boolean {
|
isTagInSelectedNotes(tag: SNTag): boolean {
|
||||||
const selectedNotes = Object.values(
|
const selectedNotes = Object.values(this.selectedNotes);
|
||||||
this.application.getAppState().notes.selectedNotes
|
|
||||||
);
|
|
||||||
return selectedNotes.every((note) =>
|
return selectedNotes.every((note) =>
|
||||||
this.application
|
this.application
|
||||||
.getAppState()
|
.getAppState()
|
||||||
|
|||||||
Reference in New Issue
Block a user