Skip to content

Commit

Permalink
Merge pull request #103 from nokia-wroclaw/fix-calendar-refresh
Browse files Browse the repository at this point in the history
Fix refreshing calendar after event removal
  • Loading branch information
pzmarzly committed Jun 4, 2020
2 parents e8337d5 + 420ff6b commit a1969b6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
9 changes: 3 additions & 6 deletions frontend/src/components/AddNewEventForm/AddNewEventForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,9 @@ const AddNewEventForm = ( { room, onSubmit } ) => {
const [ promise ] = backend.command.addEvent( room.id, event );
promise
.then( () => {
backend.cache.reset();
setTimeout( () => {
onSubmit();
form.resetFields();
setIsWaiting( false );
}, 500 );
onSubmit();
form.resetFields();
setIsWaiting( false );
} )
.catch( ( e ) => {
setIsWaiting( false );
Expand Down
13 changes: 9 additions & 4 deletions frontend/src/pages/RoomDetails/RoomDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const RoomDetails = () => {
.startOf( 'day' )
.toISOString();

const updateCalendar = () => {
const getCalendar = () => {
const [ promise, abort ] = backend.query.roomMetadataAndEvents( roomId, startDate );
promise.then( ( data ) => {
setRoom( data );
Expand All @@ -33,7 +33,12 @@ const RoomDetails = () => {
return abort;
};

useEffect( updateCalendar, [ roomId, backend ] );
const refreshCalendar = () => {
backend.cache.reset();
setTimeout( getCalendar, 500 );
};

useEffect( getCalendar, [ roomId, backend ] );

const [ drawerOpen, setDrawerOpen ] = useState( false );
const openDrawer = () => setDrawerOpen( true );
Expand All @@ -59,7 +64,7 @@ const RoomDetails = () => {
eventsData={ room.events }
startDate={ startDate }
isCompact={ isCompact }
onEventDeleted={ () => updateCalendar() }/>
onEventDeleted={ () => refreshCalendar() }/>

<Drawer
title="Add an event"
Expand All @@ -69,7 +74,7 @@ const RoomDetails = () => {
bodyStyle={ { paddingBottom: 80 } }>
{ canAdd ? <AddNewEventForm room={ room.calendar } onSubmit={ () => {
closeDrawer();
updateCalendar();
refreshCalendar();
} } /> : null }
</Drawer>
</>;
Expand Down

0 comments on commit a1969b6

Please sign in to comment.