Skip to content

Commit

Permalink
upload to correct folder when dropping file
Browse files Browse the repository at this point in the history
  • Loading branch information
loivsen authored and iOvergaard committed Jun 10, 2024
1 parent f5b321f commit 3b65ead
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/packages/media/media/collection/media-collection.element.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { UMB_MEDIA_WORKSPACE_CONTEXT } from '../workspace/media-workspace.context-token.js';
import type { UmbMediaCollectionContext } from './media-collection.context.js';
import { UMB_MEDIA_COLLECTION_CONTEXT } from './media-collection.context-token.js';
import { customElement, html, state, when } from '@umbraco-cms/backoffice/external/lit';
Expand All @@ -13,11 +14,19 @@ export class UmbMediaCollectionElement extends UmbCollectionDefaultElement {
@state()
private _progress = -1;

@state()
private _unique: string | null = null;

constructor() {
super();
this.consumeContext(UMB_MEDIA_COLLECTION_CONTEXT, (instance) => {
this.#mediaCollection = instance;
});
this.consumeContext(UMB_MEDIA_WORKSPACE_CONTEXT, (instance) => {
this.observe(instance.unique, (unique) => {
this._unique = unique ?? null;
});
});
}

#onChange() {
Expand All @@ -33,7 +42,10 @@ export class UmbMediaCollectionElement extends UmbCollectionDefaultElement {
return html`
<umb-media-collection-toolbar slot="header"></umb-media-collection-toolbar>
${when(this._progress >= 0, () => html`<uui-loader-bar progress=${this._progress}></uui-loader-bar>`)}
<umb-dropzone @change=${this.#onChange} @progress=${this.#onProgress}></umb-dropzone>
<umb-dropzone
.parentUnique=${this._unique}
@change=${this.#onChange}
@progress=${this.#onProgress}></umb-dropzone>
`;
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/packages/media/media/dropzone/dropzone-manager.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,15 @@ export class UmbDropzoneManager extends UmbControllerBase {
fileExtensions: Array<string>,
parentUnique: string | null,
): Promise<Array<UmbUploadableExtensionModel>> {
// Getting all media types allowed in our current position based on parent unique.
const { data: allAllowedMediaTypes } = await this.#mediaTypeStructure.requestAllowedChildrenOf(parentUnique);
let parentMediaType: string | null = null;
if (parentUnique) {
const { data } = await this.#mediaDetailRepository.requestByUnique(parentUnique);
parentMediaType = data?.mediaType.unique ?? null;
}

// Getting all media types allowed in our current position based on parent's media type.

const { data: allAllowedMediaTypes } = await this.#mediaTypeStructure.requestAllowedChildrenOf(parentMediaType);
if (!allAllowedMediaTypes?.items.length) return [];

const allowedByParent = allAllowedMediaTypes.items;
Expand Down

0 comments on commit 3b65ead

Please sign in to comment.