-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Make collection public (#2208)
- Loading branch information
Showing
26 changed files
with
1,109 additions
and
442 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { msg } from "@lit/localize"; | ||
import type { ReactiveController, ReactiveControllerHost } from "lit"; | ||
|
||
export type CopiedEventDetail = string; | ||
|
||
export interface CopiedEventMap { | ||
"btrix-copied": CustomEvent<CopiedEventDetail>; | ||
} | ||
|
||
/** | ||
* Copy to clipboard | ||
* | ||
* @fires btrix-copied | ||
*/ | ||
export class ClipboardController implements ReactiveController { | ||
static readonly text = { | ||
copy: msg("Copy"), | ||
copied: msg("Copied"), | ||
}; | ||
|
||
static copyToClipboard(value: string) { | ||
void navigator.clipboard.writeText(value); | ||
} | ||
|
||
private readonly host: ReactiveControllerHost & EventTarget; | ||
|
||
private timeoutId?: number; | ||
|
||
isCopied = false; | ||
|
||
constructor(host: ClipboardController["host"]) { | ||
this.host = host; | ||
host.addController(this); | ||
} | ||
|
||
hostConnected() {} | ||
|
||
hostDisconnected() { | ||
window.clearTimeout(this.timeoutId); | ||
this.timeoutId = undefined; | ||
} | ||
|
||
async copy(value: string) { | ||
ClipboardController.copyToClipboard(value); | ||
|
||
this.isCopied = true; | ||
|
||
this.timeoutId = window.setTimeout(() => { | ||
this.isCopied = false; | ||
this.host.requestUpdate(); | ||
}, 3000); | ||
|
||
this.host.requestUpdate(); | ||
|
||
await this.host.updateComplete; | ||
|
||
this.host.dispatchEvent( | ||
new CustomEvent<CopiedEventDetail>("btrix-copied", { detail: value }), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
frontend/src/features/collections/select-collection-access.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { localized, msg } from "@lit/localize"; | ||
import type { SlIcon, SlSelectEvent } from "@shoelace-style/shoelace"; | ||
import { html } from "lit"; | ||
import { customElement, property } from "lit/decorators.js"; | ||
|
||
import { BtrixElement } from "@/classes/BtrixElement"; | ||
import { CollectionAccess } from "@/types/collection"; | ||
|
||
@localized() | ||
@customElement("btrix-select-collection-access") | ||
export class SelectCollectionAccess extends BtrixElement { | ||
static readonly Options: Record< | ||
CollectionAccess, | ||
{ label: string; icon: NonNullable<SlIcon["name"]>; detail: string } | ||
> = { | ||
[CollectionAccess.Private]: { | ||
label: msg("Private"), | ||
icon: "lock", | ||
detail: msg("Only org members can view"), | ||
}, | ||
[CollectionAccess.Unlisted]: { | ||
label: msg("Unlisted"), | ||
icon: "link-45deg", | ||
detail: msg("Only people with the link can view"), | ||
}, | ||
|
||
[CollectionAccess.Public]: { | ||
label: msg("Public"), | ||
icon: "globe2", | ||
detail: msg("Anyone can view on the org's public profile"), | ||
}, | ||
}; | ||
|
||
@property({ type: String }) | ||
value: CollectionAccess = CollectionAccess.Private; | ||
|
||
@property({ type: Boolean }) | ||
readOnly = false; | ||
|
||
render() { | ||
const selected = SelectCollectionAccess.Options[this.value]; | ||
|
||
if (this.readOnly) { | ||
return html` | ||
<sl-input label=${msg("Visibility")} readonly value=${selected.label}> | ||
<sl-icon slot="prefix" name=${selected.icon}></sl-icon> | ||
<span slot="suffix">${selected.detail}</span> | ||
</sl-input> | ||
`; | ||
} | ||
|
||
return html` | ||
<div> | ||
<div class="form-label" id="collectionAccessLabel"> | ||
${msg("Visibility")} | ||
</div> | ||
<sl-dropdown | ||
class="block w-full" | ||
aria-labelledby="collectionAccessLabel" | ||
hoist | ||
sync="width" | ||
@sl-select=${(e: SlSelectEvent) => { | ||
const { value } = e.detail.item; | ||
this.value = value as CollectionAccess; | ||
}} | ||
> | ||
<sl-button slot="trigger" size="large" class="button-card" caret> | ||
<sl-icon | ||
slot="prefix" | ||
name=${selected.icon} | ||
class="size-6" | ||
></sl-icon> | ||
<span>${selected.label}</span> | ||
<div class="font-normal text-neutral-500">${selected.detail}</div> | ||
</sl-button> | ||
<sl-menu> | ||
${Object.entries(SelectCollectionAccess.Options).map( | ||
([value, { label, icon, detail }]) => html` | ||
<sl-menu-item | ||
value=${value} | ||
type="checkbox" | ||
?checked=${label === selected.label} | ||
> | ||
<sl-icon slot="prefix" name=${icon}></sl-icon> | ||
<span class="font-medium">${label}</span> | ||
<span slot="suffix" class="text-neutral-500">${detail}</span> | ||
</sl-menu-item> | ||
`, | ||
)} | ||
</sl-menu> | ||
</sl-dropdown> | ||
</div> | ||
`; | ||
} | ||
} |
Oops, something went wrong.