fix: use SNJS duplicateItem for restoring as copy

This commit is contained in:
Baptiste Grob
2020-10-01 15:12:35 +02:00
parent e23250200a
commit fff0ae1313
6 changed files with 16 additions and 28 deletions

View File

@@ -27,6 +27,7 @@ class RevisionPreviewModalCtrl extends PureViewCtrl implements RevisionPreviewSc
application!: WebApplication
unregisterComponent?: any
note!: SNNote
private originalNote!: SNNote;
/* @ngInject */
constructor(
@@ -58,8 +59,8 @@ class RevisionPreviewModalCtrl extends PureViewCtrl implements RevisionPreviewSc
ContentType.Note,
this.content
) as SNNote;
const originalNote = this.application.findItem(this.uuid) as SNNote;
const editorForNote = this.componentManager.editorForNote(originalNote);
this.originalNote = this.application.findItem(this.uuid) as SNNote;
const editorForNote = this.componentManager.editorForNote(this.originalNote);
if (editorForNote) {
/**
* Create temporary copy, as a lot of componentManager is uuid based, so might
@@ -93,15 +94,10 @@ class RevisionPreviewModalCtrl extends PureViewCtrl implements RevisionPreviewSc
restore(asCopy: boolean) {
const run = async () => {
if (asCopy) {
const contentCopy = Object.assign({}, this.content);
if (contentCopy.title) {
contentCopy.title += " (copy)";
}
await this.application.createManagedItem(
ContentType.Note,
contentCopy,
true
);
await this.application.duplicateItem(this.originalNote, {
...this.content,
title: this.content.title ? this.content.title + ' (copy)' : undefined
});
} else {
this.application.changeAndSaveItem(this.uuid, (mutator) => {
mutator.setContent(this.content);

View File

@@ -1,17 +1,10 @@
import { FooterStatus } from '@/types';
declare type StatusCallback = (string: string) => void;
export declare class StatusManager {
private statuses;
private _message;
private observers;
replaceStatusWithString(status: FooterStatus, string: string): {
string: string;
};
addStatusFromString(string: string): {
string: string;
};
removeStatus(status: FooterStatus): undefined;
addStatusObserver(callback: StatusCallback): () => void;
get message(): string;
setMessage(message: string): void;
onStatusChange(callback: StatusCallback): () => void;
private notifyObservers;
private getStatusString;
}
export {};

View File

@@ -2,7 +2,6 @@ import { WebApplication } from '@/ui_models/application';
import { ApplicationService, ApplicationEvent } from 'snjs';
export declare class ThemeManager extends ApplicationService {
private activeThemes;
private unsubState?;
private unregisterDesktop;
private unregisterStream;
onAppEvent(event: ApplicationEvent): Promise<void>;

View File

@@ -15,7 +15,7 @@ declare type WebServices = {
autolockService: AutolockService;
archiveService: ArchiveManager;
nativeExtService: NativeExtManager;
statusService: StatusManager;
statusManager: StatusManager;
themeService: ThemeManager;
prefsService: PreferencesManager;
keyboardService: KeyboardManager;
@@ -37,7 +37,7 @@ export declare class WebApplication extends SNApplication {
getAutolockService(): AutolockService;
getArchiveService(): ArchiveManager;
getNativeExtService(): NativeExtManager;
getStatusService(): StatusManager;
getStatusManager(): StatusManager;
getThemeService(): ThemeManager;
getPrefsService(): PreferencesManager;
getKeyboardService(): KeyboardManager;

4
package-lock.json generated
View File

@@ -10956,8 +10956,8 @@
"from": "github:standardnotes/sncrypto#8794c88daa967eaae493cd5fdec7506d52b257ad"
},
"snjs": {
"version": "github:standardnotes/snjs#3ed1e58670cf1e5b554e18a88f0ea9a28668a376",
"from": "github:standardnotes/snjs#3ed1e58670cf1e5b554e18a88f0ea9a28668a376"
"version": "github:standardnotes/snjs#3f2136d3c58c04ae2de24b3d0a85cffebcb816f5",
"from": "github:standardnotes/snjs#3f2136d3c58c04ae2de24b3d0a85cffebcb816f5"
},
"sockjs": {
"version": "0.3.20",

View File

@@ -70,6 +70,6 @@
},
"dependencies": {
"sncrypto": "github:standardnotes/sncrypto#8794c88daa967eaae493cd5fdec7506d52b257ad",
"snjs": "github:standardnotes/snjs#3ed1e58670cf1e5b554e18a88f0ea9a28668a376"
"snjs": "github:standardnotes/snjs#3f2136d3c58c04ae2de24b3d0a85cffebcb816f5"
}
}