comparison web/src/main.ts @ 8:f23b21bd0fce

apex search
author drewp@bigasterisk.com
date Sun, 07 Jul 2024 16:26:56 -0700
parents a4659594f2e5
children b9c2b7fedbcd
comparison
equal deleted inserted replaced
7:53ae53f7d1b3 8:f23b21bd0fce
40 width: 237px; 40 width: 237px;
41 position: absolute; 41 position: absolute;
42 left: -33px; 42 left: -33px;
43 top: -22px; 43 top: -22px;
44 z-index: -1; 44 z-index: -1;
45 }
46 dt {
47 color: blue;
48 }
49 dd {
50 margin-bottom: 25px;
45 } 51 }
46 `, 52 `,
47 ]; 53 ];
48 @state() query: string = "climate"; 54 @state() query: string = "climate";
49 @state() results: Object[] = []; 55 @state() results: Object[] = [];
104 <sl-button variant="primary" @click=${this.submit}>Submit</sl-button> 110 <sl-button variant="primary" @click=${this.submit}>Submit</sl-button>
105 <div>${this.queryError}</div> 111 <div>${this.queryError}</div>
106 </form> 112 </form>
107 </section> 113 </section>
108 <section id="results"> 114 <section id="results">
109 ${this.results.map( 115 <dl>
110 (r) => 116 ${this.results.map(
111 html`<div>${r.title}</div> 117 (r) =>
112 <div>${unsafeHTML(r.snippetHtml)}</div>` 118 html`<dt>${r.title}</dt>
113 )} 119 <dd>${unsafeHTML(r.snippetHtml)}</dd>`
120 )}
121 </dl>
114 <div>Matching results: ${this.results.length}</div> 122 <div>Matching results: ${this.results.length}</div>
115 </section> 123 </section>
116 `; 124 `;
117 } 125 }
118 126
125 133
126 this.results = []; 134 this.results = [];
127 135
128 const sentQ = await this.getCurrentQuery(); 136 const sentQ = await this.getCurrentQuery();
129 137
130 // const resp = await fetch("query", { 138 const resp = await fetch("query?" + new URLSearchParams({ q: sentQ }));
131 // method: "POST", 139 if (sentQ != (await this.getCurrentQuery())) {
132 // body: "query=" + encodeURIComponent(sentQ), 140 // old result- ignore
133 // headers: { "Content-Type": "application/x-www-form-urlencoded" }, 141 return;
134 // }); 142 }
135 // if (sentQ != (await this.getCurrentQuery())) { 143 this.results = (await resp.json()).results;
136 // // old result- ignore
137 // return;
138 // }
139 this.results.push({ title: "doc1", snippetHtml: "<h1>hello</h1>" });
140 console.log("ScoSearchPage ~ submit ~ this.results:", this.results);
141 this.requestUpdate(); 144 this.requestUpdate();
142 } 145 }
143 } 146 }