Skip to content

Commit

Permalink
fixup! feat(FileDataProvider): implement remove-event
Browse files Browse the repository at this point in the history
  • Loading branch information
ja-he committed Aug 5, 2024
1 parent ae5c56f commit 367585f
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions internal/control/cli/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func NewController(
for i, e := range events {
eventIDs[i] = e.ID
}
controller.dataProvider.RemoveEvents(eventIDs)
controller.removeEvents(eventIDs)
}),
}

Expand Down Expand Up @@ -747,7 +747,7 @@ func NewController(
"d": action.NewSimple(func() string { return "delete selected event" }, func() {
event := controller.data.CurrentEventID
if event != nil {
controller.dataProvider.RemoveEvent(*event)
controller.removeEvent(*event)
}
}),
"<cr>": action.NewSimple(func() string { return "open the event editor" }, func() {
Expand Down Expand Up @@ -1777,7 +1777,7 @@ func (c *Controller) handleMouseNoneEditEvent(e *tcell.EventMouse) {
// if button clicked, handle
switch buttons {
case tcell.Button3:
c.dataProvider.RemoveEvent(eventsInfo.Event.ID)
c.removeEvent(eventsInfo.Event.ID)
case tcell.Button2:
event := eventsInfo.Event
if event != nil && eventsInfo.Time.After(event.Start) {
Expand Down Expand Up @@ -2205,3 +2205,32 @@ func (c *Controller) moveEventsBackwardPushing() error {
func (c *Controller) moveEventsPushingBy(d, m time.Duration) error {
return fmt.Errorf("unimplemented (this should push for %s (with res %s))", d, m)
}

func (c *Controller) removeEvent(id model.EventID) {
nextEvent, err := c.dataProvider.GetFollowingEvent(id)
var nextEventID *model.EventID
if err != nil {
c.log.Error().Err(err).Msg("could not get following event")
} else if nextEvent != nil {
nextEventID = new(model.EventID)
*nextEventID = nextEvent.ID
}
err = c.dataProvider.RemoveEvent(id)
if err != nil {
c.log.Error().Err(err).Msg("could not remove event")
return
}
c.data.CurrentEventID = nextEventID
c.ensureCurrentEventVisible()
}

func (c *Controller) removeEvents(ids []model.EventID) {
err := c.dataProvider.RemoveEvents(ids)
if err != nil {
c.log.Error().Err(err).Msg("could not remove events")
return
}

c.log.Warn().Msgf("missing implementation of current-event updating after removing multiple events (just nilling)")
c.data.CurrentEventID = nil
}

0 comments on commit 367585f

Please sign in to comment.