generated from filamentphp/plugin-skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathflowforge.js
More file actions
70 lines (56 loc) · 2.42 KB
/
flowforge.js
File metadata and controls
70 lines (56 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
export default function flowforge({state}) {
return {
state,
isLoading: {},
fullyLoaded: {},
areFiltersOpen: false,
init() {
this.$wire.$on('kanban-items-loaded', (event) => {
const { columnId, isFullyLoaded } = event;
if (isFullyLoaded) {
this.fullyLoaded[columnId] = true;
}
});
},
handleSortableEnd(event) {
const newOrder = event.to.sortable.toArray();
const cardId = event.item.getAttribute('x-sortable-item');
const targetColumn = event.to.getAttribute('data-column-id');
const cardElement = event.item;
this.setCardState(cardElement, true);
const cardIndex = newOrder.indexOf(cardId);
const afterCardId = cardIndex > 0 ? newOrder[cardIndex - 1] : null;
const beforeCardId = cardIndex < newOrder.length - 1 ? newOrder[cardIndex + 1] : null;
this.$wire.moveCard(cardId, targetColumn, afterCardId, beforeCardId)
.then(() => this.setCardState(cardElement, false))
.catch(() => this.setCardState(cardElement, false));
},
setCardState(cardElement, disabled) {
cardElement.style.opacity = disabled ? '0.7' : '';
cardElement.style.pointerEvents = disabled ? 'none' : '';
},
isLoadingColumn(columnId) {
return this.isLoading[columnId] || false;
},
isColumnFullyLoaded(columnId) {
return this.fullyLoaded[columnId] || false;
},
handleSmoothScroll(columnId) {
if (this.isLoadingColumn(columnId) || this.isColumnFullyLoaded(columnId)) {
return;
}
this.isLoading[columnId] = true;
this.$wire.loadMoreItems(columnId)
.then(() => setTimeout(() => this.isLoading[columnId] = false, 100))
.catch(() => this.isLoading[columnId] = false);
},
handleColumnScroll(event, columnId) {
if (this.isColumnFullyLoaded(columnId)) return;
const { scrollTop, scrollHeight, clientHeight } = event.target;
const scrollPercentage = (scrollTop + clientHeight) / scrollHeight;
if (scrollPercentage >= 0.8 && !this.isLoadingColumn(columnId)) {
this.handleSmoothScroll(columnId);
}
},
}
}