interface FilesBreadcrumbProps {
path: string;
isShowingNotes?: boolean;
isShowingPhotos?: boolean;
}
export default function FilesBreadcrumb({ path, isShowingNotes, isShowingPhotos }: FilesBreadcrumbProps) {
let routePath = 'files';
let rootPath = '/';
if (isShowingNotes) {
routePath = 'notes';
rootPath = '/Notes/';
} else if (isShowingPhotos) {
routePath = 'photos';
rootPath = '/Photos/';
}
const itemPluralLabel = routePath;
if (path === rootPath) {
return (
All {itemPluralLabel}
);
}
const pathParts = path.slice(1, -1).split('/');
return (
{!isShowingNotes && !isShowingPhotos ? All files : null}
{isShowingNotes ? All notes : null}
{isShowingPhotos ? All photos : null}
{pathParts.map((part, index) => {
// Ignore the first directory in special ones
if (index === 0 && (isShowingNotes || isShowingPhotos)) {
return null;
}
if (index === pathParts.length - 1) {
return (
<>
/
{decodeURIComponent(part)}
>
);
}
const fullPathForPart: string[] = [];
for (let pathPartIndex = 0; pathPartIndex <= index; ++pathPartIndex) {
fullPathForPart.push(pathParts[pathPartIndex]);
}
return (
<>
/
{decodeURIComponent(part)}
>
);
})}
);
}