fix(frontend): correctly remove entries

This commit is contained in:
Jake 2023-03-29 11:06:39 +02:00 committed by Sam
parent bca0404b71
commit ce214d2066
No known key found for this signature in database
GPG Key ID: B4EF20DDE721CAA1
2 changed files with 16 additions and 32 deletions

View File

@ -190,31 +190,23 @@
}; };
const removeName = (index: number) => { const removeName = (index: number) => {
if (names.length === 1) names = []; names.splice(index, 1);
else if (index === 0) names = names.slice(1); names = [...names];
else if (index === names.length - 1) names = names.slice(0, names.length - 1);
else names = [...names.slice(0, index - 1), ...names.slice(0, index + 1)];
}; };
const removePronoun = (index: number) => { const removePronoun = (index: number) => {
if (pronouns.length === 1) pronouns = []; pronouns.splice(index, 1);
else if (index === 0) pronouns = pronouns.slice(1); pronouns = [...pronouns];
else if (index === pronouns.length - 1) pronouns = pronouns.slice(0, pronouns.length - 1);
else pronouns = [...pronouns.slice(0, index - 1), ...pronouns.slice(0, index + 1)];
}; };
const removeLink = (index: number) => { const removeLink = (index: number) => {
if (links.length === 1) links = []; links.splice(index, 1);
else if (index === 0) links = links.slice(1); links = [...links];
else if (index === links.length - 1) links = links.slice(0, links.length - 1);
else links = [...links.slice(0, index - 1), ...links.slice(0, index + 1)];
}; };
const removeField = (index: number) => { const removeField = (index: number) => {
if (fields.length === 1) fields = []; fields.splice(index, 1);
else if (index === 0) fields = fields.slice(1); fields = [...fields];
else if (index === fields.length - 1) fields = fields.slice(0, fields.length - 1);
else fields = [...fields.slice(0, index - 1), ...fields.slice(0, index + 1)];
}; };
const updateMember = async () => { const updateMember = async () => {

View File

@ -174,31 +174,23 @@
}; };
const removeName = (index: number) => { const removeName = (index: number) => {
if (names.length === 1) names = []; names.splice(index, 1);
else if (index === 0) names = names.slice(1); names = [...names];
else if (index === names.length - 1) names = names.slice(0, names.length - 1);
else names = [...names.slice(0, index - 1), ...names.slice(0, index + 1)];
}; };
const removePronoun = (index: number) => { const removePronoun = (index: number) => {
if (pronouns.length === 1) pronouns = []; pronouns.splice(index, 1);
else if (index === 0) pronouns = pronouns.slice(1); pronouns = [...pronouns];
else if (index === pronouns.length - 1) pronouns = pronouns.slice(0, pronouns.length - 1);
else pronouns = [...pronouns.slice(0, index - 1), ...pronouns.slice(0, index + 1)];
}; };
const removeLink = (index: number) => { const removeLink = (index: number) => {
if (links.length === 1) links = []; links.splice(index, 1);
else if (index === 0) links = links.slice(1); links = [...links];
else if (index === links.length - 1) links = links.slice(0, links.length - 1);
else links = [...links.slice(0, index - 1), ...links.slice(0, index + 1)];
}; };
const removeField = (index: number) => { const removeField = (index: number) => {
if (fields.length === 1) fields = []; fields.splice(index, 1);
else if (index === 0) fields = fields.slice(1); fields = [...fields];
else if (index === fields.length - 1) fields = fields.slice(0, fields.length - 1);
else fields = [...fields.slice(0, index - 1), ...fields.slice(0, index + 1)];
}; };
const updateUser = async () => { const updateUser = async () => {