Skip to content

Commit c4ba759

Browse files
committed
Remove reliance on Listing mixin. It was the last one using it.
1 parent 6a5d31e commit c4ba759

1 file changed

Lines changed: 39 additions & 11 deletions

File tree

resources/js/components/collections/Listing.vue

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@
146146
</template>
147147

148148
<script>
149-
import Listing from '../Listing.vue';
150149
import {
151150
CardPanel,
152151
StatusIndicator,
@@ -160,8 +159,6 @@ import {
160159
import ItemActions from '@statamic/components/actions/ItemActions.vue';
161160
162161
export default {
163-
mixins: [Listing],
164-
165162
components: {
166163
CardPanel,
167164
StatusIndicator,
@@ -189,6 +186,7 @@ export default {
189186
columns: this.initialColumns,
190187
requestUrl: cp_url(`collections`),
191188
mode: this.$preferences.get('collections.listing_mode', 'grid'),
189+
source: null,
192190
};
193191
},
194192
@@ -200,15 +198,45 @@ export default {
200198
201199
methods: {
202200
request() {
203-
// If we have initial data, we don't need to perform a request.
204-
// Subsequent requests, like after performing actions, we do want to perform a request.
205-
if (!this.initializedRequest) {
206-
this.loading = false;
207-
this.initializedRequest = true;
208-
return;
209-
}
201+
if (this.source) this.source.abort();
202+
this.source = new AbortController();
203+
204+
this.$axios
205+
.get(this.requestUrl, {
206+
params: this.parameters,
207+
signal: this.source.signal,
208+
})
209+
.then((response) => {
210+
this.columns = response.data.meta.columns;
211+
this.items = Object.values(response.data.data);
212+
this.meta = response.data.meta;
213+
this.loading = false;
214+
})
215+
.catch((e) => {
216+
if (this.$axios.isCancel(e)) return;
217+
this.loading = false;
218+
this.initializing = false;
219+
if (e.request && !e.response) return;
220+
this.$toast.error(e.response ? e.response.data.message : __('Something went wrong'), {
221+
duration: null,
222+
});
223+
});
224+
},
225+
226+
actionStarted() {
227+
this.loading = true;
228+
},
229+
230+
actionCompleted(successful, response) {
231+
// Intentionally not completing the loading state here since
232+
// the listing will refresh and immediately restart it.
233+
// this.loading = false;
234+
235+
successful
236+
? this.$toast.success(response.message || __('Action completed'))
237+
: this.$toast.error(response.message || __('Action failed'));
210238
211-
Listing.methods.request.call(this);
239+
this.request();
212240
},
213241
},
214242
};

0 commit comments

Comments
 (0)