Skip to content

Commit

Permalink
Fixed state change
Browse files Browse the repository at this point in the history
  • Loading branch information
tssweeney committed Oct 29, 2024
1 parent 975f52a commit 6a4292a
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ export const LeaderboardPageContentInner: React.FC<
props.project,
props.leaderboardName
);
const [workingLeaderboardValCopy, setWorkingLeaderboardValCopy] = useState(
props.leaderboardVal
);
const [leaderboardVal, setLeaderboardVal] = useState(props.leaderboardVal);
const [workingLeaderboardValCopy, setWorkingLeaderboardValCopy] =
useState(leaderboardVal);
useEffect(() => {
props.setName(workingLeaderboardValCopy.name);
}, [props, workingLeaderboardValCopy.name]);
Expand All @@ -186,30 +186,32 @@ export const LeaderboardPageContentInner: React.FC<
);
const [saving, setSaving] = useState(false);
const discardChanges = useCallback(() => {
setWorkingLeaderboardValCopy(props.leaderboardVal);
setWorkingLeaderboardValCopy(leaderboardVal);
props.setIsEditing(false);
}, [props]);
}, [leaderboardVal, props]);
const commitChanges = useCallback(() => {
const mounted = true;
setSaving(true);
updateLeaderboard(workingLeaderboardValCopy)
.then(() => {
if (mounted) {
props.setIsEditing(false);
setLeaderboardVal(workingLeaderboardValCopy);
setWorkingLeaderboardValCopy(workingLeaderboardValCopy);
setSaving(false);
}
})
.catch(e => {
console.error(e);
if (mounted) {
setWorkingLeaderboardValCopy(props.leaderboardVal);
setWorkingLeaderboardValCopy(leaderboardVal);
setSaving(false);
}
});
}, [props, updateLeaderboard, workingLeaderboardValCopy]);
}, [leaderboardVal, props, updateLeaderboard, workingLeaderboardValCopy]);
const isDirty = useMemo(() => {
return !_.isEqual(props.leaderboardVal, workingLeaderboardValCopy);
}, [props.leaderboardVal, workingLeaderboardValCopy]);
return !_.isEqual(leaderboardVal, workingLeaderboardValCopy);
}, [leaderboardVal, workingLeaderboardValCopy]);
const columnOrder = useMemo(() => {
return workingLeaderboardValCopy.columns
.map(col => {
Expand Down

0 comments on commit 6a4292a

Please sign in to comment.