Skip to content

Commit

Permalink
Fix range bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jmattheis committed Dec 7, 2019
1 parent a9f9170 commit 49d3a04
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
19 changes: 13 additions & 6 deletions ui/src/timespan/TimeSpan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface TimeSpanProps {
range: Range & {oldFrom?: moment.Moment};
initialTags: TagSelectorEntry[];
dateSelectorOpen?: React.Dispatch<React.SetStateAction<boolean>>;
rangeChange?: (r: Range) => void;
deleted?: () => void;
stopped?: () => void;
continued?: () => void;
Expand All @@ -46,6 +47,7 @@ export const TimeSpan: React.FC<TimeSpanProps> = React.memo(
id,
initialTags,
dateSelectorOpen = () => {},
rangeChange = () => {},
deleted = () => {},
stopped = () => {},
continued = () => {},
Expand Down Expand Up @@ -103,13 +105,18 @@ export const TimeSpan: React.FC<TimeSpanProps> = React.memo(
}
},
});

const wasMoved = !isSameDate(from, oldFrom);
const showDate = to !== undefined && (!isSameDate(from, to) || wasMoved);
return (
<Paper
elevation={elevation}
style={{display: 'flex', alignItems: 'center', padding: '10px', margin: '10px 0', opacity: wasMoved ? 0.5 : 1}}>
style={{
display: 'flex',
alignItems: 'center',
padding: '10px',
margin: '10px 0',
opacity: wasMoved ? 0.5 : 1,
}}>
<div style={{flex: '1', marginRight: 10}}>
<TagSelector
dialogOpen={dateSelectorOpen}
Expand Down Expand Up @@ -145,7 +152,7 @@ export const TimeSpan: React.FC<TimeSpanProps> = React.memo(
end: inUserTz(newTo).format(),
tags: toInputTags(selectedEntries),
},
});
}).then(() => rangeChange({from: newFrom, to: newTo}));
} else {
updateTimeSpan({
variables: {
Expand All @@ -155,7 +162,7 @@ export const TimeSpan: React.FC<TimeSpanProps> = React.memo(
end: to && inUserTz(to).format(),
tags: toInputTags(selectedEntries),
},
});
}).then(() => rangeChange({from: newFrom, to}));
}
}}
showDate={showDate}
Expand All @@ -179,7 +186,7 @@ export const TimeSpan: React.FC<TimeSpanProps> = React.memo(
end: inUserTz(newTo).format(),
tags: toInputTags(selectedEntries),
},
});
}).then(() => rangeChange({from: newFrom, to: newTo}));
} else {
updateTimeSpan({
variables: {
Expand All @@ -189,7 +196,7 @@ export const TimeSpan: React.FC<TimeSpanProps> = React.memo(
end: inUserTz(newTo).format(),
tags: toInputTags(selectedEntries),
},
});
}).then(() => rangeChange({from, to: newTo}));
}
}}
showDate={showDate}
Expand Down
6 changes: 6 additions & 0 deletions ui/src/timespan/calendar/CalendarPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ export const CalendarPage: React.FC = () => {
elevation={10}
id={selected.data!.id}
key={selected.data!.id}
rangeChange={(range) => {
setSelected({
...selected,
data: {...selected.data!, start: range.from.format(), end: range.to && range.to.format()},
});
}}
deleted={() => {
removeFromTimeSpanInRangeCache(apollo.cache, selected.data!.id, timeSpansResult.variables);
setSelected({selected: null, data: null});
Expand Down

0 comments on commit 49d3a04

Please sign in to comment.