keep selected sender from hash until user selects others

This commit is contained in:
lilydjwg 2021-10-24 21:08:33 +08:00
parent acf925e616
commit 5e7e55b485
2 changed files with 8 additions and 4 deletions

View File

@ -15,6 +15,7 @@
let loading = false let loading = false
let need_update_title = false let need_update_title = false
let sender let sender
let selected_init
setContext('LUOXU_URL', LUOXU_URL) setContext('LUOXU_URL', LUOXU_URL)
@ -79,6 +80,7 @@
} }
if(info.has('sender')) { if(info.has('sender')) {
sender = info.get('sender') sender = info.get('sender')
selected_init = sender
} }
if((group || islocal) && query) { if((group || islocal) && query) {
result = null result = null
@ -176,7 +178,7 @@
on:input={() => error = ''} on:input={() => error = ''}
on:keydown={e => {if(e.key == 'Enter'){do_search()}}} on:keydown={e => {if(e.key == 'Enter'){do_search()}}}
/> />
<Name group={group} bind:selected={sender}/> <Name group={group} bind:selected={sender} selected_init={selected_init}/>
<button on:click={() => do_search()}>搜索</button> <button on:click={() => do_search()}>搜索</button>
</div> </div>

View File

@ -4,6 +4,7 @@
export let group export let group
export let selected export let selected
export let selected_init
let selected_name = '' let selected_name = ''
let selected_idx let selected_idx
@ -76,16 +77,17 @@
selected = names[selected_idx][0] selected = names[selected_idx][0]
selected_name = names[selected_idx][1] selected_name = names[selected_idx][1]
input.value = selected_name input.value = selected_name
selected_init = null
} }
function update_value() { function update_value() {
if(!selected) { if(!selected || selected === selected_init) {
return return
} }
if(input.value) { if(input.value) {
input.value = selected_name input.value = selected_name
}else{ }else{
selected = null selected = selected_init
selected_name = '' selected_name = ''
} }
} }
@ -118,7 +120,7 @@
} }
} }
} }
// TODO: NOT operator
</script> </script>
<div> <div>