-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproductsview.js
129 lines (102 loc) · 4.18 KB
/
productsview.js
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
LiveG Docs
Copyright (C) LiveG. All Rights Reserved.
https://docs.liveg.tech
Licensed by the LiveG Open-Source Licence, which can be found at LICENCE.md.
*/
import * as astronaut from "https://opensource.liveg.tech/Adapt-UI/astronaut/astronaut.js";
import Fuse from "./lib/fuse.esm.js";
export var ProductsViewScreen = astronaut.component("ProductsViewScreen", function(props, children) {
var searchInput = Input({type: "search", placeholder: _("productsView_search")}) ();
var productsList = Section (
Cards({mode: "grid"}) (
...Object.keys(props.products).map(function(productId) {
var product = props.products[productId];
var locale = product.name[props.locale] ? props.locale : product.fallbackLocale;
var link = Link() (Text(product.name[locale]));
var card = Card() (
Heading(2) (link),
Paragraph() (Text(product.description[locale]))
);
link.on("click", function(event) {
screen.emit("opendoc", {product: productId});
});
return card;
})
)
);
var searchResultsList = Section() ();
searchResultsList.hide();
var screen = Screen (
Page(true) (
Section (
Container({attributes: {"aui-justify": "middle"}}) (
Heading({level: 1, styles: {fontSize: "4rem"}}) (
BrandWordmark(_("livegDocs")) (
Text(_("livegDocs_wordmark"))
)
),
Paragraph() (_("productsView_tagline")),
searchInput
)
),
productsList,
searchResultsList
)
);
fetch("data/searchindex.json").then(function(response) {
return response.json();
}).then(function(data) {
var index = data.index.filter(function(entry) {
return entry.locale == props.locale;
}).map(function(entry) {
var product = props.products[entry.productId];
entry.productName = product.name[props.locale] || product.name[product.fallbackLocale];
entry.url = `${product.docsRootUrl[props.locale] || product.docsRootUrl[product.fallbackLocale]}/${entry.page}`;
return entry;
});
var searcher = new Fuse(index, {
keys: ["pageName", "productName"]
});
searchInput.on("input", function() {
var query = searchInput.getValue().trim();
var results = searcher.search(query);
if (query == "") {
searchResultsList.hide();
productsList.show();
return;
}
if (results.length > 0) {
searchResultsList.clear().add(
Cards() (
...results.map(function(result) {
var data = result.item;
var link = Link() ();
link.setHTML(new showdown.Converter().makeHtml(data.pageName));
link.setHTML(link.find("p").getHTML());
var card = Card() (
Heading(2) (link),
Paragraph() (Text(data.productName))
);
link.on("click", function() {
screen.emit("opendoc", {product: data.productId, page: data.page});
});
return card;
})
)
);
} else {
searchResultsList.clear().add(
Message() (
Icon("search", "dark embedded") (),
Heading(2) (_("productsView_noResults_title")),
Paragraph() (_("productsView_noResults_description"))
)
);
}
productsList.hide();
searchResultsList.show();
});
});
return screen;
});