|
2 | 2 | <section id="ExercisesPanel" class="exercises-wrapper"> |
3 | 3 | <header ref="headerExercise"> |
4 | 4 | <div class="header-wrapper"> |
5 | | - <h1> |
6 | | - Résultats de recherche |
7 | | - <span v-if="!isEmptySearchModel"> - {{searchModel}}</span> |
8 | | - </h1> |
| 5 | + |
| 6 | + <div class="input-wrapper--with-icon input-with--enter-icon"> |
| 7 | + <Icon type="search"/> |
| 8 | + <input ref="inputText" class="input--primary-color" type="text" @input="resetIfEmpty" @keydown.enter="debounceInput" |
| 9 | + placeholder="Rechercher"> |
| 10 | + </div> |
9 | 11 |
|
10 | 12 | <div class="results"> |
11 | 13 | {{nbOfResults}} résultats - <span @click.self="reset" class="init">réinitialiser la recherche</span> |
|
39 | 41 | import PreviewExercise from '~/components/Exercise/PreviewExercise.vue' |
40 | 42 | import IntersectMixins from "~/components/Mixins/IntersectMixins.vue"; |
41 | 43 | import {Exercise, SelectedTag, TagLabelObjectEmitted, TagState} from "~/types"; |
| 44 | + import Icon from "~/components/Symbols/Icon.vue"; |
42 | 45 |
|
43 | 46 | const ratio = .2; |
44 | 47 |
|
45 | 48 | @Component({ |
46 | 49 | components: { |
| 50 | + Icon, |
47 | 51 | Tag, |
48 | 52 | PreviewExercise |
49 | 53 | } |
|
52 | 56 | @Ref() headerExercise!: HTMLElement; |
53 | 57 | @Ref() bodyExercise!: HTMLElement; |
54 | 58 | @Ref() anchor!: Element; |
| 59 | + @Ref() inputText!: HTMLInputElement; |
| 60 | +
|
| 61 | +
|
55 | 62 |
|
56 | 63 | intersectionObserverOptions: IntersectionObserverInit = { |
57 | 64 | root: null, |
|
188 | 195 | } |
189 | 196 | }); |
190 | 197 |
|
191 | | - this.$emit('reset'); |
| 198 | + this.resetInput(); |
| 199 | + } |
| 200 | +
|
| 201 | + debounceInput(e: any) { |
| 202 | + const value = e.target.value; |
| 203 | + this.$accessor.exercises.fetch({data: {title: value}}); |
| 204 | + this.$accessor.historical.addHistorical({ |
| 205 | + tags: this.$accessor.tags.selectedTags, |
| 206 | + title: value, |
| 207 | + vote: this.$accessor.exercises.search_criterion.vote |
| 208 | + }) |
| 209 | + } |
| 210 | +
|
| 211 | + resetInput() { |
| 212 | + this.inputText.value = "" |
| 213 | + } |
| 214 | +
|
| 215 | + resetIfEmpty(e:any) { |
| 216 | + const value:string = e.target.value; |
| 217 | +
|
| 218 | + if(value === '') { |
| 219 | + this.$accessor.exercises.fetch({data: {title: ""}}); |
| 220 | + } |
| 221 | + } |
| 222 | +
|
| 223 | + refreshInput() { |
| 224 | + this.inputText.value = this.$accessor.exercises.search_criterion.title || ''; |
| 225 | + } |
| 226 | +
|
| 227 | + setInput() { |
| 228 | + const title = this.$accessor.exercises.search_criterion.title; |
| 229 | + this.inputText.value = !!title ? title : ''; |
192 | 230 | } |
193 | 231 |
|
194 | 232 | handleIntersect(entries: IntersectionObserverEntry[]) { |
|
202 | 240 | targets(): Element[] { |
203 | 241 | return [this.anchor] |
204 | 242 | } |
| 243 | +
|
| 244 | + mounted() { |
| 245 | + this.setInput(); |
| 246 | + } |
205 | 247 | } |
206 | 248 | </script> |
207 | 249 |
|
|
236 | 278 | } |
237 | 279 | } |
238 | 280 |
|
| 281 | + .input-wrapper--with-icon { |
| 282 | + width: 100%; |
| 283 | + max-width: 400px; |
| 284 | + margin-bottom: 15px; |
| 285 | +
|
| 286 | + input { |
| 287 | + width: 100%; |
| 288 | + } |
| 289 | + } |
| 290 | +
|
239 | 291 | .exercises-content-wrapper { |
240 | 292 | overflow-y: scroll; |
241 | 293 | max-height: calc(100% - 66px); |
|
0 commit comments