mirror of
https://github.com/priyanshujain/margin-calendar.git
synced 2026-10-02 19:17:04 +00:00
fix bug on hour fold update
This commit is contained in:
1 parent
f7d3505ab2
commit
af8e66e84d
13 files changed
+243
-65
No files matched your search
@@ -9,14 +9,13 @@ import { create } from "zustand";
|
||||
import {
|
||||
DEFAULT_BOUNDS,
|
||||
addFold,
|
||||
foldAt,
|
||||
normalizeFolds,
|
||||
unfoldStrip,
|
||||
type Bounds,
|
||||
type FitLayout,
|
||||
type Fold,
|
||||
} from "../grid/fit";
|
||||
import { loadFolds, saveFolds } from "../grid/folds";
|
||||
import { bandAt, type Placed } from "./GridModel";
|
||||
import { bandAt, busyHours, type Placed } from "./GridModel";
|
||||
|
||||
export type DragMode = "create" | "move" | "resize-start" | "resize-end";
|
||||
|
||||
@@ -82,9 +81,7 @@ export const useGrid = create<GridState>((set, get) => ({
|
||||
set({ folds });
|
||||
},
|
||||
unfold: (range) => {
|
||||
const folds = saveFolds(
|
||||
normalizeFolds(get().folds).filter((f) => f.end <= range.start || f.start >= range.end),
|
||||
);
|
||||
const folds = saveFolds(unfoldStrip(get().folds, busyHours(get().items), range));
|
||||
// An out-of-bounds band has no fold to remove, so widening the floor is what holds it open.
|
||||
const base = get().floor ?? get().layout?.bounds ?? DEFAULT_BOUNDS;
|
||||
set({
|
||||
@@ -93,7 +90,7 @@ export const useGrid = create<GridState>((set, get) => ({
|
||||
});
|
||||
},
|
||||
toggleFold: (hour) => {
|
||||
const { layout, hoverHour, items, folds } = get();
|
||||
const { layout, hoverHour, items } = get();
|
||||
if (!layout) return;
|
||||
const at = hour ?? hoverHour;
|
||||
if (at === null || at === undefined) return;
|
||||
@@ -103,11 +100,8 @@ export const useGrid = create<GridState>((set, get) => ({
|
||||
get().unfold({ start: segment.start / 60, end: segment.end / 60 });
|
||||
return;
|
||||
}
|
||||
if (foldAt(folds, h)) {
|
||||
get().unfold({ start: h, end: h + 1 });
|
||||
return;
|
||||
}
|
||||
get().fold(bandAt(items, layout.bounds, h));
|
||||
const band = bandAt(items, layout.bounds, h);
|
||||
if (band) get().fold(band);
|
||||
},
|
||||
unfoldAll: () => {
|
||||
saveFolds([]);
|
||||
|
||||
Reference in new issue
Block a user