Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
Joosakur committed Jan 21, 2025
1 parent 0c620c1 commit ae54f17
Showing 1 changed file with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ export default React.memo(function UnitPreferenceSection(

useEffect(() => {
updateFormData((prev) => {
if (
units &&
prev.preferredUnits.some((u1) => !units.some((u2) => u1.id === u2.id))
) {
const preferredUnits = units
? prev.preferredUnits.filter(({ id }) =>
units.some((unit) => unit.id === id)
)
: prev.preferredUnits

if (preferredUnits.length < prev.preferredUnits.length) {
setInfoMessage({
title: t.applications.editor.unitChangeWarning.title,
text: t.applications.editor.unitChangeWarning.text,
Expand All @@ -89,13 +92,8 @@ export default React.memo(function UnitPreferenceSection(
}
})
}
return {
preferredUnits: units
? prev.preferredUnits.filter(({ id }) =>
units.some((unit) => unit.id === id)
)
: prev.preferredUnits
}

return { preferredUnits }
})
}, [
units,
Expand Down

0 comments on commit ae54f17

Please sign in to comment.