Skip to content

Modern Docker Management, Designed for Everyone

add onDownloadSuccess callback to TemplateSelectionDialog

Kyle Mendellc3a0f8446f35
diff --git a/frontend/src/lib/components/dialogs/template-selection-dialog.svelte b/frontend/src/lib/components/dialogs/template-selection-dialog.svelte
index 1a03e5be9..cc8de72f8 100644
--- a/frontend/src/lib/components/dialogs/template-selection-dialog.svelte
+++ b/frontend/src/lib/components/dialogs/template-selection-dialog.svelte
@@ -12,9 +12,10 @@
open: boolean;
templates: Template[];
onSelect: (template: Template) => void;
+ onDownloadSuccess?: () => void;
}
- let { open = $bindable(), templates, onSelect }: Props = $props();
+ let { open = $bindable(), templates, onSelect, onDownloadSuccess }: Props = $props(); // Include new prop
let loadingStates = $state(new Map<string, boolean>());
@@ -66,13 +67,15 @@
if (result) {
toast.success(`Template "${template.name}" downloaded successfully!`);
+ if (onDownloadSuccess) {
+ onDownloadSuccess();
+ }
} else {
toast.error('Failed to download template');
}
} catch (error) {
console.error('Error downloading template:', error);
- // Extract the actual error message from the API response
let errorMessage = 'Failed to download template';
if (error instanceof Error) {
errorMessage = error.message;
diff --git a/frontend/src/routes/compose/new/+page.svelte b/frontend/src/routes/compose/new/+page.svelte
index ff3f2a374..3982a2aa5 100644
--- a/frontend/src/routes/compose/new/+page.svelte
+++ b/frontend/src/routes/compose/new/+page.svelte
@@ -5,7 +5,7 @@
import * as Breadcrumb from '$lib/components/ui/breadcrumb/index.js';
import { Input } from '$lib/components/ui/input/index.js';
import { Label } from '$lib/components/ui/label/index.js';
- import { goto, invalidateAll } from '$app/navigation';
+ import { goto, invalidateAll } from '$app/navigation'; // Import invalidateAll
import { toast } from 'svelte-sonner';
import YamlEditor from '$lib/components/yaml-editor.svelte';
import { preventDefault } from '$lib/utils/form.utils';
@@ -75,39 +75,25 @@
async function handleTemplateSelect(template: Template) {
showTemplateDialog = false; // Close the dialog immediately
- if (template.isRemote) {
- isLoadingTemplateContent = true;
- handleApiResultWithCallbacks({
- result: await tryCatch(templateAPI.getTemplateContent(template.id)),
- message: `Failed to load content for template "${template.name}"`,
- setLoadingState: (value) => (isLoadingTemplateContent = value),
- onSuccess: (data) => {
- composeContent = data.content;
- envContent = data.envContent;
- if (!name.trim()) {
- name = template.name.toLowerCase().replace(/[^a-z0-9-]/g, '-');
- }
- toast.success(`Template "${template.name}" loaded successfully!`);
- },
- onError: () => {
- // Re-open dialog or show error state if fetching fails
- showTemplateDialog = true;
- }
- });
+ // The template object passed here already has content and envContent
+ // because the TemplateSelectionDialog now calls getTemplateContent
+ // before calling onSelect.
+ composeContent = template.content;
+ if (template.envContent) {
+ envContent = template.envContent;
} else {
- // Handle local templates which should have content already
- composeContent = template.content;
- if (template.envContent) {
- envContent = template.envContent;
- } else {
- envContent = defaultEnvTemplate;
- }
+ envContent = defaultEnvTemplate;
+ }
- if (!name.trim()) {
- name = template.name.toLowerCase().replace(/[^a-z0-9-]/g, '-');
- }
- toast.success(`Template "${template.name}" loaded successfully!`);
+ if (!name.trim()) {
+ name = template.name.toLowerCase().replace(/[^a-z0-9-]/g, '-');
}
+ toast.success(`Template "${template.name}" loaded successfully!`);
+
+ // No need for isLoadingTemplateContent state or API call here anymore
+ // as the dialog handles fetching content before calling onSelect.
+ // The state was primarily for the API call within this function.
+ // Keep it if other parts of the page depend on it.
}
const exampleCommands = [
@@ -296,9 +282,9 @@
</form>
</div>
-<!-- Template Selection Dialog -->
<TemplateSelectionDialog
bind:open={showTemplateDialog}
templates={data.composeTemplates || []}
onSelect={handleTemplateSelect}
+ onDownloadSuccess={invalidateAll}
/>