fix: load previews async

This commit is contained in:
Andras Bacsai 2022-07-25 18:55:58 +00:00
parent cf140ff4cf
commit cef87d9671

View File

@ -1,12 +1,10 @@
<script context="module" lang="ts"> <script context="module" lang="ts">
import type { Load } from '@sveltejs/kit'; import type { Load } from '@sveltejs/kit';
export const load: Load = async ({ fetch, params, stuff, url }) => { export const load: Load = async ({ stuff, url }) => {
try { try {
const response = await get(`/applications/${params.id}/previews`);
return { return {
props: { props: {
application: stuff.application, application: stuff.application
...response
} }
}; };
} catch (error) { } catch (error) {
@ -19,10 +17,7 @@
</script> </script>
<script lang="ts"> <script lang="ts">
export let containers: any;
export let application: any; export let application: any;
export let PRMRSecrets: any;
export let applicationSecrets: any;
import Secret from './_Secret.svelte'; import Secret from './_Secret.svelte';
import { get, post } from '$lib/api'; import { get, post } from '$lib/api';
import { page } from '$app/stores'; import { page } from '$app/stores';
@ -31,8 +26,15 @@
import { t } from '$lib/translations'; import { t } from '$lib/translations';
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { errorNotification, getDomain } from '$lib/common'; import { errorNotification, getDomain } from '$lib/common';
import { onMount } from 'svelte';
import Loading from '$lib/components/Loading.svelte';
const { id } = $page.params; const { id } = $page.params;
let containers: any;
let PRMRSecrets: any;
let applicationSecrets: any;
let loading = true;
async function refreshSecrets() { async function refreshSecrets() {
const data = await get(`/applications/${id}/secrets`); const data = await get(`/applications/${id}/secrets`);
PRMRSecrets = [...data.secrets]; PRMRSecrets = [...data.secrets];
@ -55,6 +57,19 @@
return errorNotification(error); return errorNotification(error);
} }
} }
onMount(async () => {
try {
loading = true;
const response = await get(`/applications/${id}/previews`);
containers = response.containers;
PRMRSecrets = response.PRMRSecrets;
applicationSecrets = response.applicationSecrets;
} catch (error) {
return errorNotification(error);
} finally {
loading = false;
}
});
</script> </script>
<div class="flex items-center space-x-2 p-5 px-6 font-bold"> <div class="flex items-center space-x-2 p-5 px-6 font-bold">
@ -62,7 +77,7 @@
<div class="md:max-w-64 truncate text-base tracking-tight md:text-2xl lg:block"> <div class="md:max-w-64 truncate text-base tracking-tight md:text-2xl lg:block">
Preview Deployments Preview Deployments
</div> </div>
<span class="text-xs">{application.name} </span> <span class="text-xs">{application?.name}</span>
</div> </div>
{#if application.gitSource?.htmlUrl && application.repository && application.branch} {#if application.gitSource?.htmlUrl && application.repository && application.branch}
<a <a
@ -108,6 +123,9 @@
</a> </a>
{/if} {/if}
</div> </div>
{#if loading}
<Loading />
{:else}
<div class="mx-auto max-w-6xl px-6 pt-4"> <div class="mx-auto max-w-6xl px-6 pt-4">
<div class="flex justify-center py-4 text-center"> <div class="flex justify-center py-4 text-center">
<Explainer <Explainer
@ -173,3 +191,4 @@
{/if} {/if}
</div> </div>
</div> </div>
{/if}