Skip to content

Commit

Permalink
combine two functions
Browse files Browse the repository at this point in the history
  • Loading branch information
scazan committed Jul 12, 2024
1 parent 00553f5 commit bbb8b80
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
16 changes: 7 additions & 9 deletions src/components/Header/SpacesDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Collection, Site, Space } from '@gitbook/api';
import { getContentPointer } from '@/app/(space)/fetch';
import { getCurrentSiteCustomization, getSiteSpaces, getSpaceCustomization } from '@/lib/api';
import { tcls } from '@/lib/tailwind';
import { getSpaceTitle } from '@/lib/utils';
import { getContentTitle } from '@/lib/utils';

import { Dropdown, DropdownChevron, DropdownMenu } from './Dropdown';
import { SpacesDropdownMenuItem } from './SpacesDropdownMenuItem';
Expand All @@ -13,6 +13,7 @@ export async function SpacesDropdown(props: {
spaces: Space[];
parent?: Site | Collection | null;
}) {
props.parent?.object;
const { space, spaces } = props;
const contentPointer = getContentPointer();

Expand Down Expand Up @@ -62,10 +63,7 @@ export async function SpacesDropdown(props: {
'text-header-link-500',
)}
>
{getSpaceTitle({
space,
customization: spaceCustomizationsMap.get(space.id) ?? {},
})}
{getContentTitle(space, spaceCustomizationsMap.get(space.id) ?? {})}
<DropdownChevron />
</div>
)}
Expand All @@ -76,10 +74,10 @@ export async function SpacesDropdown(props: {
key={`${otherSpace.id}-${index}`}
variantSpace={{
id: otherSpace.id,
title: getSpaceTitle({
space: otherSpace,
customization: spaceCustomizationsMap.get(otherSpace.id) ?? {},
}),
title: getContentTitle(
otherSpace,
spaceCustomizationsMap.get(otherSpace.id) ?? {},
),
url: otherSpace.urls.published ?? otherSpace.urls.app,
}}
active={otherSpace.id === space.id}
Expand Down
13 changes: 1 addition & 12 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
export function getContentTitle(
space: Space,
customization: CustomizationSettings | SiteCustomizationSettings,
parent: Site | Collection | null,
parent?: Site | Collection | null,
) {
// When we are rendering a site, always give priority to the customization title first
// and then fallback to the site title
Expand All @@ -23,14 +23,3 @@ export function getContentTitle(
// Otherwise the legacy behavior is not changed to avoid regressions
return parent ? parent.title : customization.title ?? space.title;
}

/**
* Get the title to display for a Space.
*/
export function getSpaceTitle(args: {
space: Space;
customization: CustomizationSettings | SiteCustomizationSettings;
}) {
const { space, customization } = args;
return customization.title ?? space.title;
}

0 comments on commit bbb8b80

Please sign in to comment.