From 49198aafe93151421ce03a588f2caeeebd021764 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 7 Jul 2024 20:15:26 -0400 Subject: [PATCH] Hide document TOC when empty --- app/scenes/Document/components/Contents.tsx | 39 +++++++++------------ app/scenes/Document/components/Header.tsx | 8 ++++- shared/i18n/locales/en_US/translation.json | 1 + 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/app/scenes/Document/components/Contents.tsx b/app/scenes/Document/components/Contents.tsx index 216fd76fa..b6cf6c4d2 100644 --- a/app/scenes/Document/components/Contents.tsx +++ b/app/scenes/Document/components/Contents.tsx @@ -5,7 +5,6 @@ import styled from "styled-components"; import breakpoint from "styled-components-breakpoint"; import { EditorStyleHelper } from "@shared/editor/styles/EditorStyleHelper"; import { depths, s } from "@shared/styles"; -import Text from "~/components/Text"; import useWindowScrollPosition from "~/hooks/useWindowScrollPosition"; const HEADING_OFFSET = 20; @@ -54,26 +53,26 @@ export default function Contents({ headings }: Props) { const headingAdjustment = minHeading - 1; const { t } = useTranslation(); + if (headings.length === 0) { + return null; + } + return ( {t("Contents")} - {headings.length ? ( - - {headings - .filter((heading) => heading.level < 4) - .map((heading) => ( - - {heading.title} - - ))} - - ) : ( - {t("Headings you add to the document will appear here")} - )} + + {headings + .filter((heading) => heading.level < 4) + .map((heading) => ( + + {heading.title} + + ))} + ); } @@ -112,10 +111,6 @@ const Heading = styled.h3` margin-top: 10px; `; -const Empty = styled(Text)` - font-size: 14px; -`; - const ListItem = styled.li<{ level: number; active?: boolean }>` margin-left: ${(props) => (props.level - 1) * 10}px; margin-bottom: 8px; diff --git a/app/scenes/Document/components/Header.tsx b/app/scenes/Document/components/Header.tsx index 79a57a717..84f2cac25 100644 --- a/app/scenes/Document/components/Header.tsx +++ b/app/scenes/Document/components/Header.tsx @@ -121,7 +121,13 @@ function DocumentHeader({ const canToggleEmbeds = team?.documentEmbeds; const toc = (