Auto select last artifact

This commit is contained in:
ernstmul
2025-05-14 10:41:26 +02:00
parent e34390a10a
commit d3bbe0fb9f
4 changed files with 26 additions and 10 deletions
+4 -3
View File
@@ -5,9 +5,10 @@ import { base } from '$app/paths';
import { page } from '$app/state';
import { Dependencies } from '$lib/constants';
export async function createArtifact() {
export async function createArtifact(projectId?: string) {
const artifact = await sdk.forProject.imagine.create(ID.unique());
await goto(`${base}/project-${page.params.project}/studio/artifact-${artifact.$id}`);
await goto(
`${base}/project-${projectId ?? page.params.project}/studio/artifact-${artifact.$id}`
);
invalidate(Dependencies.ARTIFACTS);
}
@@ -2,12 +2,6 @@ import { Dependencies } from '$lib/constants';
import { sdk } from '$lib/stores/sdk';
import { error } from '@sveltejs/kit';
import type { LayoutLoad } from './$types';
import { preferences } from '$lib/stores/preferences';
import { failedInvoice } from '$lib/stores/billing';
import { isCloud } from '$lib/system';
import type { Organization } from '$lib/stores/organization';
import { defaultRoles, defaultScopes } from '$lib/constants';
import type { Plan } from '$lib/sdk/billing';
export const load: LayoutLoad = async ({ params, depends }) => {
depends(Dependencies.ARTIFACTS);
@@ -0,0 +1,19 @@
import type { PageLoad } from './$types';
import { sdk } from '$lib/stores/sdk';
import { createArtifact } from '$lib/helpers/artifact';
import { goto } from '$app/navigation';
import { base } from '$app/paths';
import { page } from '$app/state';
export const load: PageLoad = async ({ params }) => {
const artifacts = await sdk.forProject.imagine.list();
if (artifacts.total === 0) {
await createArtifact(params.project);
return;
}
const lastUpdatedArtifact = artifacts.artifacts.reduce((latest, artifact) => {
return new Date(artifact.$updatedAt) > new Date(latest.$updatedAt) ? artifact : latest;
});
await goto(`${base}/project-${params.project}/studio/artifact-${lastUpdatedArtifact.$id}`);
};
@@ -164,7 +164,9 @@
mappedArtifacts.push({
name: 'Create artifact',
isActive: false,
onClick: createArtifact,
onClick: () => {
createArtifact();
},
icon: IconPlus
});
return mappedArtifacts;