Skip to content

Commit 83e2785

Browse files
committed
feat: use the <umb-imaging-thumbnail> element in media collections
1 parent 6fb7e10 commit 83e2785

File tree

2 files changed

+7
-42
lines changed

2 files changed

+7
-42
lines changed

src/packages/media/media/collection/media-collection.context.ts

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,20 @@
11
import type { UmbMediaCollectionFilterModel, UmbMediaCollectionItemModel } from './types.js';
22
import { UMB_MEDIA_GRID_COLLECTION_VIEW_ALIAS } from './views/index.js';
3-
import { UmbImagingRepository } from '@umbraco-cms/backoffice/imaging';
4-
import { UmbArrayState } from '@umbraco-cms/backoffice/observable-api';
53
import { UmbDefaultCollectionContext } from '@umbraco-cms/backoffice/collection';
64
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
75

86
export class UmbMediaCollectionContext extends UmbDefaultCollectionContext<
97
UmbMediaCollectionItemModel,
108
UmbMediaCollectionFilterModel
119
> {
12-
#imagingRepository: UmbImagingRepository;
13-
14-
#thumbnailItems = new UmbArrayState<UmbMediaCollectionItemModel>([], (x) => x.unique);
15-
public readonly thumbnailItems = this.#thumbnailItems.asObservable();
10+
/**
11+
* The thumbnail items that are currently displayed in the collection.
12+
* @deprecated Use the `<umb-imaging-thumbnail>` element instead.
13+
*/
14+
public readonly thumbnailItems = this.items;
1615

1716
constructor(host: UmbControllerHost) {
1817
super(host, UMB_MEDIA_GRID_COLLECTION_VIEW_ALIAS);
19-
this.#imagingRepository = new UmbImagingRepository(host);
20-
21-
this.observe(this.items, async (items) => {
22-
if (!items?.length) return;
23-
24-
const { data } = await this.#imagingRepository.requestThumbnailUrls(
25-
items.map((m) => m.unique),
26-
400,
27-
400,
28-
);
29-
30-
this.#thumbnailItems.setValue(
31-
items.map((item) => {
32-
const thumbnail = data?.find((m) => m.unique === item.unique)?.url;
33-
return { ...item, url: thumbnail };
34-
}),
35-
);
36-
});
3718
}
3819
}
3920

src/packages/media/media/collection/views/grid/media-grid-collection-view.element.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class UmbMediaGridCollectionViewElement extends UmbLitElement {
5252

5353
this.observe(this.#collectionContext.loading, (loading) => (this._loading = loading), '_observeLoading');
5454

55-
this.observe(this.#collectionContext.thumbnailItems, (items) => (this._items = items), '_observeItems');
55+
this.observe(this.#collectionContext.items, (items) => (this._items = items), '_observeItems');
5656

5757
this.observe(
5858
this.#collectionContext.selection.selection,
@@ -127,13 +127,7 @@ export class UmbMediaGridCollectionViewElement extends UmbLitElement {
127127
@selected=${() => this.#onSelect(item)}
128128
@deselected=${() => this.#onDeselect(item)}
129129
class="media-item">
130-
${when(
131-
item.url,
132-
() => html`<img src=${item.url!} alt=${item.name} draggable="false" />`,
133-
() => html`<umb-icon name=${item.icon}></umb-icon>`,
134-
)}
135-
<!-- TODO: [LK] I'd like to indicate a busy state when bulk actions are triggered. -->
136-
<!-- <div class="container"><uui-loader></uui-loader></div> -->
130+
<umb-imaging-thumbnail unique=${item.unique} alt=${item.name} icon=${item.icon}></umb-imaging-thumbnail>
137131
</uui-card-media>
138132
`;
139133
}
@@ -158,16 +152,6 @@ export class UmbMediaGridCollectionViewElement extends UmbLitElement {
158152
grid-auto-rows: 200px;
159153
gap: var(--uui-size-space-5);
160154
}
161-
162-
img {
163-
background-image: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" fill-opacity=".1"><path d="M50 0h50v50H50zM0 50h50v50H0z"/></svg>');
164-
background-size: 10px 10px;
165-
background-repeat: repeat;
166-
}
167-
168-
umb-icon {
169-
font-size: var(--uui-size-8);
170-
}
171155
`,
172156
];
173157
}

0 commit comments

Comments
 (0)