Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: toc improvements (#4977) (#6818)

01zulfifa1f64f50588
diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsx
index fdb95ece3..792a67c70 100644
--- a/apps/web/src/components/editor/index.tsx
+++ b/apps/web/src/components/editor/index.tsx
@@ -204,14 +204,20 @@ export default function TabsView() {
</Panel>
</>
)}
+
+ {isTOCVisible && activeSessionId && (
+ <>
+ <PanelResizeHandle className="panel-resize-handle" />
+ <Panel id="toc-panel" order={3} defaultSize={25} minSize={15}>
+ <TableOfContents sessionId={activeSessionId} />
+ </Panel>
+ </>
+ )}
</PanelGroup>
<DropZone overlayRef={overlayRef} />
{arePropertiesVisible && activeSessionId && (
<Properties sessionId={activeSessionId} />
)}
- {isTOCVisible && activeSessionId && (
- <TableOfContents sessionId={activeSessionId} />
- )}
</ScopedThemeProvider>
</>
);
diff --git a/apps/web/src/components/editor/table-of-contents.tsx b/apps/web/src/components/editor/table-of-contents.tsx
index edc2d59b7..c139cab55 100644
--- a/apps/web/src/components/editor/table-of-contents.tsx
+++ b/apps/web/src/components/editor/table-of-contents.tsx
@@ -37,9 +37,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import React, { useEffect, useState } from "react";
-import { ArrowLeft } from "../icons";
+import { Cross } from "../icons";
import { useEditorStore } from "../../stores/editor-store";
-import { AnimatedFlex } from "../animated";
import ScrollContainer from "../scroll-container";
import { ScopedThemeProvider } from "../theme-provider";
import { Section } from "../properties";
@@ -87,25 +86,12 @@ function TableOfContents(props: TableOfContentsProps) {
}, [sessionId, tableOfContents]);
return (
- <AnimatedFlex
- animate={{
- x: 0
- }}
- transition={{
- duration: 0.1,
- bounceDamping: 1,
- bounceStiffness: 1,
- ease: "easeOut"
- }}
- initial={{ x: 600 }}
+ <Flex
sx={{
display: "flex",
- position: "absolute",
- right: 0,
top: TITLE_BAR_HEIGHT,
zIndex: 999,
height: "100%",
- width: "300px",
borderLeft: "1px solid",
borderLeftColor: "border"
}}
@@ -124,8 +110,9 @@ function TableOfContents(props: TableOfContentsProps) {
<ScrollContainer>
<Section
title={strings.toc()}
+ buttonPosition="right"
button={
- <ArrowLeft
+ <Cross
data-test-id="toc-close"
onClick={() => toggleTableOfContents(false)}
size={18}
@@ -150,7 +137,7 @@ function TableOfContents(props: TableOfContentsProps) {
key={t.id}
sx={{
textAlign: "left",
- paddingLeft: `${t.level * 5 + (t.level - 1) * 5}px`,
+ paddingLeft: `${t.level * 10 + (t.level - 1) * 10}px`,
py: 1,
pr: 1,
borderLeft: "5px solid transparent",
@@ -171,7 +158,7 @@ function TableOfContents(props: TableOfContentsProps) {
</Section>
</ScrollContainer>
</ScopedThemeProvider>
- </AnimatedFlex>
+ </Flex>
);
}
export default React.memo(TableOfContents);
diff --git a/apps/web/src/components/properties/index.tsx b/apps/web/src/components/properties/index.tsx
index 23ed47c04..5b870173c 100644
--- a/apps/web/src/components/properties/index.tsx
+++ b/apps/web/src/components/properties/index.tsx
@@ -715,11 +715,17 @@ function SessionHistory({ noteId }: { noteId: string }) {
);
}
-type SectionProps = { title: string; subtitle?: string; button?: JSX.Element };
+type SectionProps = {
+ title: string;
+ subtitle?: string;
+ button?: JSX.Element;
+ buttonPosition?: "left" | "right";
+};
export function Section({
title,
subtitle,
button,
+ buttonPosition = "left",
children
}: PropsWithChildren<SectionProps>) {
return (
@@ -729,9 +735,18 @@ export function Section({
flexDirection: "column"
}}
>
- <Flex mx={1} mt={2} sx={{ alignItems: "center" }}>
- {button}
+ <Flex
+ mx={1}
+ mt={2}
+ sx={{
+ alignItems: "center",
+ justifyContent:
+ buttonPosition === "right" ? "space-between" : "flex-start"
+ }}
+ >
+ {buttonPosition === "left" && button}
<Text variant="subtitle">{title}</Text>
+ {buttonPosition === "right" && button}
</Flex>
{subtitle && (
<Text variant="subBody" mb={1} mx={1}>
diff --git a/apps/web/src/stores/editor-store.ts b/apps/web/src/stores/editor-store.ts
index 2067cca9c..e02c62b3f 100644
--- a/apps/web/src/stores/editor-store.ts
+++ b/apps/web/src/stores/editor-store.ts
@@ -166,7 +166,7 @@ class EditorStore extends BaseStore<EditorStore> {
arePropertiesVisible = false;
documentPreview?: DocumentPreview;
- isTOCVisible = false;
+ isTOCVisible = Config.get("editor:toc", false);
editorMargins = Config.get("editor:margins", true);
history: string[] = [];
@@ -935,11 +935,11 @@ class EditorStore extends BaseStore<EditorStore> {
};
toggleTableOfContents = (toggleState?: boolean) => {
- this.set(
- (state) =>
- (state.isTOCVisible =
- toggleState !== undefined ? toggleState : !state.isTOCVisible)
- );
+ this.set((state) => {
+ state.isTOCVisible =
+ toggleState !== undefined ? toggleState : !state.isTOCVisible;
+ Config.set("editor:toc", !state.isTOCVisible);
+ });
};
toggleEditorMargins = (toggleState?: boolean) => {