fix: Tabs on document references don't show active state
'Referenced by' -> 'Backlinks'
This commit is contained in:
@@ -14,9 +14,11 @@ function NavLinkWithChildrenFunc(
|
|||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
<Route path={to} exact={exact}>
|
<Route path={to} exact={exact}>
|
||||||
{({ match }) => (
|
{({ match, location }) => (
|
||||||
<NavLink {...rest} to={to} exact={exact} ref={ref}>
|
<NavLink {...rest} to={to} exact={exact} ref={ref}>
|
||||||
{children ? children(match) : null}
|
{children
|
||||||
|
? children(rest.isActive ? rest.isActive(match, location) : match)
|
||||||
|
: null}
|
||||||
</NavLink>
|
</NavLink>
|
||||||
)}
|
)}
|
||||||
</Route>
|
</Route>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { observer } from "mobx-react";
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { Trans } from "react-i18next";
|
import { Trans } from "react-i18next";
|
||||||
import { useLocation } from "react-router-dom";
|
import { useLocation } from "react-router-dom";
|
||||||
|
import styled from "styled-components";
|
||||||
import Document from "~/models/Document";
|
import Document from "~/models/Document";
|
||||||
import Fade from "~/components/Fade";
|
import Fade from "~/components/Fade";
|
||||||
import Tab from "~/components/Tab";
|
import Tab from "~/components/Tab";
|
||||||
@@ -29,6 +30,7 @@ function References({ document }: Props) {
|
|||||||
const showBacklinks = !!backlinks.length;
|
const showBacklinks = !!backlinks.length;
|
||||||
const showChildDocuments = !!children.length;
|
const showChildDocuments = !!children.length;
|
||||||
const isBacklinksTab = location.hash === "#backlinks" || !showChildDocuments;
|
const isBacklinksTab = location.hash === "#backlinks" || !showChildDocuments;
|
||||||
|
const height = Math.max(backlinks.length, children.length) * 40;
|
||||||
|
|
||||||
return showBacklinks || showChildDocuments ? (
|
return showBacklinks || showChildDocuments ? (
|
||||||
<Fade>
|
<Fade>
|
||||||
@@ -40,35 +42,56 @@ function References({ document }: Props) {
|
|||||||
)}
|
)}
|
||||||
{showBacklinks && (
|
{showBacklinks && (
|
||||||
<Tab to="#backlinks" isActive={() => isBacklinksTab}>
|
<Tab to="#backlinks" isActive={() => isBacklinksTab}>
|
||||||
<Trans>Referenced by</Trans>
|
<Trans>Backlinks</Trans>
|
||||||
</Tab>
|
</Tab>
|
||||||
)}
|
)}
|
||||||
</Tabs>
|
</Tabs>
|
||||||
{isBacklinksTab
|
<Content style={{ height }}>
|
||||||
? backlinks.map((backlinkedDocument) => (
|
{showBacklinks && (
|
||||||
<ReferenceListItem
|
<List $active={isBacklinksTab}>
|
||||||
anchor={document.urlId}
|
{backlinks.map((backlinkedDocument) => (
|
||||||
key={backlinkedDocument.id}
|
|
||||||
document={backlinkedDocument}
|
|
||||||
showCollection={
|
|
||||||
backlinkedDocument.collectionId !== document.collectionId
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
: children.map((node) => {
|
|
||||||
// If we have the document in the store already then use it to get the extra
|
|
||||||
// contextual info, otherwise the collection node will do (only has title and id)
|
|
||||||
const document = documents.get(node.id);
|
|
||||||
return (
|
|
||||||
<ReferenceListItem
|
<ReferenceListItem
|
||||||
key={node.id}
|
anchor={document.urlId}
|
||||||
document={document || node}
|
key={backlinkedDocument.id}
|
||||||
showCollection={false}
|
document={backlinkedDocument}
|
||||||
|
showCollection={
|
||||||
|
backlinkedDocument.collectionId !== document.collectionId
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
);
|
))}
|
||||||
})}
|
</List>
|
||||||
|
)}
|
||||||
|
{showChildDocuments && (
|
||||||
|
<List $active={!isBacklinksTab}>
|
||||||
|
{children.map((node) => {
|
||||||
|
// If we have the document in the store already then use it to get the extra
|
||||||
|
// contextual info, otherwise the collection node will do (only has title and id)
|
||||||
|
const document = documents.get(node.id);
|
||||||
|
return (
|
||||||
|
<ReferenceListItem
|
||||||
|
key={node.id}
|
||||||
|
document={document || node}
|
||||||
|
showCollection={false}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</List>
|
||||||
|
)}
|
||||||
|
</Content>
|
||||||
</Fade>
|
</Fade>
|
||||||
) : null;
|
) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Content = styled.div`
|
||||||
|
position: relative;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const List = styled.div<{ $active: boolean }>`
|
||||||
|
visibility: ${({ $active }) => ($active ? "visible" : "hidden")};
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
`;
|
||||||
|
|
||||||
export default observer(References);
|
export default observer(References);
|
||||||
|
|||||||
@@ -150,7 +150,6 @@
|
|||||||
"Starred documents could not be loaded": "Starred documents could not be loaded",
|
"Starred documents could not be loaded": "Starred documents could not be loaded",
|
||||||
"Starred": "Starred",
|
"Starred": "Starred",
|
||||||
"Show more": "Show more",
|
"Show more": "Show more",
|
||||||
"Show less": "Show less",
|
|
||||||
"Toggle sidebar": "Toggle sidebar",
|
"Toggle sidebar": "Toggle sidebar",
|
||||||
"Delete {{ documentName }}": "Delete {{ documentName }}",
|
"Delete {{ documentName }}": "Delete {{ documentName }}",
|
||||||
"Return to App": "Back to App",
|
"Return to App": "Back to App",
|
||||||
@@ -258,7 +257,6 @@
|
|||||||
"Move": "Move",
|
"Move": "Move",
|
||||||
"Permanently delete": "Permanently delete",
|
"Permanently delete": "Permanently delete",
|
||||||
"Enable embeds": "Enable embeds",
|
"Enable embeds": "Enable embeds",
|
||||||
"Disable embeds": "Disable embeds",
|
|
||||||
"Full width": "Full width",
|
"Full width": "Full width",
|
||||||
"Move {{ documentName }}": "Move {{ documentName }}",
|
"Move {{ documentName }}": "Move {{ documentName }}",
|
||||||
"Permanently delete {{ documentName }}": "Permanently delete {{ documentName }}",
|
"Permanently delete {{ documentName }}": "Permanently delete {{ documentName }}",
|
||||||
@@ -401,7 +399,7 @@
|
|||||||
"Deleted by {{userName}}": "Deleted by {{userName}}",
|
"Deleted by {{userName}}": "Deleted by {{userName}}",
|
||||||
"Observing {{ userName }}": "Observing {{ userName }}",
|
"Observing {{ userName }}": "Observing {{ userName }}",
|
||||||
"Nested documents": "Nested documents",
|
"Nested documents": "Nested documents",
|
||||||
"Referenced by": "Referenced by",
|
"Backlinks": "Backlinks",
|
||||||
"Anyone with the link <1></1>can view this document": "Anyone with the link <1></1>can view this document",
|
"Anyone with the link <1></1>can view this document": "Anyone with the link <1></1>can view this document",
|
||||||
"Share": "Share",
|
"Share": "Share",
|
||||||
"Share this document": "Share this document",
|
"Share this document": "Share this document",
|
||||||
|
|||||||
Reference in New Issue
Block a user