Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion resources/js/components/actions/BulkActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const emit = defineEmits(['started', 'completed']);
const { prepareActions, runServerAction } = useActions();

let actions = ref([]);
let loading = ref(false);

const confirmableActions = useTemplateRef('confirmableActions');

Expand Down Expand Up @@ -49,6 +50,8 @@ function getActions() {
return;
}

loading.value = true;

let params = {
selections: toRaw(props.selections),
};
Expand All @@ -59,7 +62,10 @@ function getActions() {

axios
.post(props.url + '/list', params)
.then(response => actions.value = response.data);
.then(response => {
actions.value = response.data;
loading.value = false;
});
}

let errors = ref({});
Expand Down Expand Up @@ -91,5 +97,6 @@ function runAction(action, values, onSuccess, onError) {
<slot
v-if="showAlways || hasSelections"
:actions="preparedActions"
:loading="loading"
/>
</template>
20 changes: 16 additions & 4 deletions resources/js/components/ui/Listing/BulkActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@
import { Motion } from 'motion-v';
import { injectListingContext } from '../Listing/Listing.vue';
import { computed, ref, watch } from 'vue';
import { Button, ButtonGroup } from '@ui';
import { Button, ButtonGroup, Icon } from '@ui';
import BulkActions from '@/components/actions/BulkActions.vue';

const { actionUrl, actionContext, selections, refresh, clearSelections } = injectListingContext();
const busy = ref(false);
const hasSelections = computed(() => selections.value.length > 0);
const visible = ref(false);
let visibleTimeout = null;

watch(hasSelections, (value) => {
clearTimeout(visibleTimeout);
if (value) {
visibleTimeout = setTimeout(() => visible.value = true, 300);
} else {
visible.value = false;
}
});

watch(busy, (busy) => Statamic.$progress.loading('action', busy));

Expand Down Expand Up @@ -40,21 +51,22 @@ function actionFailed(response) {
:context="actionContext"
@started="actionStarted"
@completed="actionCompleted"
v-slot="{ actions }"
v-slot="{ actions, loading }"
>
<Motion
v-if="hasSelections"
v-if="visible"
layout
data-floating-toolbar
class="sticky inset-x-0 bottom-1 sm:bottom-6 z-100 flex w-full max-w-[95vw] mx-auto justify-center "
:initial="{ y: 100, opacity: 0 }"
:animate="{ y: 0, opacity: 1 }"
:transition="{ duration: 0.2, delay: 0.075, ease: 'easeInOut' }"
:transition="{ duration: 0.2, ease: 'easeInOut' }"
>
<div class="space-y-3 rounded-xl border border-gray-300/60 dark:border-gray-700 p-1 bg-gray-200/55 backdrop-blur-[20px] shadow-[0_1px_16px_-2px_rgba(63,63,71,0.2)] dark:bg-gray-800 dark:shadow-[0_10px_15px_rgba(0,0,0,.5)] dark:inset-shadow-2xs dark:inset-shadow-white/10">
<ButtonGroup>
<Button
class="text-blue-500!"
:icon-append="loading ? 'loading' : null"
:text="__n(`Deselect :count item|Deselect all :count items`, selections.length)"
@click="clearSelections"
/>
Expand Down