mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
Auto select last artifact
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user