Skip to content

Commit

Permalink
Refactor navigation structure by moving navigation items and title re…
Browse files Browse the repository at this point in the history
…trieval logic to a shared module. Update NavigationBar and main page to utilize the new centralized navigation data, improving maintainability and consistency across the application.
  • Loading branch information
Malte2036 committed Jan 21, 2025
1 parent d205d01 commit eb31084
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 118 deletions.
44 changes: 2 additions & 42 deletions src/lib/navigation/NavigationBar.svelte
Original file line number Diff line number Diff line change
@@ -1,58 +1,18 @@
<script lang="ts">
import { page } from '$app/stores';
import logo from '$lib/icons/thw-mzgw.webp';
const navItems = [
{
title: 'Quiz',
items: [
{ name: 'Grundausbildungs-Quiz', href: '/quiz/ga/listing/' },
{ name: 'Sprechfunk-Quiz', href: '/quiz/radio/listing/' },
{ name: 'Atemschutz-Quiz', href: '/quiz/agt/listing/' },
{ name: 'CBRN-Quiz', href: '/quiz/cbrn/listing/' }
]
},
{
title: 'Tools',
items: [
{ name: 'CBRN-Schutzanzug', href: '/cbrn/protective-suite' },
{ name: 'Finnentest', href: 'https://finnentest.thw-tools.de', external: true },
{ name: 'Elektro Spannungsfall', href: 'https://elektro.thw-tools.de', external: true },
{ name: 'THW Bekleidungs Rechner', href: '/clothing' }
]
}
];
import { navigationItems, getCurrentTitleByPath } from '$lib/shared/navigation';
$: currentPath = $page.url.pathname;
$: isHomePage = currentPath === '/';
function getCurrentTitleByPath(path: string): string | undefined {
if (path.startsWith('/quiz/ga')) {
return 'Grundausbildungs-Quiz';
} else if (path.startsWith('/quiz/agt')) {
return 'Atemschutz-Quiz';
} else if (path.startsWith('/quiz/cbrn')) {
return 'CBRN-Quiz';
} else if (path.startsWith('/quiz/radio')) {
return 'Sprechfunk-Quiz';
} else if (path.startsWith('/cbrn/protective-suite')) {
return 'CBRN-Schutzanzug';
} else if (path.startsWith('/clothing')) {
return 'Bekleidungsrechner';
} else if (path === '/') {
return undefined;
} else {
return 'THW-Tools';
}
}
</script>

