-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding breadcrumb all around the app
- Loading branch information
Showing
41 changed files
with
627 additions
and
293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { Link, useMatches } from '@remix-run/react'; | ||
import { Future } from '@swan-io/boxed'; | ||
import clsx from 'clsx'; | ||
import { | ||
type FunctionComponent, | ||
type PropsWithChildren, | ||
useEffect, | ||
useState, | ||
} from 'react'; | ||
import { filter } from 'remeda'; | ||
|
||
type Links = { | ||
Element: FunctionComponent | undefined; | ||
pathname: string; | ||
}[]; | ||
|
||
const Separator = () => ( | ||
<span className="text-s text-grey-80 font-bold">/</span> | ||
); | ||
|
||
const LinkWrapper = ({ | ||
isLast, | ||
children, | ||
pathname, | ||
}: PropsWithChildren<{ isLast: boolean; pathname: string }>) => { | ||
return isLast ? ( | ||
children | ||
) : ( | ||
<Link | ||
to={pathname} | ||
className={clsx('transition-colors', { | ||
'text-grey-50 hover:text-grey-00': !isLast, | ||
})} | ||
> | ||
{children} | ||
</Link> | ||
); | ||
}; | ||
|
||
export const BreadCrumbs = () => { | ||
const matches = useMatches(); | ||
const [links, setLinks] = useState<Links>([]); | ||
|
||
console.log('Matches', matches); | ||
|
||
useEffect(() => { | ||
Future.all( | ||
matches.map(({ id, pathname }) => | ||
Future.fromPromise( | ||
import(/* @vite-ignore */ `../${id}`) as Promise<{ | ||
BreadCrumb?: FunctionComponent; | ||
}>, | ||
).map((result) => ({ | ||
Element: result.isOk() ? result.value.BreadCrumb : undefined, | ||
pathname, | ||
})), | ||
), | ||
) | ||
.map(filter((r) => r.Element !== undefined)) | ||
.then(setLinks); | ||
}, [matches]); | ||
|
||
return ( | ||
<div className="flex flex-row items-center gap-4"> | ||
{links.map(({ Element, pathname }, i) => { | ||
const isLast = i === links.length - 1; | ||
|
||
return Element ? ( | ||
<div className="text-s flex items-center gap-4 font-bold" key={i}> | ||
<LinkWrapper isLast={isLast} pathname={pathname}> | ||
<Element /> | ||
</LinkWrapper> | ||
{!isLast ? <Separator /> : null} | ||
</div> | ||
) : null; | ||
})} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/app-builder/src/routes/_builder+/cases+/_layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Outlet } from '@remix-run/react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Icon } from 'ui-icons'; | ||
|
||
export const BreadCrumb = () => { | ||
const { t } = useTranslation(['navigation', 'cases']); | ||
|
||
return ( | ||
<div className="flex items-center"> | ||
<Icon icon="case-manager" className="me-2 size-6" /> | ||
{t('navigation:case_manager')} | ||
</div> | ||
); | ||
}; | ||
|
||
export default function CasesLayout() { | ||
return <Outlet />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.