1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-18 09:35:20 +02:00
joplin/ElectronClient/gui/NoteToolbar/NoteToolbar.tsx
Laurent Cozic 51732a5adb Desktop: Fixed various bugs and regressions following note editor refactoring
Squashed commit of the following:

commit 5fde36f5c3fa7c7efbce6d81f48fe841c823e88c
Author: Laurent Cozic <laurent@cozic.net>
Date:   Sun May 3 18:43:20 2020 +0100

    Cannot fix for now

commit 251284db3c8b7da6db83f3e06fd19bfdc8b8dd3f
Author: Laurent Cozic <laurent@cozic.net>
Date:   Sun May 3 18:31:08 2020 +0100

    Fixed print to multiple PDFs logic

commit 00d9557996fb984b400fe650594150ae2681e03f
Author: Laurent Cozic <laurent@cozic.net>
Date:   Sun May 3 17:49:20 2020 +0100

    Fixed local search in TinyMCE

commit 46778bf0a79f3bba9ddbc27389fadce4f8944507
Author: Laurent Cozic <laurent@cozic.net>
Date:   Sun May 3 17:37:31 2020 +0100

    Restored note toolbar buttons

commit 3e623c98f0a1cf08bf7d0136f0c8982c5e1ddcd8
Author: Laurent Cozic <laurent@cozic.net>
Date:   Sun May 3 12:30:57 2020 +0100

    Various fixes and moved note toolbar to left of title

commit 790262fe9df5b08d4a619e5244d2906047b39855
Author: Laurent Cozic <laurent@cozic.net>
Date:   Sun May 3 11:21:11 2020 +0100

    Clean up

commit cea30f42e69014ecabda6fa5083199a1ba7b7510
Author: Laurent Cozic <laurent@cozic.net>
Date:   Sun May 3 11:08:23 2020 +0100

    Fixed note loading in TinyMCE
2020-05-03 18:44:49 +01:00

158 lines
3.6 KiB
TypeScript

import * as React from 'react';
const { connect } = require('react-redux');
const { buildStyle } = require('../../theme.js');
const Toolbar = require('../Toolbar.min.js');
const Note = require('lib/models/Note');
const Folder = require('lib/models/Folder');
const { time } = require('lib/time-utils.js');
const { _ } = require('lib/locale');
const { substrWithEllipsis } = require('lib/string-utils');
interface ButtonClickEvent {
name: string,
}
interface NoteToolbarProps {
theme: number,
style: any,
selectedFolderId: string,
folders: any[],
watchedNoteFiles: string[],
notesParentType: string,
note: any,
dispatch: Function,
onButtonClick(event:ButtonClickEvent):void,
historyNotes: any[],
}
function styles_(props:NoteToolbarProps) {
return buildStyle('NoteToolbar', props.theme, (/* theme:any*/) => {
return {
root: {
...props.style,
borderBottom: 'none',
},
};
});
}
function useToolbarItems(props:NoteToolbarProps) {
const { note, selectedFolderId, folders, watchedNoteFiles, notesParentType, dispatch, onButtonClick, historyNotes } = props;
const toolbarItems = [];
const folder = Folder.byId(folders, selectedFolderId);
if (folder && ['Search', 'Tag', 'SmartFilter'].includes(notesParentType)) {
toolbarItems.push({
title: _('In: %s', substrWithEllipsis(folder.title, 0, 16)),
iconName: 'fa-book',
onClick: () => {
props.dispatch({
type: 'FOLDER_AND_NOTE_SELECT',
folderId: folder.id,
noteId: note.id,
});
Folder.expandTree(folders, folder.parent_id);
},
});
}
if (historyNotes.length) {
toolbarItems.push({
tooltip: _('Back'),
iconName: 'fa-arrow-left',
onClick: () => {
if (!historyNotes.length) return;
const lastItem = historyNotes[historyNotes.length - 1];
dispatch({
type: 'FOLDER_AND_NOTE_SELECT',
folderId: lastItem.parent_id,
noteId: lastItem.id,
historyNoteAction: 'pop',
});
},
});
}
if (watchedNoteFiles.indexOf(note.id) >= 0) {
toolbarItems.push({
tooltip: _('Click to stop external editing'),
title: _('Watching...'),
iconName: 'fa-external-link',
onClick: () => {
onButtonClick({ name: 'stopExternalEditing' });
},
});
} else {
toolbarItems.push({
tooltip: _('Edit in external editor'),
iconName: 'fa-external-link',
onClick: () => {
onButtonClick({ name: 'startExternalEditing' });
},
});
}
toolbarItems.push({
tooltip: _('Tags'),
iconName: 'fa-tags',
onClick: () => {
onButtonClick({ name: 'setTags' });
},
});
if (note.is_todo) {
const item:any = {
iconName: 'fa-clock-o',
enabled: !note.todo_completed,
onClick: () => {
onButtonClick({ name: 'setAlarm' });
},
};
if (Note.needAlarm(note)) {
item.title = time.formatMsToLocal(note.todo_due);
} else {
item.tooltip = _('Set alarm');
}
toolbarItems.push(item);
}
toolbarItems.push({
tooltip: _('Note properties'),
iconName: 'fa-info-circle',
onClick: () => {
dispatch({
type: 'WINDOW_COMMAND',
name: 'commandNoteProperties',
noteId: note.id,
onRevisionLinkClick: () => {
onButtonClick({ name: 'showRevisions' });
},
});
},
});
return toolbarItems;
}
function NoteToolbar(props:NoteToolbarProps) {
const styles = styles_(props);
const toolbarItems = useToolbarItems(props);
return <Toolbar style={styles.root} items={toolbarItems} />;
}
const mapStateToProps = (state:any) => {
return {
selectedFolderId: state.selectedFolderId,
folders: state.folders,
watchedNoteFiles: state.watchedNoteFiles,
historyNotes: state.historyNotes,
notesParentType: state.notesParentType,
};
};
export default connect(mapStateToProps)(NoteToolbar);