Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Move generator sharing actions into context

Bitti1dc922383f4e
diff --git a/src/components/GeneratorSharing.tsx b/src/components/GeneratorSharing.tsx
index 2349701..992cd3d 100644
--- a/src/components/GeneratorSharing.tsx
+++ b/src/components/GeneratorSharing.tsx
@@ -1,12 +1,14 @@
-import { useEffect, useRef, useState } from "react";
-import { Checkbox, ContentDialog, InfoBar, SettingsCard } from "./ui";
-import { Video20 } from "./ui/icons";
+import { useEffect, useRef, useState, type ReactNode } from "react";
+import { Checkbox, ContentDialog, InfoBar } from "./ui";
import { inTauri } from "../lib/nativeShell";
import { importGeneratorSlop, portableGenerator, serializeGeneratorSlop } from "../lib/slop";
import { openSlopFile, readBrowserSlopFile, saveSlopFile } from "../lib/slopFiles";
import type { GeneratorTemplate } from "../lib/settings";
-export function GeneratorSharing({ templates }: { templates: GeneratorTemplate[] }) {
+export function GeneratorSharing({ templates, children }: {
+ templates: GeneratorTemplate[];
+ children?: (actions: { importButton: ReactNode; exportButton: ReactNode }) => ReactNode;
+}) {
const [choosing, setChoosing] = useState(false);
const [selected, setSelected] = useState<string[]>([]);
const [busy, setBusy] = useState(false);
@@ -47,13 +49,12 @@ export function GeneratorSharing({ templates }: { templates: GeneratorTemplate[]
}
} catch (reason) { fail(reason); } finally { finish(); }
};
- return <>
- <SettingsCard icon={<Video20 />} header="Share generator templates" description="Share download URLs and generator settings in a .slop file.">
- <button type="button" className="secondary-button" disabled={busy} onClick={() => void importFile()}>Import</button>
- <button type="button" className="secondary-button" disabled={busy} onClick={() => {
+ const importButton = <button type="button" className="secondary-button" disabled={busy} onClick={() => void importFile()}>Import</button>;
+ const exportButton = <button type="button" className="secondary-button" disabled={busy} onClick={() => {
setError(null); setMessage(null); setSelected(choices.filter((choice) => !choice.reason).slice(0, 100).map(({ template }) => template.id)); setChoosing(true);
- }}>Export</button>
- </SettingsCard>
+ }}>Export</button>;
+ return <>
+ {children ? children({ importButton, exportButton }) : <>{importButton}{exportButton}</>}
<input ref={input} type="file" accept=".slop,application/json" hidden aria-label="Import .slop file" disabled={busy} onChange={(event) => {
const file = event.target.files?.[0]; event.target.value = "";
if (!file || !begin()) return;
diff --git a/src/components/SettingsView.tsx b/src/components/SettingsView.tsx
index b2ed816..886528d 100644
--- a/src/components/SettingsView.tsx
+++ b/src/components/SettingsView.tsx
@@ -518,10 +518,11 @@ export function SettingsView({ onClose, updates, initialTab = "engine", titleBar
};
const generatorEditor = editingTemplate && <>
- <div className="settings-page__actions">
+ <GeneratorSharing key={`sharing:${selectedTemplate.id}`} templates={[selectedTemplate]}>{({ exportButton }) => <div className="settings-page__actions">
{templateNeedsDownload(selectedTemplate) && <button type="button" className="primary-button" disabled={!desktop || downloadState?.active} onClick={() => void downloadTemplateWeights(selectedTemplate.id)}><Download16 /> Download weights</button>}
<button type="button" className="secondary-button" disabled={Boolean(downloading)} onClick={clearAll}><Reset16 /> Clear generator paths</button>
- </div>
+ <div className="settings-page__actions-end">{exportButton}</div>
+ </div>}</GeneratorSharing>
{downloadStatus}
<InfoBar severity={engineSeverity(status, desktop)} title={engineHeadline(status, desktop)} message={<>
{engineDetail(status, desktop, missing.length)}
@@ -576,12 +577,12 @@ export function SettingsView({ onClose, updates, initialTab = "engine", titleBar
const generatorList = <>
{downloadStatus}
- <GeneratorSharing templates={templateSettings.templates} />
<ReferenceIconSetting templates={templateSettings} />
{generatorSections.filter((section) => section.id === "generators" || section.templates.length > 0).map((section) => <SettingsGroup key={section.id} heading={section.title}>
- {section.id === "generators" && <SettingsCard icon={<Add20 />} header="Add a generator" description="Choose the generator used by default, or open one to edit its model setup">
+ {section.id === "generators" && <GeneratorSharing templates={[]}>{({ importButton }) => <SettingsCard icon={<Add20 />} header="Add a generator" description="Choose the generator used by default, or open one to edit its model setup">
+ {importButton}
<button type="button" className="secondary-button" onClick={addTemplate}>New generator</button>
- </SettingsCard>}
+ </SettingsCard>}</GeneratorSharing>}
<div className="settings-card-list" role="list" aria-label={section.title}>
{section.templates.map((template) => {
const needsDownload = templateNeedsDownload(template);
diff --git a/src/styles/settings.css b/src/styles/settings.css
index c44ce84..d664b16 100644
--- a/src/styles/settings.css
+++ b/src/styles/settings.css
@@ -151,6 +151,10 @@
margin-bottom: var(--space-2);
}
+.settings-page__actions-end {
+ margin-left: auto;
+}
+
.settings-caption {
margin: 0 0 var(--space-2);
color: var(--text-secondary);