2022-01-11 20:35:32 +03:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import {action} from '@ember/object';
|
|
|
|
import {run} from '@ember/runloop';
|
2017-10-30 12:38:01 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2022-01-11 20:35:32 +03:00
|
|
|
|
|
|
|
export default class GhSearchInputComponent extends Component {
|
|
|
|
@service router;
|
2024-04-10 14:44:24 +03:00
|
|
|
@service search;
|
2022-01-11 20:35:32 +03:00
|
|
|
|
|
|
|
@action
|
|
|
|
openSelected(selected) {
|
|
|
|
if (!selected) {
|
|
|
|
return;
|
2016-04-19 18:55:10 +03:00
|
|
|
}
|
|
|
|
|
2022-01-11 20:35:32 +03:00
|
|
|
this.args.onSelected?.(selected);
|
2018-01-11 20:43:23 +03:00
|
|
|
|
2024-04-11 17:01:39 +03:00
|
|
|
if (selected.groupName === 'Posts') {
|
2022-01-11 20:35:32 +03:00
|
|
|
let id = selected.id.replace('post.', '');
|
2023-10-12 15:17:39 +03:00
|
|
|
this.router.transitionTo('lexical-editor.edit', 'post', id);
|
2018-01-11 20:43:23 +03:00
|
|
|
}
|
|
|
|
|
2024-04-11 17:01:39 +03:00
|
|
|
if (selected.groupName === 'Pages') {
|
2022-01-11 20:35:32 +03:00
|
|
|
let id = selected.id.replace('page.', '');
|
2023-10-12 15:17:39 +03:00
|
|
|
this.router.transitionTo('lexical-editor.edit', 'page', id);
|
2018-01-11 20:43:23 +03:00
|
|
|
}
|
|
|
|
|
2024-04-22 17:49:43 +03:00
|
|
|
if (selected.groupName === 'Staff') {
|
2022-01-11 20:35:32 +03:00
|
|
|
let id = selected.id.replace('user.', '');
|
2023-10-09 10:12:46 +03:00
|
|
|
this.router.transitionTo('settings-x.settings-x', `staff/${id}`);
|
2018-01-11 20:43:23 +03:00
|
|
|
}
|
|
|
|
|
2024-04-11 17:01:39 +03:00
|
|
|
if (selected.groupName === 'Tags') {
|
2022-01-11 20:35:32 +03:00
|
|
|
let id = selected.id.replace('tag.', '');
|
|
|
|
this.router.transitionTo('tag', id);
|
2019-06-18 13:47:21 +03:00
|
|
|
}
|
2022-01-11 20:35:32 +03:00
|
|
|
}
|
2018-01-11 20:43:23 +03:00
|
|
|
|
2022-01-11 20:35:32 +03:00
|
|
|
@action
|
|
|
|
onClose(select, keyboardEvent) {
|
|
|
|
// refocus search input after dropdown is closed (eg, by pressing Escape)
|
|
|
|
run.later(() => {
|
|
|
|
keyboardEvent?.target.focus();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|