refactor(frontend): replace reverse-index splice loops with findIndex/filter
Single-match removals use findIndex + splice; the reminder-null cleanup uses filter since model.reminders is on a local shallow clone.
This commit is contained in:
parent
2c6029eac4
commit
dd83e0d42b
|
|
@ -291,13 +291,12 @@ async function deleteSharable() {
|
|||
|
||||
await stuffService.delete(stuffModel)
|
||||
showDeleteModal.value = false
|
||||
for (let i = sharables.value.length - 1; i >= 0; i--) {
|
||||
if (
|
||||
(sharables.value[i].username === stuffModel.username && props.shareType === 'user') ||
|
||||
(sharables.value[i].id === stuffModel.teamId && props.shareType === 'team')
|
||||
) {
|
||||
sharables.value.splice(i, 1)
|
||||
}
|
||||
const idx = sharables.value.findIndex(s =>
|
||||
(props.shareType === 'user' && s.username === stuffModel.username) ||
|
||||
(props.shareType === 'team' && s.id === stuffModel.teamId),
|
||||
)
|
||||
if (idx !== -1) {
|
||||
sharables.value.splice(idx, 1)
|
||||
}
|
||||
success({
|
||||
message: t('project.share.userTeam.removeSuccess', {
|
||||
|
|
|
|||
|
|
@ -99,10 +99,9 @@ async function removeAssignee(user: IUser) {
|
|||
await taskStore.removeAssignee({user: user, taskId: props.taskId})
|
||||
|
||||
// Remove the assignee from the project
|
||||
for (let a = assignees.value.length - 1; a >= 0; a--) {
|
||||
if (assignees.value[a].id === user.id) {
|
||||
assignees.value.splice(a, 1)
|
||||
}
|
||||
const idx = assignees.value.findIndex(a => a.id === user.id)
|
||||
if (idx !== -1) {
|
||||
assignees.value.splice(idx, 1)
|
||||
}
|
||||
success({message: t('task.assignee.unassignSuccess')})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,10 +124,9 @@ async function removeLabel(label: ILabel) {
|
|||
await taskStore.removeLabel({label, taskId: props.taskId})
|
||||
}
|
||||
|
||||
for (let l = labels.value.length - 1; l >= 0; l--) {
|
||||
if (labels.value[l].id === label.id) {
|
||||
labels.value.splice(l, 1)
|
||||
}
|
||||
const idx = labels.value.findIndex(l => l.id === label.id)
|
||||
if (idx !== -1) {
|
||||
labels.value.splice(idx, 1)
|
||||
}
|
||||
emit('update:modelValue', labels.value)
|
||||
success({message: t('task.label.removeSuccess')})
|
||||
|
|
|
|||
|
|
@ -62,11 +62,7 @@ export default class TaskService extends AbstractService<ITask> {
|
|||
|
||||
model.reminderDates = null
|
||||
// remove all nulls, these would create empty reminders
|
||||
for (let index = model.reminders.length - 1; index >= 0; index--) {
|
||||
if (model.reminders[index] === null) {
|
||||
model.reminders.splice(index, 1)
|
||||
}
|
||||
}
|
||||
model.reminders = model.reminders.filter(r => r !== null)
|
||||
// Make normal timestamps from js dates
|
||||
if (model.reminders.length > 0) {
|
||||
model.reminders.forEach(r => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue