Skip to content

Commit

Permalink
fix: improving the ignore change function
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasz97 committed Sep 27, 2024
1 parent be26c82 commit 315b44f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/components/timesheet/TimeSheetTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,35 @@ export const TimeSheetTable = component$<TimeSheetTableProps>(
}
timeEntriesState[project.name][date] = hours;

// This functions will ignore the change if the user passes over a time entry without editing it
const ignoreChange = () => {
const { hours, date, project, task, startHour, endHour, description } =
const { index, hours, date, project, task, startHour, endHour, description } =
timeEntryObject;

if (timeEntriesState[project.name][date] !== hours) return false;

const entryNotChanged = state.dataTimeEntries.find(
// Check if the entry already exists
const entryExists = state.dataTimeEntries.find(
(entry) =>
entry.hours === hours &&
entry.index === index &&
entry.date === date &&
entry.project.name === project.name &&
entry.project.type === project.type &&
entry.task === task &&
entry.task.name === task.name &&
entry.startHour === startHour &&
entry.endHour === endHour &&
entry.description === description
);

return entryNotChanged || (entryNotChanged && hours === 0);
// If the entry exists
if (entryExists) {
// Return true if the new hours are the same as the existing hours
return entryExists.hours === hours;
} else {
// If the entry does not exist
// return true if the hours are 0
return hours === 0;
}
};

if (ignoreChange()) {
Expand Down

0 comments on commit 315b44f

Please sign in to comment.