Something went wrong. Try again.
A simple to-do app focused on tasks that can be completed within a specific time span. taskline.tobinio.dev
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031import type { Todo, Uuid } from "./types";
export function updateOrInsertAfterTodo( data: Todo[], insert: Todo, position: "top" | "bottom", previous?: Uuid,): Todo[] { const index = data.findIndex((value) => value.uuid === insert.uuid); const previousIndex = previous ? data.findIndex((value) => value.uuid === previous) : undefined;
if (index === -1) { if (previousIndex !== undefined) { const offset = position === "top" ? 0 : 1; data.splice(previousIndex + offset, 0, insert); } else { if (position === "top") { data.unshift(insert); } else { data.push(insert); } } } else { data[index] = insert; }
return data;}