Skip to content

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

feat: simplify editor toolbar buttons

thecodrr04cfb6ff6c11
diff --git a/apps/web/src/components/editor/toolbar.js b/apps/web/src/components/editor/toolbar.js
index 6a53ee846..a9ffec8b4 100644
--- a/apps/web/src/components/editor/toolbar.js
+++ b/apps/web/src/components/editor/toolbar.js
@@ -65,6 +65,19 @@ function Toolbar(props) {
}, [sessionState]);
const tools = useMemo(
+ () => [
+ {
+ title: isNotePublished ? "Published" : "Publish",
+ icon: isNotePublished ? Icon.Published : Icon.Publish,
+ hidden: !sessionId,
+ enabled: !isLocked,
+ onClick: () => showPublishView(store.get().session.id, "top"),
+ },
+ ],
+ [sessionId, isLocked, isNotePublished]
+ );
+
+ const inlineTools = useMemo(
() => [
{
title: theme === "Dark" ? "Light mode" : "Dark mode",
@@ -73,33 +86,34 @@ function Toolbar(props) {
enabled: true,
onClick: () => toggleNightMode(),
},
+
{
- title: isFullscreen ? "Exit fullscreen" : "Enter fullscreen",
- icon: isFullscreen ? Icon.ExitFullscreen : Icon.Fullscreen,
+ title: isFocusMode ? "Normal mode" : "Focus mode",
+ icon: isFocusMode ? Icon.NormalMode : Icon.FocusMode,
enabled: true,
- hidden: !isFocusMode,
hideOnMobile: true,
onClick: () => {
+ toggleFocusMode();
if (isFullscreen) {
exitFullscreen(document);
- } else {
- enterFullscreen(document.documentElement);
+ setIsFullscreen(false);
}
- setIsFullscreen((s) => !s);
+ if (tinymce.activeEditor) tinymce.activeEditor.focus();
},
},
{
- title: isFocusMode ? "Normal mode" : "Focus mode",
- icon: isFocusMode ? Icon.NormalMode : Icon.FocusMode,
+ title: isFullscreen ? "Exit fullscreen" : "Enter fullscreen",
+ icon: isFullscreen ? Icon.ExitFullscreen : Icon.Fullscreen,
enabled: true,
+ hidden: !isFocusMode,
hideOnMobile: true,
onClick: () => {
- toggleFocusMode();
if (isFullscreen) {
exitFullscreen(document);
- setIsFullscreen(false);
+ } else {
+ enterFullscreen(document.documentElement);
}
- if (tinymce.activeEditor) tinymce.activeEditor.focus();
+ setIsFullscreen((s) => !s);
},
},
{
@@ -116,13 +130,6 @@ function Toolbar(props) {
hidden: !sessionId,
onClick: () => tinymce.activeEditor.execCommand("Redo"),
},
- {
- title: isNotePublished ? "Published" : "Publish",
- icon: isNotePublished ? Icon.Published : Icon.Publish,
- hidden: !sessionId,
- enabled: !isLocked,
- onClick: () => showPublishView(store.get().session.id, "top"),
- },
{
title: "Properties",
icon: Icon.Properties,
@@ -138,10 +145,8 @@ function Toolbar(props) {
toggleFocusMode,
toggleProperties,
isFocusMode,
- isLocked,
theme,
toggleNightMode,
- isNotePublished,
sessionId,
]
);
@@ -194,16 +199,16 @@ function Toolbar(props) {
}}
/>
</Flex>
- <Flex alignItems="center" justifyContent="flex-end">
+ <Flex>
{tools.map((tool) => (
<Button
data-test-id={tool.title.toLowerCase().replace(/ /g, "-")}
disabled={!tool.enabled}
variant="tool"
flexShrink={0}
- ml={2}
title={tool.title}
key={tool.title}
+ mr={1}
sx={{
display: [
tool.hideOnMobile ? "none" : "flex",
@@ -220,22 +225,54 @@ function Toolbar(props) {
<Text display={["none", "none", "block"]} variant="body" ml={1}>
{tool.title}
</Text>
- {tool.new && (
- <Text
- variant="subBody"
- fontSize={10}
- ml={1}
- bg="primary"
- color="static"
- px={"3px"}
- py="1px"
- sx={{ borderRadius: "default" }}
- >
- NEW
- </Text>
- )}
</Button>
))}
+ <Flex
+ alignItems="center"
+ justifyContent="flex-end"
+ bg="bgSecondary"
+ sx={{ borderRadius: "default", overflow: "hidden" }}
+ >
+ {inlineTools.map((tool) => (
+ <Button
+ data-test-id={tool.title.toLowerCase().replace(/ /g, "-")}
+ disabled={!tool.enabled}
+ variant="tool"
+ bg="transparent"
+ flexShrink={0}
+ title={tool.title}
+ key={tool.title}
+ sx={{
+ borderRadius: 0,
+ display: [
+ tool.hideOnMobile ? "none" : "flex",
+ tool.hidden ? "none" : "flex",
+ ],
+ color: tool.enabled ? "text" : "disabled",
+ cursor: tool.enabled ? "pointer" : "not-allowed",
+ }}
+ onClick={tool.onClick}
+ flexDirection="row"
+ alignItems="center"
+ >
+ <tool.icon size={18} color={tool.enabled ? "text" : "disabled"} />
+ {tool.new && (
+ <Text
+ variant="subBody"
+ fontSize={10}
+ ml={1}
+ bg="primary"
+ color="static"
+ px={"3px"}
+ py="1px"
+ sx={{ borderRadius: "default" }}
+ >
+ NEW
+ </Text>
+ )}
+ </Button>
+ ))}
+ </Flex>
</Flex>
</Flex>
);