Skip to content

Commit 4421ee0

Browse files
authored
Merge pull request #276 from connorabbas/admin-role-dev
Pull master
2 parents 7fad459 + df7348d commit 4421ee0

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

resources/js/composables/usePaginatedData.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export function usePaginatedData(
116116
});
117117
}
118118

119-
function paginate(event: PageState | DataTablePageEvent): void {
119+
function paginate(event: PageState | DataTablePageEvent): Promise<Page<PageProps>> {
120120
if (event.rows !== pagination.value.rows) {
121121
pagination.value.page = 1;
122122
} else {
@@ -125,18 +125,23 @@ export function usePaginatedData(
125125

126126
pagination.value.rows = event.rows;
127127

128-
fetchData({
128+
return fetchData({
129129
onFinish: () => {
130130
scrollToTop();
131131
},
132132
});
133133
}
134134

135-
function filter(): void {
135+
function filter(options: InertiaRouterFetchCallbacks = {}): Promise<Page<PageProps>> {
136+
const { onFinish: onFinishCallback, onSuccess, onError } = options;
137+
136138
pagination.value.page = 1;
137-
fetchData({
139+
return fetchData({
140+
onSuccess,
141+
onError,
138142
onFinish: () => {
139143
scrollToTop();
144+
onFinishCallback?.();
140145
},
141146
});
142147
}
@@ -156,6 +161,8 @@ export function usePaginatedData(
156161
const { onSuccess, onError, onFinish } = options;
157162

158163
return new Promise((resolve, reject) => {
164+
processing.value = true;
165+
159166
router.visit(window.location.pathname, {
160167
method: 'get',
161168
preserveUrl: false,
@@ -171,6 +178,7 @@ export function usePaginatedData(
171178
reject(errors);
172179
},
173180
onFinish() {
181+
processing.value = false;
174182
onFinish?.();
175183
},
176184
});

0 commit comments

Comments
 (0)