bewcloud/components/files/FilesBreadcrumb.tsx

71 lines
2 KiB
TypeScript
Raw Permalink Normal View History

interface FilesBreadcrumbProps {
path: string;
2024-04-26 13:31:25 +00:00
isShowingNotes?: boolean;
2024-04-27 07:12:44 +00:00
isShowingPhotos?: boolean;
fileShareId?: string;
}
export default function FilesBreadcrumb({ path, isShowingNotes, isShowingPhotos, fileShareId }: FilesBreadcrumbProps) {
let routePath = fileShareId ? `file-share/${fileShareId}` : 'files';
2024-04-27 07:12:44 +00:00
let rootPath = '/';
let itemPluralLabel = 'files';
2024-04-26 13:31:25 +00:00
2024-04-27 07:12:44 +00:00
if (isShowingNotes) {
routePath = 'notes';
itemPluralLabel = 'notes';
2024-04-27 07:12:44 +00:00
rootPath = '/Notes/';
} else if (isShowingPhotos) {
routePath = 'photos';
itemPluralLabel = 'photos';
2024-04-27 07:12:44 +00:00
rootPath = '/Photos/';
}
2024-04-27 07:12:44 +00:00
if (path === rootPath) {
2024-04-26 13:31:25 +00:00
return (
<h3 class='text-base font-semibold text-white whitespace-nowrap mr-2'>
2024-04-27 07:12:44 +00:00
All {itemPluralLabel}
2024-04-26 13:31:25 +00:00
</h3>
);
}
const pathParts = path.slice(1, -1).split('/');
return (
<h3 class='text-base font-semibold text-white whitespace-nowrap mr-2'>
{!isShowingNotes && !isShowingPhotos ? <a href={`/${routePath}?path=/`}>All files</a> : null}
2024-04-27 07:12:44 +00:00
{isShowingNotes ? <a href={`/notes?path=/Notes/`}>All notes</a> : null}
{isShowingPhotos ? <a href={`/photos?path=/Photos/`}>All photos</a> : null}
{pathParts.map((part, index) => {
2024-04-27 07:12:44 +00:00
// Ignore the first directory in special ones
if (index === 0 && (isShowingNotes || isShowingPhotos)) {
return null;
}
if (index === pathParts.length - 1) {
return (
<>
<span class='ml-2 text-xs'>/</span>
2024-04-26 13:31:25 +00:00
<span class='ml-2'>{decodeURIComponent(part)}</span>
</>
);
}
const fullPathForPart: string[] = [];
for (let pathPartIndex = 0; pathPartIndex <= index; ++pathPartIndex) {
fullPathForPart.push(pathParts[pathPartIndex]);
}
return (
<>
<span class='ml-2 text-xs'>/</span>
<a href={`/${routePath}?path=/${encodeURIComponent(fullPathForPart.join('/'))}/`} class='ml-2'>
{decodeURIComponent(part)}
</a>
</>
);
})}
</h3>
);
}