22import { ref , computed , useTemplateRef , watch } from ' vue' ;
33import useActions from ' ./Actions.js' ;
44import ConfirmableAction from ' ./ConfirmableAction.vue' ;
5+ import useSkeletonDelay from ' @/composables/skeleton-delay.js' ;
56import axios from ' axios' ;
67
78const props = defineProps ({
@@ -19,11 +20,17 @@ const { prepareActions, runServerAction } = useActions();
1920const confirmableActions = useTemplateRef (' confirmableActions' );
2021const actions = ref (props .actions );
2122const actionsLoaded = ref (props .actions !== undefined );
23+ const loading = ref (false );
24+ const shouldShowSkeleton = useSkeletonDelay (loading);
25+ let loadActionsRequest = null ;
2226
2327watch (
24- () => props .actions ,
25- () => actions .value = props .actions ,
26- { deep: true }
28+ () => props .actions ,
29+ () => {
30+ actions .value = props .actions ;
31+ actionsLoaded .value = props .actions !== undefined ;
32+ },
33+ { deep: true }
2734);
2835
2936let preparedActions = computed (() => {
@@ -52,7 +59,11 @@ function runAction(action, values, onSuccess, onError) {
5259
5360function loadActions () {
5461 if (actionsLoaded .value ) {
55- return ;
62+ return Promise .resolve (actions .value );
63+ }
64+
65+ if (loading .value ) {
66+ return loadActionsRequest;
5667 }
5768
5869 let params = {
@@ -63,9 +74,22 @@ function loadActions() {
6374 params .context = props .context ;
6475 }
6576
66- axios . post ( props . url + ' /list ' , params). then (( response ) => ( actions . value = response . data )) ;
77+ loading . value = true ;
6778
68- actionsLoaded .value = true ;
79+ loadActionsRequest = axios
80+ .post (props .url + ' /list' , params)
81+ .then ((response ) => {
82+ actions .value = response .data ;
83+ actionsLoaded .value = true ;
84+
85+ return response .data ;
86+ })
87+ .finally (() => {
88+ loading .value = false ;
89+ loadActionsRequest = null ;
90+ });
91+
92+ return loadActionsRequest;
6993}
7094
7195defineExpose ({
@@ -84,5 +108,10 @@ defineExpose({
84108 :is-dirty =" isDirty"
85109 @confirmed =" runAction"
86110 />
87- <slot :actions =" preparedActions" :load-actions =" loadActions" />
111+ <slot
112+ :actions =" preparedActions"
113+ :load-actions =" loadActions"
114+ :loading =" loading"
115+ :should-show-skeleton =" shouldShowSkeleton"
116+ />
88117</template >
0 commit comments