qa: Don't fail if no scenario + don't show menu item

This commit is contained in:
nemunaire 2024-09-18 11:16:44 +02:00
parent 7ae1517a59
commit a630075116
2 changed files with 9 additions and 1 deletions

View File

@ -23,6 +23,7 @@
} from '@sveltestrap/sveltestrap';
import { auth, gitlab, version } from '$lib/stores/auth';
import { themes } from '$lib/stores/themes';
export let activemenu = "";
$: {
@ -50,6 +51,7 @@
<span class="d-none d-md-inline">Accueil</span>
</NavLink>
</NavItem>
{#if $themes.length}
<NavItem>
<NavLink
href="themes"
@ -59,6 +61,7 @@
<span class="d-none d-md-inline">Scénarios</span>
</NavLink>
</NavItem>
{/if}
<NavItem>
<NavLink
href="exercices"

View File

@ -23,7 +23,12 @@ export class Theme {
export async function getThemes() {
const res = await fetch(`api/themes`, {headers: {'Accept': 'application/json'}})
if (res.status == 200) {
return (await res.json()).map((t) => new Theme(t));
const data = await res.json();
if (data) {
return data.map((t) => new Theme(t));
} else {
return [];
}
} else {
throw new Error((await res.json()).errmsg);
}