@@ -9,9 +9,8 @@ class SearchHieroglyphs extends HTMLElement {
9
9
this . db = hieroglyphDb
10
10
11
11
this . innerHTML = `
12
- <div class="results-info"></div>
13
- <div class="results">
14
- </div>
12
+ <div class="results-info"></div>
13
+ <div class="results"></div>
15
14
`
16
15
17
16
this . listen ( )
@@ -31,9 +30,12 @@ class SearchHieroglyphs extends HTMLElement {
31
30
32
31
renderResultsInfo ( query = { } , results = this . db . hieroglyphs ) {
33
32
if ( Object . entries ( query ) . length > 0 ) {
34
- let queryInfo = document . createElement ( 'div' )
35
- queryInfo . textContent = `Your search for "${ this . stringifyQuery ( query ) } " had ${ results . length } result${ results . length !== 1 ? 's' : '' } .`
36
- this . querySelector ( '.results-info' ) . append ( queryInfo )
33
+ this . querySelector ( '.results-info' )
34
+ . innerHTML = `Your search for "${ this . stringifyQuery ( query ) } " had ${ results . length } result${ results . length !== 1 ? 's' : '' } . `
35
+
36
+ this . querySelector ( '.results-info' )
37
+ . insertAdjacentHTML ( 'beforeend' , `<button class=clear-results-button>Clear</button>` )
38
+
37
39
}
38
40
}
39
41
@@ -63,9 +65,15 @@ class SearchHieroglyphs extends HTMLElement {
63
65
}
64
66
65
67
listen ( ) {
68
+ this . addEventListener ( 'click' , clickEvent => {
69
+ if ( clickEvent . target . matches ( '.clear-results-button' ) ) {
70
+ this . renderResults ( )
71
+ }
72
+ } )
73
+
66
74
this . addEventListener ( 'hieroglyph-clicked' , hieroglyphClickedEvent => {
67
75
let hieroglyph = hieroglyphClickedEvent . detail
68
- console . log ( hieroglyph )
76
+ this . search ( ` hieroglyph: ${ hieroglyph . hieroglyph } ` )
69
77
} )
70
78
71
79
this . addEventListener ( 'category-clicked' , categoryClickedEvent => {
0 commit comments