{#if !isHomePage}
<div class="sticky top-0 z-50 bg-white">
<thw-navigation-bar
logoUrl={logo}
title={getCurrentTitleByPath(currentPath)}
{navItems}
navItems={navigationItems}
{currentPath}
/>
</div>
Expand Down
107 changes: 107 additions & 0 deletions src/lib/shared/navigation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import HammerIcon from '$lib/icons/HammerIcon.svelte';
import WalkieTalkieIcon from '$lib/icons/WalkieTalkieIcon.svelte';
import ChartSimpleIcon from '$lib/icons/ChartSimpleIcon.svelte';
import CircleRadiationIcon from '$lib/icons/CircleRadiationIcon.svelte';
import VestIcon from '$lib/icons/VestIcon.svelte';
import HearthPulseIcon from '$lib/icons/HearthPulseIcon.svelte';
import BoltIcon from '$lib/icons/BoltIcon.svelte';

export type NavigationItem = {
name: string;
href: string;
external?: boolean;
icon?: any;
event?: string;
};

export type NavigationCategory = {
title: string;
description?: string;
items: NavigationItem[];
};

export function getCurrentTitleByPath(path: string): string | undefined {
if (path.startsWith('/quiz/ga')) {
return 'Grundausbildungs-Quiz';
} else if (path.startsWith('/quiz/agt')) {
return 'Atemschutz-Quiz';
} else if (path.startsWith('/quiz/cbrn')) {
return 'CBRN-Quiz';
} else if (path.startsWith('/quiz/radio')) {
return 'Sprechfunk-Quiz';
} else if (path.startsWith('/cbrn/protective-suite')) {
return 'CBRN-Schutzanzug';
} else if (path.startsWith('/clothing')) {
return 'Bekleidungsrechner';
} else if (path === '/') {
return undefined;
} else {
return 'THW-Tools';
}
}

export const navigationItems: NavigationCategory[] = [
{
title: 'Ausbildungs-Quiz',
description: 'Teste und verbessere dein Wissen in verschiedenen THW-Bereichen',
items: [
{
name: 'Grundausbildungs-Quiz',
href: '/quiz/ga/listing/',
event: 'Open GA Quiz',
icon: HammerIcon
},
{
name: 'Sprechfunk-Quiz',
href: '/quiz/radio/listing/',
event: 'Open Radio Quiz',
icon: WalkieTalkieIcon
},
{
name: 'Atemschutz-Quiz',
href: '/quiz/agt/listing/',
event: 'Open AGT Quiz',
icon: ChartSimpleIcon
},
{
name: 'CBRN-Quiz',
href: '/quiz/cbrn/listing/',
event: 'Open CBRN Quiz',
icon: CircleRadiationIcon
}
]
},
{
title: 'Tools',
description: 'Hilfreiche Werkzeuge für den THW-Alltag',
items: [
{
name: 'Bekleidungsrechner',
href: '/clothing',
event: 'Open Clothing Calculator',
icon: VestIcon
},

{
name: 'Finnentest',
href: 'https://finnentest.thw-tools.de',
event: 'Open Finnentest',
external: true,
icon: HearthPulseIcon
},
{
name: 'Elektro Spannungsfall',
href: 'https://elektro.thw-tools.de',
event: 'Open Elektro Spannungsfall',
external: true,
icon: BoltIcon
}
// {
// name: 'CBRN-Schutzanzug',
// href: '/cbrn/protective-suite',
// event: 'Open CBRN Protective Suite',
// icon: VestIcon
// }
]
}
];
81 changes: 5 additions & 76 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
<script lang="ts">
import FlaskVialIcon from '$lib/icons/FlaskVialIcon.svelte';
import logo from '$lib/icons/thw-mzgw.webp';
import LinkButton from '../lib/LinkButton.svelte';
import ChartSimpleIcon from '../lib/icons/ChartSimpleIcon.svelte';
import HearthPulseIcon from '../lib/icons/HearthPulseIcon.svelte';
import BoltIcon from '$lib/icons/BoltIcon.svelte';
import HammerIcon from '$lib/icons/HammerIcon.svelte';
import VestIcon from '$lib/icons/VestIcon.svelte';
import { bannerMessage } from '$lib/shared/stores/bannerMessage';
import { onMount } from 'svelte';
import WalkieTalkieIcon from '$lib/icons/WalkieTalkieIcon.svelte';
import CircleRadiationIcon from '$lib/icons/CircleRadiationIcon.svelte';
import { navigationItems } from '$lib/shared/navigation';
const description = {
headline: 'Inoffizielle Tools für THW-Helfer:',
Expand Down Expand Up @@ -45,70 +37,7 @@
}
});
const toolCategories = [
{
title: 'Ausbildungs-Quiz',
description: 'Teste und verbessere dein Wissen in verschiedenen THW-Bereichen',
tools: [
{
name: 'Grundausbildungs-Quiz',
icon: HammerIcon,
url: '/quiz/ga/listing/',
event: 'Open GA Quiz'
},
{
name: 'Sprechfunk-Quiz',
icon: WalkieTalkieIcon,
url: '/quiz/radio/listing/',
event: 'Open Radio Quiz'
},
{
name: 'Atemschutz-Quiz',
icon: ChartSimpleIcon,
url: '/quiz/agt/listing/',
event: 'Open AGT Quiz'
},
{
name: 'CBRN-Quiz',
icon: CircleRadiationIcon,
url: '/quiz/cbrn/listing/',
event: 'Open CBRN Quiz'
}
]
},
{
title: 'Praktische Tools',
description: 'Hilfreiche Werkzeuge für den THW-Alltag',
tools: [
{
name: 'THW Bekleidungs Rechner',
icon: VestIcon,
url: '/clothing',
event: 'Open THW Clothing'
},
{
name: 'Finnentest',
icon: HearthPulseIcon,
url: 'https://finnentest.thw-tools.de',
event: 'Open Finnentest',
external: true
},
{
name: 'Elektro Spannungsfall',
icon: BoltIcon,
url: 'https://elektro.thw-tools.de',
event: 'Open Elektro Spannungsfall',
external: true
},
{
name: 'CBRN-Schutzanzug',
icon: VestIcon,
url: '/cbrn/protective-suite',
event: 'Open CBRN Protective Suite'
}
]
}
];
const toolCategories = navigationItems;
</script>

<svelte:head>
Expand Down Expand Up @@ -157,9 +86,9 @@
</div>

<!-- Tools List -->
<div class="flex flex-col gap-3 flex-grow">
{#each category.tools as tool}
<LinkButton url={tool.url} blank={tool.external} dataUmamiEvent={tool.event}>
<div class="flex flex-col gap-3">
{#each category.items as tool}
<LinkButton url={tool.href} blank={tool.external} dataUmamiEvent={tool.event}>
<div class="w-6 group-hover:text-thw-600 transition-colors">
<svelte:component this={tool.icon} />
</div>
Expand Down

0 comments on commit eb31084

Please # to comment.