Adds loading state on the context

This commit is contained in:
leekelleher
2024-04-30 16:12:04 +01:00
parent e0becf34c6
commit 7151350066
3 changed files with 11 additions and 0 deletions

View File

@@ -31,6 +31,9 @@ export class UmbDefaultCollectionContext<
#manifest?: ManifestCollection;
#repository?: UmbCollectionRepository;
#loading = new UmbObjectState<boolean>(false);
public readonly loading = this.#loading.asObservable();
#items = new UmbArrayState<CollectionItemType>([], (x) => x);
public readonly items = this.#items.asObservable();
@@ -176,6 +179,8 @@ export class UmbDefaultCollectionContext<
if (!this.#repository) throw new Error(`Missing repository for ${this.#manifest}`);
this.#loading.setValue(true);
const filter = this.#filter.getValue();
const { data } = await this.#repository.requestCollection(filter);
@@ -184,6 +189,8 @@ export class UmbDefaultCollectionContext<
this.#totalItems.setValue(data.total);
this.pagination.setTotalItems(data.total);
}
this.#loading.setValue(false);
}
/**

View File

@@ -39,6 +39,8 @@ export class UmbDocumentGridCollectionViewElement extends UmbLitElement {
#observeCollectionContext() {
if (!this.#collectionContext) return;
this.observe(this.#collectionContext.loading, (loading) => (this._loading = loading), '_observeLoading');
this.observe(
this.#collectionContext.userDefinedProperties,
(userDefinedProperties) => {

View File

@@ -75,6 +75,8 @@ export class UmbDocumentTableCollectionViewElement extends UmbLitElement {
#observeCollectionContext() {
if (!this.#collectionContext) return;
this.observe(this.#collectionContext.loading, (loading) => (this._loading = loading), '_observeLoading');
this.observe(
this.#collectionContext.userDefinedProperties,
(userDefinedProperties) => {