interface FilesBreadcrumbProps {
path: string;
isShowingNotes?: boolean;
isShowingPhotos?: boolean;
fileShareId?: string;
}
export default function FilesBreadcrumb({ path, isShowingNotes, isShowingPhotos, fileShareId }: FilesBreadcrumbProps) {
let routePath = fileShareId ? `file-share/${fileShareId}` : 'files';
let rootPath = '/';
let itemPluralLabel = 'files';
if (isShowingNotes) {
routePath = 'notes';
itemPluralLabel = 'notes';
rootPath = '/Notes/';
} else if (isShowingPhotos) {
routePath = 'photos';
itemPluralLabel = 'photos';
rootPath = '/Photos/';
}
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)}
>
);
})}
);
}