Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add "Export" and "Duplicate" buttons in notes options menu. #688

Merged
merged 25 commits into from
Oct 19, 2021
Merged
Changes from 10 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e917871
fix: Fix icon colors so they work with themes
amanharwara Oct 15, 2021
dd088b6
feat: Add EditorIdentifier enum to @/enums.ts
amanharwara Oct 15, 2021
788d60a
feat: Implement "Export" & "Duplicate" actions in notes' options
amanharwara Oct 15, 2021
e465dd4
feat: Simplify format detection while saving notes
amanharwara Oct 17, 2021
43f3dd9
Update app/assets/javascripts/components/NotesOptions.tsx
amanharwara Oct 17, 2021
b1582f8
Update app/assets/javascripts/components/NotesOptions.tsx
amanharwara Oct 17, 2021
302b779
Merge branch 'develop' into feat/notes-options-actions
amanharwara Oct 17, 2021
eba6c5b
chore(deps): Bump @standardnotes/features to 1.7.0
amanharwara Oct 17, 2021
1164756
refactor: Remove unused deps from notes options menu
amanharwara Oct 17, 2021
9a6fd2b
Merge branch 'develop' into feat/notes-options-actions
amanharwara Oct 17, 2021
4777203
refactor: Use FeatureIdentifier enum instead of EditorIdentifier
amanharwara Oct 17, 2021
66fbe6c
Merge branch 'feat/notes-options-actions' of github.com:amanharwara/w…
amanharwara Oct 17, 2021
88fc84a
chore(deps): Bump @standardnotes/features to 1.7.1
amanharwara Oct 17, 2021
d7dc044
Merge branch 'develop' into feat/notes-options-actions
amanharwara Oct 19, 2021
2efd988
chore(deps): Bump @standardnotes/snjs to 2.15.1
amanharwara Oct 19, 2021
ad16d37
Merge branch 'feat/notes-options-actions' of github.com:amanharwara/w…
amanharwara Oct 19, 2021
21f1f35
fix: Editor option types in default editor dropdown
amanharwara Oct 19, 2021
6c390ee
feat: Add correct PrefKeys to NotesCtrlState
amanharwara Oct 19, 2021
473627f
Merge branch 'develop' into feat/notes-options-actions
amanharwara Oct 19, 2021
e7dccd9
refactor: Remove filter from extensions preferences
amanharwara Oct 19, 2021
6bbf02b
chore: Bump @standardnotes/features to 1.7.2
amanharwara Oct 19, 2021
0427abf
Merge branch 'feat/notes-options-actions' of github.com:amanharwara/w…
amanharwara Oct 19, 2021
10145fa
Merge branch 'develop' into feat/notes-options-actions
amanharwara Oct 19, 2021
36a30f8
chore(deps): Bump snjs to 2.15.2
amanharwara Oct 19, 2021
a2ee7fb
Merge branch 'feat/notes-options-actions' of github.com:amanharwara/w…
amanharwara Oct 19, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/assets/icons/ic-copy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/icons/ic-download.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 42 additions & 5 deletions app/assets/javascripts/components/NotesOptions.tsx
Original file line number Diff line number Diff line change
@@ -20,9 +20,9 @@ type Props = {
};

type DeletePermanentlyButtonProps = {
closeOnBlur: Props["closeOnBlur"];
closeOnBlur: Props['closeOnBlur'];
onClick: () => void;
}
};

const DeletePermanentlyButton = ({
closeOnBlur,
@@ -45,8 +45,9 @@ export const NotesOptions = observer(
top: 0,
right: 0,
});
const [tagsMenuMaxHeight, setTagsMenuMaxHeight] =
useState<number | 'auto'>('auto');
const [tagsMenuMaxHeight, setTagsMenuMaxHeight] = useState<number | 'auto'>(
'auto'
);
const [altKeyDown, setAltKeyDown] = useState(false);

const toggleOn = (condition: (note: SNNote) => boolean) => {
@@ -86,7 +87,7 @@ export const NotesOptions = observer(
},
onKeyUp: () => {
setAltKeyDown(false);
}
},
});

