Skip to content

Commit 1ceb9a6

Browse files
mattludwigsfhunleth
authored andcommitted
Search on load
1 parent 26eb5d8 commit 1ceb9a6

File tree

3 files changed

+13
-34
lines changed

3 files changed

+13
-34
lines changed

index.html

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,6 @@ <h3><a href="https://github.com/elixir-circuits/circuits_uart">UART</a></h3>
5858
<div class="container section content js-hex-query-component query-component">
5959
<h2 class="header h2 text center">What uses Elixir Circuits?</h2>
6060

61-
62-
<div class="flex-container library-search">
63-
<a href="#" class="js-hex-circuits-library btn btn--big pill hover-active" data-name="circuits_gpio">GPIO</a>
64-
<a href="#" class="js-hex-circuits-library btn pill btn--big hover-active" data-name="circuits_i2c">I2C</a>
65-
<a href="#" class="js-hex-circuits-library btn pill btn--big hover-active" data-name="circuits_spi">SPI</a>
66-
<a href="#" class="js-hex-circuits-library btn pill btn--big hover-active" data-name="circuits_uart">UART</a>
67-
</div>
68-
6961
<div class="js-hex-search-avalibale-libraries avalibale-libraries-list"></div>
7062
</div>
7163
<footer>

index.js

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,21 @@ var hexSearch = {
1212
},
1313

1414
init: function () {
15-
console.log("Starting query eng");
15+
var libraries = ["circuits_uart", "circuits_i2c", "circuits_gpio", "circuits_spi"];
1616

17-
var jsQueryDom = document.querySelector(".js-hex-query-component");
18-
var jsHexSearchlibraries = document.querySelectorAll(".js-hex-circuits-library");
19-
20-
for (var i = 0; i < jsHexSearchlibraries.length; i++) {
21-
this.attachLibraryClick(jsHexSearchlibraries[i], this.state);
17+
for (var i = 0; i < libraries.length; i++) {
18+
this.update("search", libraries[i], this.state);
2219
}
2320
},
2421

2522
update: function(update_command, updateData, state) {
2623
switch (update_command) {
2724
case "search":
28-
var elm = updateData[0];
29-
var libQuery = updateData[1];
30-
31-
if (elm.classList.contains("active")) {
32-
state[this.libNameToStateName(libQuery)] = [];
33-
elm.classList.remove("active");
34-
this.update("updateDom", null, state);
35-
} else {
36-
state.lastSearch = libQuery;
37-
elm.classList.add("active");
38-
this.update("search_response", this.search(libQuery), state);
39-
}
40-
25+
this.update("search_response", [this.search(updateData), updateData], state);
4126
break;
4227
case "search_response":
43-
updateData
28+
var libSearched = updateData[1];
29+
updateData[0]
4430
.then(function (response) {
4531
for (var i = 0; i < response.data.length; i++) {
4632
var lib = {
@@ -49,19 +35,19 @@ var hexSearch = {
4935
description: response.data[i].meta.description,
5036
};
5137

52-
if (state.lastSearch === "circuits_i2c") {
38+
if (libSearched === "circuits_i2c") {
5339
state.i2cLibraries.push(lib);
5440
}
5541

56-
if (state.lastSearch === "circuits_gpio") {
42+
if (libSearched === "circuits_gpio") {
5743
state.gpioLibraries.push(lib);
5844
}
5945

60-
if (state.lastSearch === "circuits_spi") {
46+
if (libSearched === "circuits_spi") {
6147
state.gpioLibraries.push(lib);
6248
}
6349

64-
if (state.lastSearch === "circuits_uart") {
50+
if (libSearched === "circuits_uart") {
6551
state.uartLibraries.push(lib);
6652
}
6753
}
@@ -96,6 +82,7 @@ var hexSearch = {
9682

9783
updateDom: function(state) {
9884
var ul = document.createElement("ul");
85+
ul.classList.add("flex-container");
9986
ul.id = "js-hex-lib-list";
10087

10188
for (var i = 0; i < state.i2cLibraries.length; i++) {

styles.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ ul {
176176
}
177177

178178
.library-search-item {
179-
margin-bottom: 25px;
179+
margin: 25px;
180180
}
181181

182182
.library-search-item .library-name {
@@ -195,8 +195,8 @@ ul {
195195
}
196196

197197
.avalibale-libraries-list {
198-
width: 50%;
199198
text-align: center;
199+
padding: 15px;
200200
}
201201

202202
footer {

0 commit comments

Comments
 (0)