Skip to content

Commit

Permalink
Move page title retrieval logic to breadcrumbs component
Browse files Browse the repository at this point in the history
This makes it easier to manage it across CE and EE builds given the fact
that EE has its own (app)/+layout.svelte
  • Loading branch information
nas-tabchiche committed Dec 20, 2024
1 parent 6f8b337 commit cd66535
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
15 changes: 15 additions & 0 deletions frontend/src/lib/components/Breadcrumbs/Breadcrumbs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { page } from '$app/stores';
import { breadcrumbs, type Breadcrumb } from '$lib/utils/breadcrumbs';
import { safeTranslate } from '$lib/utils/i18n';
import { pageTitle } from '$lib/utils/stores';
async function trimBreadcrumbsToCurrentPath(
breadcrumbs: Breadcrumb[],
Expand All @@ -15,9 +16,23 @@
return breadcrumbs;
}
function getPageTitle(): string {
return safeTranslate(
$page.data.title || $page.data.str || $page.data.name || $breadcrumbs.length > 1
? $breadcrumbs[$breadcrumbs.length - 1]?.label
: $page.url.pathname.split('/').pop()
);
}
afterNavigate(async () => {
$breadcrumbs = await trimBreadcrumbsToCurrentPath($breadcrumbs, $page.url.pathname);
});
$: {
$pageTitle = getPageTitle();
if ($breadcrumbs.length < 2)
breadcrumbs.push([{ label: $pageTitle, href: $page.url.pathname }]);
}
</script>

<ol class="breadcrumb-nonresponsive h-6 overflow-hidden whitespace-nowrap">
Expand Down
14 changes: 0 additions & 14 deletions frontend/src/routes/(app)/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,8 @@
import commandPaletteOpen from '$lib/components/CommandPalette/CommandPalette.svelte';
let sidebarOpen = true;
function getPageTitle(): string {
return safeTranslate(
$page.data.title || $page.data.str || $page.data.name || $breadcrumbs.length > 1
? $breadcrumbs[$breadcrumbs.length - 1]?.label
: $page.url.pathname.split('/').pop()
);
}
$: classesSidebarOpen = (open: boolean) => (open ? 'ml-7 lg:ml-64' : 'ml-7');
$: {
$pageTitle = getPageTitle();
if ($breadcrumbs.length < 2)
breadcrumbs.push([{ label: $pageTitle, href: $page.url.pathname }]);
}
$: if (browser) {
const fromLogin = getCookie('from_login');
if (fromLogin === 'true') {
Expand Down

0 comments on commit cd66535

Please sign in to comment.