pages_core 3.15.2 → 3.15.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/app/assets/builds/pages_core/admin-dist.js +1 -1
- data/app/assets/builds/pages_core/admin-dist.js.map +3 -3
- data/app/javascript/components/Attachments/useAttachments.ts +9 -2
- data/app/javascript/components/ImageGrid/useImageGrid.ts +21 -5
- data/app/javascript/components/PageForm.tsx +2 -6
- data/app/javascript/components/drag/useDragCollection.ts +2 -0
- data/app/javascript/types/Attachments.ts +1 -0
- data/app/javascript/types/Drag.ts +1 -0
- data/app/javascript/types/Images.ts +1 -0
- metadata +1 -1
@@ -6,10 +6,17 @@ export default function useAttachments(
|
|
6
6
|
records: Attachments.Record[]
|
7
7
|
): Attachments.State {
|
8
8
|
const [deleted, setDeleted] = useState<Attachments.Record[]>([]);
|
9
|
+
const collection = useDragCollection(records);
|
10
|
+
|
11
|
+
const update = (records: Attachments.Record[]) => {
|
12
|
+
collection.dispatch({ type: "reinitialize", payload: records });
|
13
|
+
setDeleted([]);
|
14
|
+
};
|
9
15
|
|
10
16
|
return {
|
11
|
-
collection:
|
17
|
+
collection: collection,
|
12
18
|
deleted: deleted,
|
13
|
-
setDeleted: setDeleted
|
19
|
+
setDeleted: setDeleted,
|
20
|
+
update: update
|
14
21
|
};
|
15
22
|
}
|
@@ -4,23 +4,39 @@ import * as Images from "../../types/Images";
|
|
4
4
|
|
5
5
|
import { useDragCollection } from "../drag";
|
6
6
|
|
7
|
-
|
8
|
-
records: Images.Record[],
|
9
|
-
enablePrimary = false
|
10
|
-
): Images.GridState {
|
7
|
+
function filterRecords(records: Images.Record[], enablePrimary = false) {
|
11
8
|
const primaryRecords = enablePrimary
|
12
9
|
? records.filter((r) => r.primary).slice(0, 1)
|
13
10
|
: [];
|
14
11
|
const imageRecords = records.filter((r) => primaryRecords.indexOf(r) === -1);
|
12
|
+
return [primaryRecords, imageRecords];
|
13
|
+
}
|
14
|
+
|
15
|
+
export default function useImageGrid(
|
16
|
+
records: Images.Record[],
|
17
|
+
enablePrimary = false
|
18
|
+
): Images.GridState {
|
19
|
+
const [primaryRecords, imageRecords] = filterRecords(records, enablePrimary);
|
15
20
|
|
16
21
|
const primary = useDragCollection(primaryRecords);
|
17
22
|
const images = useDragCollection(imageRecords);
|
18
23
|
const [deleted, setDeleted] = useState<Images.Record[]>([]);
|
19
24
|
|
25
|
+
const update = (records: Images.Record[]) => {
|
26
|
+
const [primaryRecords, imageRecords] = filterRecords(
|
27
|
+
records,
|
28
|
+
enablePrimary
|
29
|
+
);
|
30
|
+
primary.dispatch({ type: "reinitialize", payload: primaryRecords });
|
31
|
+
images.dispatch({ type: "reinitialize", payload: imageRecords });
|
32
|
+
setDeleted([]);
|
33
|
+
};
|
34
|
+
|
20
35
|
return {
|
21
36
|
primary: primary,
|
22
37
|
images: images,
|
23
38
|
deleted: deleted,
|
24
|
-
setDeleted: setDeleted
|
39
|
+
setDeleted: setDeleted,
|
40
|
+
update: update
|
25
41
|
};
|
26
42
|
}
|
@@ -82,11 +82,6 @@ export default function PageForm(props: Props) {
|
|
82
82
|
});
|
83
83
|
};
|
84
84
|
|
85
|
-
const clearDeletedObjects = () => {
|
86
|
-
filesState.setDeleted([]);
|
87
|
-
imagesState.setDeleted([]);
|
88
|
-
};
|
89
|
-
|
90
85
|
const handleSubmit = (evt: React.MouseEvent) => {
|
91
86
|
evt.preventDefault();
|
92
87
|
let method = postJson;
|
@@ -110,7 +105,8 @@ export default function PageForm(props: Props) {
|
|
110
105
|
if (response.errors && response.errors.length > 0) {
|
111
106
|
errorToast("A validation error prevented the page from being saved.");
|
112
107
|
} else {
|
113
|
-
|
108
|
+
filesState.update(response.page_files);
|
109
|
+
imagesState.update(response.page_images);
|
114
110
|
noticeToast("Your changes were saved");
|
115
111
|
}
|
116
112
|
})
|
@@ -66,6 +66,8 @@ function dragCollectionReducer<T = Drag.DraggableRecord>(
|
|
66
66
|
return { ...d, rect: getPosition(d) };
|
67
67
|
});
|
68
68
|
});
|
69
|
+
case "reinitialize":
|
70
|
+
return action.payload.map((r) => createDraggable(r));
|
69
71
|
case "remove":
|
70
72
|
return state.filter(
|
71
73
|
(d: Drag.Draggable<T>) => d.handle !== action.payload.handle
|
@@ -15,6 +15,7 @@ export type CollectionAction<T = DraggableRecord> =
|
|
15
15
|
payload: Item<T>[];
|
16
16
|
}
|
17
17
|
| { type: "update"; payload: Item<T> }
|
18
|
+
| { type: "reinitialize"; payload: Array<T> }
|
18
19
|
| { type: "remove"; payload: Draggable<T> }
|
19
20
|
| { type: "updatePositions"; payload?: Draggable<T> };
|
20
21
|
|