|
20 | 20 | import { getConversations, deleteConversation, getConversationStateSearchKeys } from '$lib/services/conversation-service.js'; |
21 | 21 | import { utcToLocal } from '$lib/helpers/datetime'; |
22 | 22 | import { ConversationChannel } from '$lib/helpers/enums'; |
23 | | - import RemoteSearchInput from '$lib/common/RemoteSearchInput.svelte'; |
| 23 | + import StateSearch from './state-search.svelte'; |
24 | 24 |
|
25 | | - let isLoading = false; |
26 | | - let isComplete = false; |
27 | 25 | const duration = 3000; |
28 | 26 | const firstPage = 1; |
29 | 27 | const pageSize = 15; |
30 | 28 |
|
| 29 | + /** @type {boolean} */ |
| 30 | + let isLoading = false; |
| 31 | + let isComplete = false; |
| 32 | + let showStateSearch = false; |
| 33 | +
|
31 | 34 | /** @type {import('$commonTypes').PagedItems<import('$conversationTypes').ConversationModel>} */ |
32 | 35 | let conversations = { count: 0, items: [] }; |
33 | 36 |
|
|
69 | 72 | tags: [] |
70 | 73 | }; |
71 | 74 |
|
72 | | - /** @type {string} */ |
73 | | - let stateKey = ""; |
74 | | -
|
75 | | - /** @type {string | null} */ |
76 | | - let stateValue = null; |
| 75 | + /** @type {{key: string, value: string | null}[]} */ |
| 76 | + let states = [ |
| 77 | + { key: '', value: ''} |
| 78 | + ]; |
77 | 79 |
|
78 | 80 | onMount(async () => { |
79 | 81 | isLoading = true; |
|
214 | 216 | * @param {any} e |
215 | 217 | */ |
216 | 218 | function handleConfirmStateModal(e) { |
217 | | - if (stateKey) { |
218 | | - searchOption.states = [ |
219 | | - { |
220 | | - key: { data: stateKey, isValid: true }, |
221 | | - value: { data: stateValue || '', isValid: true }, |
222 | | - active_rounds: {data: -1, isValid: true}, |
223 | | - } |
224 | | - ]; |
225 | | - } else { |
226 | | - searchOption.states = []; |
227 | | - } |
| 219 | + searchOption.states = states.filter(x => !!lodash.trim(x.key)).map(x => ({ |
| 220 | + key: { data: x.key, isValid: true }, |
| 221 | + value: { data: x.value || '', isValid: true }, |
| 222 | + active_rounds: {data: -1, isValid: true}, |
| 223 | + })); |
228 | 224 | handleSearchStates(); |
229 | 225 | searchConversations(e); |
230 | 226 | } |
|
251 | 247 | } |
252 | 248 |
|
253 | 249 | function getSearchStates() { |
254 | | - return searchOption.states?.map(x => { |
255 | | - return { |
256 | | - key: x.key?.data, |
257 | | - value: x.value?.data |
258 | | - }; |
259 | | - }) || []; |
| 250 | + searchOption.states = states?.filter(x => !!lodash.trim(x.key))?.map(x => ({ |
| 251 | + key: { data: x.key, isValid: true }, |
| 252 | + value: { data: x.value || '', isValid: true }, |
| 253 | + active_rounds: {data: -1, isValid: true}, |
| 254 | + })) || []; |
| 255 | + return searchOption.states.map(x => ({ key: x.key.data, value: x.value.data }));; |
260 | 256 | } |
261 | 257 |
|
262 | 258 | function handleSearchStates() { |
|
358 | 354 | <div class="mb-0 card-title flex-grow-0"> |
359 | 355 | <h5 class="mb-0">{$_('Conversation List')}</h5> |
360 | 356 | </div> |
361 | | - <div> |
362 | | - <div class="state-search-container"> |
363 | | - <div> |
364 | | - <RemoteSearchInput |
365 | | - bind:value={stateKey} |
366 | | - onSearch={e => handleStateSearch(e)} |
367 | | - placeholder="Search States" |
368 | | - /> |
369 | | - </div> |
370 | | - <div> |
371 | | - <Input |
372 | | - type="text" |
373 | | - bind:value={stateValue} |
374 | | - disabled={!stateKey} |
375 | | - placeholder="Enter a value" |
376 | | - /> |
377 | | - </div> |
378 | | - <div> |
379 | | - <Button color="primary" on:click={handleConfirmStateModal}>Confirm</Button> |
| 357 | + <div class="state-search-btn-wrapper"> |
| 358 | + <Button |
| 359 | + color={showStateSearch ? 'secondary' : 'primary'} |
| 360 | + on:click={() => showStateSearch = !showStateSearch} |
| 361 | + > |
| 362 | + <div class="state-search-btn"> |
| 363 | + <div> |
| 364 | + {#if showStateSearch} |
| 365 | + <i class="bx bx-hide" /> |
| 366 | + {:else} |
| 367 | + <i class="bx bx-search-alt" /> |
| 368 | + {/if} |
| 369 | + </div> |
| 370 | + <div class="search-btn-text">{'State Search'}</div> |
380 | 371 | </div> |
381 | | - </div> |
| 372 | + </Button> |
382 | 373 | </div> |
383 | 374 | </div> |
384 | 375 | </CardBody> |
| 376 | + {#if showStateSearch} |
| 377 | + <CardBody class="border-bottom" style="display: flex; justify-content: flex-end;"> |
| 378 | + <StateSearch bind:states={states} onSearch={q => handleStateSearch(q)}/> |
| 379 | + </CardBody> |
| 380 | + {/if} |
385 | 381 | <CardBody class="border-bottom"> |
386 | 382 | <Row class="g-3"> |
387 | 383 | <Col lg="3"> |
|
0 commit comments