Skip to content

Commit

Permalink
change collection metadata dialog into just collection create dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
emma-sg committed Jan 30, 2025
1 parent bcd66e3 commit ffb69a4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { localized, msg, str } from "@lit/localize";
import type { SlInput, SlSelectEvent } from "@shoelace-style/shoelace";
import { serialize } from "@shoelace-style/shoelace/dist/utilities/form.js";
import { html, nothing } from "lit";
import { html } from "lit";
import {
customElement,
property,
Expand All @@ -28,12 +28,9 @@ export type CollectionSavedEvent = CustomEvent<{
/**
* @fires btrix-collection-saved CollectionSavedEvent Fires
*/
@customElement("btrix-collection-metadata-dialog")
@customElement("btrix-collection-create-dialog")
@localized()
export class CollectionMetadataDialog extends BtrixElement {
@property({ type: Object })
collection?: Collection;

export class CollectionCreateDialog extends BtrixElement {
@property({ type: Boolean })
open = false;

Expand Down Expand Up @@ -63,9 +60,7 @@ export class CollectionMetadataDialog extends BtrixElement {

render() {
return html`<btrix-dialog
label=${this.collection
? msg("Edit Metadata")
: msg("Create a New Collection")}
label=${msg("Create a New Collection")}
?open=${this.open}
@sl-show=${() => (this.isDialogVisible = true)}
@sl-after-hide=${() => (this.isDialogVisible = false)}
Expand Down Expand Up @@ -98,9 +93,7 @@ export class CollectionMetadataDialog extends BtrixElement {
);
form.requestSubmit(submitInput);
}}
>${this.collection
? msg("Save")
: msg("Create Collection")}</sl-button
>${msg("Create Collection")}</sl-button
>
</div>
</btrix-dialog>`;
Expand All @@ -113,21 +106,18 @@ export class CollectionMetadataDialog extends BtrixElement {
class="with-max-help-text"
name="name"
label=${msg("Name")}
value=${this.collection?.name || ""}
placeholder=${msg("My Collection")}
autocomplete="off"
required
help-text=${this.validateNameMax.helpText}
@sl-input=${this.validateNameMax.validate}
>
</sl-input>
<sl-textarea
<sl-input
class="with-max-help-text"
name="caption"
value=${this.collection?.caption || ""}
placeholder=${msg("Summarize the collection's content")}
autocomplete="off"
rows="2"
help-text=${this.validateCaptionMax.helpText}
@sl-input=${this.validateCaptionMax.validate}
>
Expand All @@ -138,32 +128,27 @@ export class CollectionMetadataDialog extends BtrixElement {
${msg(
"Write a short description that summarizes this collection. If the collection is shareable, this will appear next to the collection name.",
)}
${this.collection
? nothing
: msg(
html`You can add a longer description in the “About”
section after creating the collection.`,
)}
${msg(
html`You can add a longer description in the “About” section
after creating the collection.`,
)}
</span>
<sl-icon
name="info-circle"
style="vertical-align: -.175em"
></sl-icon>
</sl-tooltip>
</span>
</sl-textarea>
${when(
!this.collection,
() => html`
<sl-divider></sl-divider>
<btrix-select-collection-access
@sl-select=${(e: SlSelectEvent) =>
(this.showPublicWarning =
(e.detail.item.value as CollectionAccess) ===
CollectionAccess.Public)}
></btrix-select-collection-access>
`,
)}
</sl-input>
<sl-divider></sl-divider>
<btrix-select-collection-access
@sl-select=${(e: SlSelectEvent) =>
(this.showPublicWarning =
(e.detail.item.value as CollectionAccess) ===
CollectionAccess.Public)}
></btrix-select-collection-access>
${when(
this.showPublicWarning && this.org,
(org) => html`
Expand Down Expand Up @@ -218,18 +203,11 @@ export class CollectionMetadataDialog extends BtrixElement {
const body = JSON.stringify({
name,
caption,
access:
this.selectCollectionAccess?.value ||
this.collection?.access ||
CollectionAccess.Private,
access: this.selectCollectionAccess?.value || CollectionAccess.Private,
defaultThumbnailName: DEFAULT_THUMBNAIL,
});
let path = `/orgs/${this.orgId}/collections`;
let method = "POST";
if (this.collection) {
path = `/orgs/${this.orgId}/collections/${this.collection.id}`;
method = "PATCH";
}
const path = `/orgs/${this.orgId}/collections`;
const method = "POST";
const data = await this.api.fetch<Collection>(path, {
method,
body,
Expand All @@ -238,14 +216,12 @@ export class CollectionMetadataDialog extends BtrixElement {
this.dispatchEvent(
new CustomEvent("btrix-collection-saved", {
detail: {
id: this.collection?.id || data.id,
id: data.id,
},
}) as CollectionSavedEvent,
);
this.notify.toast({
message: this.collection
? msg(str`"${data.name || name}" metadata updated`)
: msg(str`Created "${data.name || name}" collection`),
message: msg(str`Created "${data.name || name}" collection`),
variant: "success",
icon: "check2-circle",
id: "collection-metadata-status",
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/org/collections-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class CollectionsList extends BtrixElement {
)}
</div>
</btrix-dialog>
<btrix-collection-metadata-dialog
<btrix-collection-create-dialog
.collection=${
this.openDialogName === "create" ? undefined : this.selectedCollection
}
Expand All @@ -243,7 +243,7 @@ export class CollectionsList extends BtrixElement {
}
}}
>
</btrix-collection-metadata-dialog>
</btrix-collection-create-dialog>
<btrix-collection-edit-dialog
.collection=${this.selectedCollection}
?open=${this.openDialogName === "edit"}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/org/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ export class Org extends BtrixElement {
@sl-hide=${() => (this.openDialogName = undefined)}
>
</btrix-new-browser-profile-dialog>
<btrix-collection-metadata-dialog
<btrix-collection-create-dialog
?open=${this.openDialogName === "collection"}
@sl-hide=${() => (this.openDialogName = undefined)}
@btrix-collection-saved=${(e: CollectionSavedEvent) => {
Expand All @@ -454,7 +454,7 @@ export class Org extends BtrixElement {
);
}}
>
</btrix-collection-metadata-dialog>
</btrix-collection-create-dialog>
</div>
`;
}
Expand Down

0 comments on commit ffb69a4

Please sign in to comment.