|
|
@ -3,13 +3,22 @@
|
|
|
|
<script>
|
|
|
|
<script>
|
|
|
|
export let people = [];
|
|
|
|
export let people = [];
|
|
|
|
|
|
|
|
|
|
|
|
let filteredPeople;
|
|
|
|
|
|
|
|
let selected;
|
|
|
|
|
|
|
|
let prefix = '';
|
|
|
|
let prefix = '';
|
|
|
|
let first = '';
|
|
|
|
let first = '';
|
|
|
|
let last = '';
|
|
|
|
let last = '';
|
|
|
|
let i = 0;
|
|
|
|
let i = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$: filteredPeople = prefix
|
|
|
|
|
|
|
|
? people.filter(person => {
|
|
|
|
|
|
|
|
const name = `${person.last}, ${person.first}`;
|
|
|
|
|
|
|
|
return name.toLowerCase().startsWith(prefix.toLowerCase());
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
: people;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$: selected = filteredPeople[i];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$: reset_inputs(selected);
|
|
|
|
|
|
|
|
|
|
|
|
function create() {
|
|
|
|
function create() {
|
|
|
|
people = people.concat({ first, last });
|
|
|
|
people = people.concat({ first, last });
|
|
|
|
i = people.length - 1;
|
|
|
|
i = people.length - 1;
|
|
|
@ -27,18 +36,8 @@
|
|
|
|
i = Math.min(i, people.length - 1);
|
|
|
|
i = Math.min(i, people.length - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$: filteredPeople = prefix
|
|
|
|
function reset_inputs(person) {
|
|
|
|
? people.filter(person => {
|
|
|
|
({ first, last } = person);
|
|
|
|
const name = `${person.last}, ${person.first}`;
|
|
|
|
|
|
|
|
return name.toLowerCase().startsWith(prefix.toLowerCase());
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
: people;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$: selected = filteredPeople[i];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$: if (selected) {
|
|
|
|
|
|
|
|
first = selected.first;
|
|
|
|
|
|
|
|
last = selected.last;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|