Files
outline/app/scenes/Collection/components/CollectionMeta.tsx
T
Tom Moor 30da7e7ae6 fix: Reduce layout shift on page load (#14843)
* fix: Reduce layout shift on page load

- Open the history sidebar on load without the slide-in animation
- Keep server task counts until the editor exists
- Measure the header before paint so actions do not switch to compact
- Do not mark a store loaded from a filtered list
- Show cached list items only once that list has been fetched
- Reserve space for the collection document count, search result count and document views

* fix: Clear the document sidebar before a replacement instance sets it

* test
2026-12-02 22:50:43 -05:00

119 lines
3.5 KiB
TypeScript

import { observer } from "mobx-react";
import { GlobeIcon, PadlockIcon, TeamIcon } from "outline-icons";
import { useEffect } from "react";
import { useTranslation } from "react-i18next";
import styled from "styled-components";
import { breakpoint } from "@shared/styles/breakpoint";
import { flattenTree } from "@shared/utils/tree";
import type Collection from "~/models/Collection";
import Flex from "~/components/Flex";
import { HeaderMeta, Separator } from "~/components/HeaderMeta";
import OwnersLabel from "~/components/OwnersLabel";
import Tooltip from "~/components/Tooltip";
import useCurrentTeam from "~/hooks/useCurrentTeam";
import useStores from "~/hooks/useStores";
type Props = {
/** The collection to display meta information for */
collection: Collection;
};
/**
* A line of meta information about a collection, rendered directly beneath its
* title to match the equivalent display for documents.
*/
export const CollectionMeta = observer(function CollectionMeta_({
collection,
}: Props) {
const { t } = useTranslation();
const { shares } = useStores();
const team = useCurrentTeam();
const share = shares.getByCollectionId(collection.id);
const isPubliclyShared =
team.sharing !== false && collection.sharing !== false && !!share?.isActive;
// The document structure is cached on the collection once loaded, so this is
// a no-op when the sidebar or another tab has already requested it.
useEffect(() => {
void collection.fetchDocuments();
}, [collection]);
const documentCount = collection.documents
? flattenTree(collection.asNavigationNode).length - 1
: undefined;
return (
<Meta align="center" dir="ltr">
<Tooltip
content={
collection.isPrivate
? t("Only members with access can view")
: t("All members in the workspace can view")
}
side="bottom"
>
<IconLabel align="center">
{collection.isPrivate ? (
<PadlockIcon size={18} />
) : (
<TeamIcon size={18} />
)}
{collection.isPrivate ? t("Private") : t("Workspace")}
</IconLabel>
</Tooltip>
{isPubliclyShared && (
<>
<Separator />
<Tooltip content={t("Anyone with the link can view")} side="bottom">
<IconLabel align="center">
<GlobeIcon size={18} />
{t("Publicly shared")}
</IconLabel>
</Tooltip>
</>
)}
{/* Reserve the space while the count loads, so the line does not grow. */}
<DocumentCount
$hidden={documentCount === undefined}
aria-hidden={documentCount === undefined}
>
<Separator />
{t("{{ count }} document", { count: documentCount ?? 0 })}
</DocumentCount>
{collection.ownerIds.length > 0 && (
<span>
<Separator />
<OwnersLabel ownerIds={collection.ownerIds} />
</span>
)}
</Meta>
);
});
const DocumentCount = styled.span<{ $hidden: boolean }>`
font-variant-numeric: tabular-nums;
visibility: ${(props) => (props.$hidden ? "hidden" : "visible")};
`;
const IconLabel = styled(Flex)`
gap: 2px;
cursor: default;
`;
const Meta = styled(HeaderMeta)`
// Aligns with the collection title, which is indented on mobile.
margin-inline-start: 16px;
${breakpoint("mobile", "tablet")`
// Icons have built-in padding, offset it so they align with stacked text.
${IconLabel} svg {
margin-inline-start: -4px;
}
`}
${breakpoint("tablet")`
margin-inline-start: 0;
`}
`;