2020-11-13 19:09:28 +02:00
|
|
|
import { State, stateUtils } from '../../reducer';
|
2020-10-18 22:52:10 +02:00
|
|
|
|
2021-01-22 19:41:11 +02:00
|
|
|
import BaseModel from '../../BaseModel';
|
|
|
|
import Folder from '../../models/Folder';
|
|
|
|
import MarkupToHtml from '@joplin/renderer/MarkupToHtml';
|
2020-10-18 22:52:10 +02:00
|
|
|
|
2020-11-13 19:09:28 +02:00
|
|
|
export default function stateToWhenClauseContext(state: State) {
|
2020-10-18 22:52:10 +02:00
|
|
|
const noteId = state.selectedNoteIds.length === 1 ? state.selectedNoteIds[0] : null;
|
|
|
|
const note = noteId ? BaseModel.byId(state.notes, noteId) : null;
|
|
|
|
|
|
|
|
return {
|
|
|
|
// Application state
|
|
|
|
notesAreBeingSaved: stateUtils.hasNotesBeingSaved(state),
|
|
|
|
syncStarted: state.syncStarted,
|
|
|
|
|
|
|
|
// Current location
|
|
|
|
inConflictFolder: state.selectedFolderId === Folder.conflictFolderId(),
|
|
|
|
|
|
|
|
// Note selection
|
|
|
|
oneNoteSelected: !!note,
|
|
|
|
someNotesSelected: state.selectedNoteIds.length > 0,
|
|
|
|
multipleNotesSelected: state.selectedNoteIds.length > 1,
|
|
|
|
noNotesSelected: !state.selectedNoteIds.length,
|
|
|
|
|
|
|
|
// Note history
|
|
|
|
historyhasBackwardNotes: state.backwardHistoryNotes.length > 0,
|
|
|
|
historyhasForwardNotes: state.forwardHistoryNotes.length > 0,
|
|
|
|
|
|
|
|
// Folder selection
|
|
|
|
oneFolderSelected: !!state.selectedFolderId,
|
|
|
|
|
|
|
|
// Current note properties
|
|
|
|
noteIsTodo: note ? !!note.is_todo : false,
|
|
|
|
noteTodoCompleted: note ? !!note.todo_completed : false,
|
|
|
|
noteIsMarkdown: note ? note.markup_language === MarkupToHtml.MARKUP_LANGUAGE_MARKDOWN : false,
|
|
|
|
noteIsHtml: note ? note.markup_language === MarkupToHtml.MARKUP_LANGUAGE_HTML : false,
|
|
|
|
};
|
|
|
|
}
|