Fix time snapping for event drag operations in week view

- Apply snapping to final event position after accounting for click offset
- Ensure preview position matches snapped final position
- Maintain time increment alignment during drag operations
- Fix scope issue for time_increment in mouseup handler

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Connor Johnstone
2025-08-29 13:12:12 -04:00
parent d35fc11267
commit 53ea5e3fc1

View File

@@ -204,6 +204,7 @@ pub fn week_view(props: &WeekViewProps) -> Html {
let drag_state = drag_state_clone.clone();
let on_create_event = props.on_create_event.clone();
let on_event_update = props.on_event_update.clone();
let time_increment = props.time_increment;
Callback::from(move |_e: MouseEvent| {
if let Some(current_drag) = (*drag_state).clone() {
if current_drag.is_dragging && current_drag.has_moved {
@@ -236,7 +237,9 @@ pub fn week_view(props: &WeekViewProps) -> Html {
},
DragType::MoveEvent(event) => {
// Calculate new start time based on drag position (accounting for click offset)
let event_top_position = current_drag.current_y - current_drag.offset_y;
let unsnapped_position = current_drag.current_y - current_drag.offset_y;
// Snap the final position to maintain time increment alignment
let event_top_position = snap_to_increment(unsnapped_position, time_increment);
let new_start_time = pixels_to_time(event_top_position);
// Calculate duration from original event
@@ -601,7 +604,9 @@ pub fn week_view(props: &WeekViewProps) -> Html {
},
DragType::MoveEvent(event) => {
// Calculate the event's new position accounting for click offset
let preview_position = drag.current_y - drag.offset_y;
let unsnapped_position = drag.current_y - drag.offset_y;
// Snap the final position to maintain time increment alignment
let preview_position = snap_to_increment(unsnapped_position, props.time_increment);
let new_start_time = pixels_to_time(preview_position);
let original_duration = if let Some(end) = event.end {
end.signed_duration_since(event.start)