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

Commit

Permalink
fix: do not modify timestamps when modifying note metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
moughxyz committed Mar 22, 2022
1 parent b6cdbe3 commit 35f584f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 32 deletions.
6 changes: 3 additions & 3 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "standardnotes-mobile",
"version": "3.13.0",
"user-version": "3.13.0",
"version": "3.14.0",
"user-version": "3.14.0",
"private": true,
"license": "AGPL-3.0-or-later",
"scripts": {
Expand Down Expand Up @@ -36,7 +36,7 @@
"@standardnotes/react-native-textview": "1.0.2",
"@standardnotes/react-native-utils": "1.0.1",
"@standardnotes/sncrypto-common": "1.7.3",
"@standardnotes/snjs": "2.89.4",
"@standardnotes/snjs": "2.90.0",
"@standardnotes/stylekit": "5.17.0",
"@types/styled-components-react-native": "5.1.3",
"js-base64": "^3.7.2",
Expand Down
18 changes: 12 additions & 6 deletions src/lib/snjs_helper_hooks.ts
Expand Up @@ -447,18 +447,24 @@ export const useChangeNote = (
note: SNNote | undefined,
editor: NoteViewController | undefined = undefined
) => {
// Context
const application = React.useContext(ApplicationContext);

const [canChangeNote] = useChangeNoteChecks(note, editor);

const changeNote = useCallback(
async (mutate: (mutator: NoteMutator) => void) => {
async (
mutate: (mutator: NoteMutator) => void,
updateTimestamps: boolean
) => {
if (await canChangeNote()) {
await application?.mutator.changeAndSaveItem(note!.uuid, mutator => {
const noteMutator = mutator as NoteMutator;
mutate(noteMutator);
});
await application?.mutator.changeAndSaveItem(
note!.uuid,
mutator => {
const noteMutator = mutator as NoteMutator;
mutate(noteMutator);
},
updateTimestamps
);
}
},
[application, note, canChangeNote]
Expand Down
10 changes: 5 additions & 5 deletions src/screens/Notes/NoteCell.tsx
Expand Up @@ -72,7 +72,7 @@ export const NoteCell = ({
() => {
changeNote(mutator => {
mutator.trashed = true;
});
}, false);
},
undefined
);
Expand Down Expand Up @@ -120,7 +120,7 @@ export const NoteCell = ({
callback: () =>
changeNote(mutator => {
mutator.pinned = !note.pinned;
}),
}, false),
});

options.push({
Expand All @@ -138,7 +138,7 @@ export const NoteCell = ({

changeNote(mutator => {
mutator.archived = !note.archived;
});
}, false);
},
});

Expand All @@ -148,7 +148,7 @@ export const NoteCell = ({
callback: () =>
changeNote(mutator => {
mutator.locked = !note.locked;
}),
}, false),
});

