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
Show file tree
Hide file tree
Changes from 4 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.
54 changes: 48 additions & 6 deletions app/assets/javascripts/components/NotesOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ import {
DisclosureButton,
DisclosurePanel,
} from '@reach/disclosure';
import { SNNote } from '@standardnotes/snjs/dist/@types';
import {
PayloadContent,
SNComponent,
SNNote,
} from '@standardnotes/snjs/dist/@types';
import { WebApplication } from '@/ui_models/application';
import { KeyboardModifier } from '@/services/ioService';
import { EditorIdentifier } from '@/enums';

type Props = {
application: WebApplication;
Expand All @@ -20,9 +25,9 @@ type Props = {
};

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

const DeletePermanentlyButton = ({
closeOnBlur,
Expand All @@ -45,8 +50,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) => {
Expand Down Expand Up @@ -86,7 +92,7 @@ export const NotesOptions = observer(
},
onKeyUp: () => {
setAltKeyDown(false);
}
},
});

return () => {
Expand Down Expand Up @@ -122,6 +128,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;
amanharwara marked this conversation as resolved.
Show resolved Hide resolved
const downloadAnchor = document.createElement('a');
downloadAnchor.setAttribute(
'href',
'data:text/plain;charset=utf-8,' + encodeURIComponent(note.text)
);
downloadAnchor.setAttribute('download', `${note.title}${format}`);
amanharwara marked this conversation as resolved.
Show resolved Hide resolved
downloadAnchor.click();
});
};

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

return (
<>
<Switch
Expand Down Expand Up @@ -246,6 +272,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}
Expand Down
16 changes: 15 additions & 1 deletion app/assets/javascripts/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:
Expand Down