/
index.ts
40 lines (34 loc) · 1.03 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { provide, tag, Events, Selectors, Tag } from '@storefront/core';
import Autocomplete from '../autocomplete';
@provide('saytCategories')
@tag('gb-sayt-categories', require('./index.html'))
class Categories {
state: Categories.State = {
onClick: ({ matchAll, value }) => () =>
this.actions.updateSearch({
clear: true,
query: this.select(Selectors.autocompleteQuery),
...(<any>matchAll || {
navigationId: this.props.category,
value,
}),
}),
query: this.select(Selectors.autocompleteQuery),
};
init() {
this.subscribe(Events.AUTOCOMPLETE_QUERY_UPDATED, this.updateQuery);
}
updateQuery = (query: string) => this.set({ query });
}
interface Categories extends Tag<Categories.Props, Categories.State> {}
namespace Categories {
export interface Props {
category: string;
values: any[];
}
export interface State {
query: string;
onClick: (category: { value?: string; matchAll?: boolean }) => () => void;
}
}
export default Categories;