options.push({
Expand All @@ -172,7 +172,7 @@ export const NoteCell = ({
callback: () => {
changeNote(mutator => {
mutator.trashed = false;
});
}, false);
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Settings/Sections/OptionsSection.tsx
Expand Up @@ -123,7 +123,7 @@ export const OptionsSection = ({ title, encryptionAvailable }: Props) => {
if (!result) {
return;
} else if ('error' in result) {
application!.alertService!.alert(result.error);
application!.alertService!.alert(result.error.text);
} else if (result.errorCount) {
application!.alertService!.alert(
`Import complete. ${result.errorCount} items were not imported because ` +
Expand Down
34 changes: 21 additions & 13 deletions src/screens/SideMenu/NoteSideMenu.tsx
Expand Up @@ -131,7 +131,7 @@ export const NoteSideMenu = React.memo((props: Props) => {
() => {
changeNote(mutator => {
mutator.trashed = true;
});
}, false);
props.drawerRef?.closeDrawer();
if (!application?.getAppState().isInTabletMode) {
navigation.popToTop();
Expand Down Expand Up @@ -246,10 +246,14 @@ export const NoteSideMenu = React.memo((props: Props) => {
props.drawerRef?.closeDrawer();
if (!selectedComponent) {
if (!note?.prefersPlainEditor) {
await application?.mutator.changeItem(note!.uuid, mutator => {
const noteMutator = mutator as NoteMutator;
noteMutator.prefersPlainEditor = true;
});
await application?.mutator.changeItem(
note!.uuid,
mutator => {
const noteMutator = mutator as NoteMutator;
noteMutator.prefersPlainEditor = true;
},
false
);
}
if (
activeEditorComponent?.isExplicitlyEnabledForItem(note!.uuid) ||
Expand All @@ -264,10 +268,14 @@ export const NoteSideMenu = React.memo((props: Props) => {
}
const prefersPlain = note!.prefersPlainEditor;
if (prefersPlain) {
await application?.mutator.changeItem(note!.uuid, mutator => {
const noteMutator = mutator as NoteMutator;
noteMutator.prefersPlainEditor = false;
});
await application?.mutator.changeItem(
note!.uuid,
mutator => {
const noteMutator = mutator as NoteMutator;
noteMutator.prefersPlainEditor = false;
},
false
);
}
await associateComponentWithNote(application, selectedComponent, note);
}
Expand Down Expand Up @@ -429,7 +437,7 @@ export const NoteSideMenu = React.memo((props: Props) => {
const pinEvent = () =>
changeNote(mutator => {
mutator.pinned = !note.pinned;
});
}, false);

const archiveOption = note.archived ? 'Unarchive' : 'Archive';
const archiveEvent = () => {
Expand All @@ -441,15 +449,15 @@ export const NoteSideMenu = React.memo((props: Props) => {
}
changeNote(mutator => {
mutator.archived = !note.archived;
});
}, false);
leaveEditor();
};

const lockOption = note.locked ? 'Enable editing' : 'Prevent editing';
const lockEvent = () =>
changeNote(mutator => {
mutator.locked = !note.locked;
});
}, false);

const protectOption = note.protected ? 'Unprotect' : 'Protect';
const protectEvent = async () => await protectOrUnprotectNote();
Expand Down Expand Up @@ -516,7 +524,7 @@ export const NoteSideMenu = React.memo((props: Props) => {
onSelect: () => {
changeNote(mutator => {
mutator.trashed = false;
});
}, false);
},
},
{
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -1952,10 +1952,10 @@
resolved "https://registry.yarnpkg.com/@standardnotes/sncrypto-common/-/sncrypto-common-1.7.3.tgz#1e62a14800393be44cdb376d1d72fbc064334fc1"
integrity sha512-twwYeBL+COkNF9IUM5bWrLZ4gXjg41tRxBMR3r3JcbrkyYjcNqVHf9L+YdBcndjSV3/9xwWl2pYWK1RB3UR2Xg==

"@standardnotes/snjs@2.89.4":
version "2.89.4"
resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.89.4.tgz#b7257bca0ad16de98e4f4b55e65a59481d069416"
integrity sha512-rT+H7dzimvMLjTpbI4eukIAfpcveKXBgraDnPqNTY8c7638attdXG0wmjwCa2S09VHElnBqMUq054dqOmBvVnQ==
"@standardnotes/snjs@2.90.0":
version "2.90.0"
resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.90.0.tgz#87f11c52d8511ee7c0939f021b5ce96f47748222"
integrity sha512-3AilDSB7FdqxPP25zf41PoHZ0iqd6dcuzT4qtYkLTGnAz/WaCLzJy0sS/e5x9tHW3sltoVRhXJsRRmQV5JZFCQ==
dependencies:
"@standardnotes/applications" "^1.2.6"
"@standardnotes/auth" "^3.17.11"
Expand Down

0 comments on commit 35f584f

Please sign in to comment.