2020-07-03 23:32:39 +02:00
|
|
|
import { CommandRuntime, CommandDeclaration } from '../../../lib/services/CommandService';
|
|
|
|
const BaseModel = require('lib/BaseModel');
|
|
|
|
const { uuid } = require('lib/uuid.js');
|
|
|
|
|
|
|
|
export const declaration:CommandDeclaration = {
|
|
|
|
name: 'search',
|
2020-09-15 15:01:07 +02:00
|
|
|
iconName: 'icon-search',
|
2020-07-03 23:32:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export const runtime = (comp:any):CommandRuntime => {
|
|
|
|
return {
|
2020-09-15 15:01:07 +02:00
|
|
|
execute: async ({ query }:any) => {
|
2020-07-03 23:32:39 +02:00
|
|
|
if (!comp.searchId_) comp.searchId_ = uuid.create();
|
|
|
|
|
|
|
|
comp.props.dispatch({
|
|
|
|
type: 'SEARCH_UPDATE',
|
|
|
|
search: {
|
|
|
|
id: comp.searchId_,
|
|
|
|
title: query,
|
|
|
|
query_pattern: query,
|
|
|
|
query_folder_id: null,
|
|
|
|
type_: BaseModel.TYPE_SEARCH,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (query) {
|
|
|
|
comp.props.dispatch({
|
|
|
|
type: 'SEARCH_SELECT',
|
|
|
|
id: comp.searchId_,
|
|
|
|
});
|
|
|
|
} else {
|
2020-09-21 18:50:59 +02:00
|
|
|
// Note: Normally there's no need to do anything when the search query
|
|
|
|
// is cleared as the reducer should handle all state changes.
|
|
|
|
// https://github.com/laurent22/joplin/issues/3748
|
|
|
|
|
|
|
|
// const note = await Note.load(comp.props.selectedNoteId);
|
|
|
|
// if (note) {
|
|
|
|
// comp.props.dispatch({
|
|
|
|
// type: 'FOLDER_AND_NOTE_SELECT',
|
|
|
|
// folderId: note.parent_id,
|
|
|
|
// noteId: note.id,
|
|
|
|
// });
|
|
|
|
// }
|
2020-07-03 23:32:39 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|