refactor: share skills dialog opener

This commit is contained in:
Peter Steinberger
2026-04-20 22:37:50 +01:00
parent e0621bd7b9
commit b33ce7a371

View File

@@ -24,6 +24,13 @@ function safeExternalHref(raw?: string): string | null {
return resolveSafeExternalUrl(raw, window.location.href);
}
function showDialogWhenClosed(el?: Element) {
if (!(el instanceof HTMLDialogElement) || el.open) {
return;
}
el.showModal();
}
export type SkillsStatusFilter = "all" | "ready" | "needs-setup" | "disabled";
export type SkillsProps = {
@@ -290,17 +297,11 @@ function renderClawHubResults(props: SkillsProps) {
function renderClawHubDetailDialog(props: SkillsProps) {
const detail = props.clawhubDetail;
const ensureModalOpen = (el?: Element) => {
if (!(el instanceof HTMLDialogElement) || el.open) {
return;
}
el.showModal();
};
return html`
<dialog
class="md-preview-dialog"
${ref(ensureModalOpen)}
${ref(showDialogWhenClosed)}
@click=${(e: Event) => {
const dialog = e.currentTarget as HTMLDialogElement;
if (e.target === dialog) {
@@ -422,17 +423,11 @@ function renderSkillDetail(skill: SkillStatusEntry, props: SkillsProps) {
const showBundledBadge = Boolean(skill.bundled && skill.source !== "openclaw-bundled");
const missing = computeSkillMissing(skill);
const reasons = computeSkillReasons(skill);
const ensureModalOpen = (el?: Element) => {
if (!(el instanceof HTMLDialogElement) || el.open) {
return;
}
el.showModal();
};
return html`
<dialog
class="md-preview-dialog"
${ref(ensureModalOpen)}
${ref(showDialogWhenClosed)}
@click=${(e: Event) => {
const dialog = e.currentTarget as HTMLDialogElement;
if (e.target === dialog) {