Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

Commit

Permalink
fix: insert template note when creating with default editor
Browse files Browse the repository at this point in the history
  • Loading branch information
moughxyz committed Jan 10, 2022
1 parent 9ed6c6b commit 2adbfce
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
4 changes: 2 additions & 2 deletions ios/StandardNotes.xcodeproj/project.pbxproj
Expand Up @@ -11,7 +11,7 @@
13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; };
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
1C2EEB3B45F4EB07AC795C77 /* (null) in Frameworks */ = {isa = PBXBuildFile; };
1C2EEB3B45F4EB07AC795C77 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; };
33BB1B14071EBE5978EBF3A8 /* libPods-StandardNotes-StandardNotesTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 04FCB5A3A3387CA3CFC82AA3 /* libPods-StandardNotes-StandardNotesTests.a */; };
BC8DEA834BF198E8511F04FF /* libPods-StandardNotesDev.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 51F2D747BE02C2A1BCFEEFD1 /* libPods-StandardNotesDev.a */; };
CD7D5ECA27800609005FE1BF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CD7D5EC927800608005FE1BF /* LaunchScreen.storyboard */; };
Expand Down Expand Up @@ -83,7 +83,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
1C2EEB3B45F4EB07AC795C77 /* (null) in Frameworks */,
1C2EEB3B45F4EB07AC795C77 /* BuildFile in Frameworks */,
DD3D1CE428EC1C8BA0C49211 /* libPods-StandardNotes.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
43 changes: 35 additions & 8 deletions src/screens/Compose/Compose.tsx
Expand Up @@ -5,11 +5,14 @@ import { ApplicationContext } from '@Root/ApplicationContext';
import { SCREEN_COMPOSE } from '@Screens/screens';
import {
ApplicationEvent,
ComponentMutator,
ComponentViewer,
ContentType,
isPayloadSourceInternalChange,
isPayloadSourceRetrieved,
ItemMutator,
NoteMutator,
PayloadSource,
SNComponent,
} from '@standardnotes/snjs';
import { ICON_ALERT, ICON_LOCK } from '@Style/icons';
Expand Down Expand Up @@ -85,24 +88,30 @@ export class Compose extends React.Component<{}, State> {

componentDidMount() {
this.removeNoteInnerValueObserver = this.editor?.addNoteInnerValueChangeObserver(
(newNote, source) => {
(note, source) => {
if (isPayloadSourceRetrieved(source!)) {
this.setState({
title: newNote.title,
text: newNote.text,
title: note.title,
text: note.text,
});
}

if (newNote.lastSyncBegan || newNote.dirty) {
if (newNote.lastSyncEnd) {
const isTemplateNoteInsertedToBeInteractableWithEditor =
source === PayloadSource.Constructor && note.dirty;
if (isTemplateNoteInsertedToBeInteractableWithEditor) {
return;
}

if (note.lastSyncBegan || note.dirty) {
if (note.lastSyncEnd) {
if (
newNote.dirty ||
newNote.lastSyncBegan!.getTime() > newNote.lastSyncEnd.getTime()
note.dirty ||
note.lastSyncBegan!.getTime() > note.lastSyncEnd.getTime()
) {
this.showSavingStatus();
} else if (
this.context?.getStatusManager().hasMessage(SCREEN_COMPOSE) &&
newNote.lastSyncEnd.getTime() > newNote.lastSyncBegan!.getTime()
note.lastSyncEnd.getTime() > note.lastSyncBegan!.getTime()
) {
this.showAllChangesSavedStatus();
}
Expand Down Expand Up @@ -262,6 +271,18 @@ export class Compose extends React.Component<{}, State> {
return this.context?.mobileComponentManager!;
}

async associateComponentWithCurrentNote(component: SNComponent) {
const note = this.note;
if (!note) {
return;
}
return this.context?.changeItem(component.uuid, (m: ItemMutator) => {
const mutator = m as ComponentMutator;
mutator.removeDisassociatedItemId(note.uuid);
mutator.associateWithItem(note.uuid);
});
}

reloadComponentEditorState = async () => {
this.setState({
downloadingEditor: false,
Expand All @@ -271,6 +292,12 @@ export class Compose extends React.Component<{}, State> {

const associatedEditor = this.componentManager.editorForNote(this.note!);

/** Editors cannot interact with template notes so the note must be inserted */
if (associatedEditor && this.editor?.isTemplateNote) {
await this.editor?.insertTemplatedNote();
this.associateComponentWithCurrentNote(associatedEditor);
}

if (!associatedEditor) {
if (this.state.componentViewer) {
this.componentManager.destroyComponentViewer(
Expand Down

0 comments on commit 2adbfce

Please sign in to comment.