return () => {
@@ -122,6 +123,26 @@ export const NotesOptions = observer(
setTagsMenuOpen(!tagsMenuOpen);
};

const downloadSelectedItems = () => {
notes.forEach((note) => {
const editor = application.componentManager.editorForNote(note);
const format = editor?.package_info?.file_type || 'txt';
const downloadAnchor = document.createElement('a');
downloadAnchor.setAttribute(
'href',
'data:text/plain;charset=utf-8,' + encodeURIComponent(note.text)
);
downloadAnchor.setAttribute('download', `${note.title}.${format}`);
downloadAnchor.click();
});
};

const duplicateSelectedItems = () => {
notes.forEach((note) => {
application.duplicateItem(note);
});
};

return (
<>
<Switch
@@ -246,6 +267,22 @@ export const NotesOptions = observer(
Unpin
</button>
)}
<button
onBlur={closeOnBlur}
className="sn-dropdown-item"
onClick={downloadSelectedItems}
>
<Icon type="download" className={iconClass} />
Export
</button>
<button
onBlur={closeOnBlur}
className="sn-dropdown-item"
onClick={duplicateSelectedItems}
>
<Icon type="copy" className={iconClass} />
Duplicate
</button>
{unarchived && (
<button
onBlur={closeOnBlur}
16 changes: 15 additions & 1 deletion app/assets/javascripts/enums.ts
Original file line number Diff line number Diff line change
@@ -20,5 +20,19 @@ export enum HtmlInputTypes {
Text = 'text',
Time = 'time',
Url = 'url',
Week = 'week'
Week = 'week',
}

export enum EditorIdentifier {
amanharwara marked this conversation as resolved.
Show resolved Hide resolved
PlainEditor = 'plain-editor',
BoldEditor = 'org.standardnotes.bold-editor',
CodeEditor = 'org.standardnotes.code-editor',
MarkdownBasic = 'org.standardnotes.simple-markdown-editor',
MarkdownMath = 'org.standardnotes.fancy-markdown-editor',
MarkdownMinimist = 'org.standardnotes.minimal-markdown-editor',
MarkdownPro = 'org.standardnotes.advanced-markdown-editor',
PlusEditor = 'org.standardnotes.plus-editor',
SecureSpreadsheets = 'org.standardnotes.standard-sheets',
TaskEditor = 'org.standardnotes.simple-task-editor',
TokenVault = 'org.standardnotes.token-vault',
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Dropdown, DropdownItem } from '@/components/Dropdown';
import { IconType } from '@/components/Icon';
import { EditorIdentifier } from '@/enums';
import {
PreferencesGroup,
PreferencesSegment,
@@ -20,20 +21,6 @@ type Props = {
application: WebApplication;
};

enum EditorIdentifier {
PlainEditor = 'plain-editor',
BoldEditor = 'org.standardnotes.bold-editor',
CodeEditor = 'org.standardnotes.code-editor',
MarkdownBasic = 'org.standardnotes.simple-markdown-editor',
MarkdownMath = 'org.standardnotes.fancy-markdown-editor',
MarkdownMinimist = 'org.standardnotes.minimal-markdown-editor',
MarkdownPro = 'org.standardnotes.advanced-markdown-editor',
PlusEditor = 'org.standardnotes.plus-editor',
SecureSpreadsheets = 'org.standardnotes.standard-sheets',
TaskEditor = 'org.standardnotes.simple-task-editor',
TokenVault = 'org.standardnotes.token-vault',
}

const getEditorIconType = (identifier: string): IconType | null => {
switch (identifier) {
case EditorIdentifier.BoldEditor:
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@
"@reach/checkbox": "^0.13.2",
"@reach/dialog": "^0.13.0",
"@reach/listbox": "^0.16.1",
"@standardnotes/features": "1.6.1",
"@standardnotes/features": "1.7.0",
"@standardnotes/sncrypto-web": "1.5.2",
"@standardnotes/snjs": "2.14.14",
"mobx": "^6.3.2",
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -2117,20 +2117,20 @@
dependencies:
"@standardnotes/auth" "^3.7.0"

"@standardnotes/[email protected]":
version "1.6.1"
resolved "https://registry.yarnpkg.com/@standardnotes/features/-/features-1.6.1.tgz#bfa227bd231dc1b54449936663731f5132b08e23"
integrity sha512-IC6fEotUqs23JdZx96JnEgARxwYzjmPz3UwU/uVn8hHjxPev/W0nyZFRiSlj4v+dod0jSa6FTR8iLLsOQ6M4Ug==
dependencies:
"@standardnotes/common" "^1.1.0"

"@standardnotes/[email protected]":
version "1.6.2"
resolved "https://registry.yarnpkg.com/@standardnotes/features/-/features-1.6.2.tgz#98c5998426d9f93e06c2846c5bc7b6aef8d31063"
integrity sha512-s/rqRyG7mrrgxJOzckPSYlB68wsRpM9jlFwDE+7zQO5/xKh+37ueWfy3RoqOgkKLey6lMpnTurofIJCvqLM3dQ==
dependencies:
"@standardnotes/common" "^1.1.0"

"@standardnotes/[email protected]":
version "1.7.0"
resolved "https://registry.yarnpkg.com/@standardnotes/features/-/features-1.7.0.tgz#b2a455d51c09c621693ce0f118109be839ae261e"
integrity sha512-1leqzLc4UoctKaIJyZma0H63PWVb+5L0O6bRtraXqdqfX/ohCKaJqfIrm8CTrisupq+W8NIY6JuCSAq4q6c49Q==
dependencies:
"@standardnotes/common" "^1.1.0"

"@standardnotes/[email protected]":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@standardnotes/settings/-/settings-1.2.0.tgz#d7936c788138265b0720085ca9e63358d3092459"