Delete tag when update reveals its a duplicate
This commit is contained in:
parent
473517c3b3
commit
2993a7b744
@ -30,6 +30,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
|
|
||||||
if (name.length === 0) {
|
if (name.length === 0) {
|
||||||
deleteTag(event);
|
deleteTag(event);
|
||||||
|
} else {
|
||||||
|
dispatch("tagupdate");
|
||||||
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -15,11 +15,20 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
let newInput: HTMLInputElement;
|
let newInput: HTMLInputElement;
|
||||||
let newName: string = "";
|
let newName: string = "";
|
||||||
|
|
||||||
function focusInputNew(): void {
|
function focusNewInput(): void {
|
||||||
newInput.focus();
|
newInput.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
const insertTagAt = (index: number) => () => {
|
function checkForDuplicateAt(index: number): void {
|
||||||
|
const names = tags.map(getName);
|
||||||
|
const nameToUpdateTo = names.splice(index, 1)[0];
|
||||||
|
|
||||||
|
if (names.includes(nameToUpdateTo)) {
|
||||||
|
deleteTagAt(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function insertTagAt(index: number): void {
|
||||||
const names = tags.map(getName);
|
const names = tags.map(getName);
|
||||||
const nameToInsert = names.splice(index, 1)[0];
|
const nameToInsert = names.splice(index, 1)[0];
|
||||||
|
|
||||||
@ -29,12 +38,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
|
|
||||||
tags.splice(index, 0, attachId(nameToInsert));
|
tags.splice(index, 0, attachId(nameToInsert));
|
||||||
tags = tags;
|
tags = tags;
|
||||||
};
|
}
|
||||||
|
|
||||||
const deleteTagAt = (index: number) => () => {
|
function deleteTagAt(index: number): void {
|
||||||
tags.splice(index, 1);
|
tags.splice(index, 1);
|
||||||
tags = tags;
|
tags = tags;
|
||||||
};
|
}
|
||||||
|
|
||||||
function appendTag(): void {
|
function appendTag(): void {
|
||||||
const names = tags.map(getName);
|
const names = tags.map(getName);
|
||||||
@ -49,13 +58,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
|
|
||||||
<StickyBottom>
|
<StickyBottom>
|
||||||
<div class="d-flex flex-wrap">
|
<div class="d-flex flex-wrap">
|
||||||
<AddTagBadge on:click={focusInputNew} />
|
<AddTagBadge on:click={focusNewInput} />
|
||||||
|
|
||||||
{#each tags as tag, index (tag.id)}
|
{#each tags as tag, index (tag.id)}
|
||||||
<Tag
|
<Tag
|
||||||
bind:name={tag.name}
|
bind:name={tag.name}
|
||||||
on:tagadd={insertTagAt(index)}
|
on:tagupdate={() => checkForDuplicateAt(index)}
|
||||||
on:tagdelete={deleteTagAt(index)}
|
on:tagadd={() => insertTagAt(index)}
|
||||||
|
on:tagdelete={() => deleteTagAt(index)}
|
||||||
/>
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user