Skip to content

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

feat: a much more compact "compact mode"

thecodrr147398078276
diff --git a/apps/web/src/components/group-header/index.js b/apps/web/src/components/group-header/index.js
index ec7c51b4e..e1143eb50 100644
--- a/apps/web/src/components/group-header/index.js
+++ b/apps/web/src/components/group-header/index.js
@@ -95,6 +95,7 @@ function GroupHeader(props) {
setNotesViewMode,
setNotebooksViewMode,
]);
+ const isCompact = useMemo(() => viewMode === "compact", [viewMode]);
if (!title) return null;
@@ -117,15 +118,21 @@ function GroupHeader(props) {
p={1}
mx={1}
my={1}
- py={index > 0 ? [2, "8px"] : 1}
+ py={1}
pl={1}
pr={0}
alignItems="center"
justifyContent="space-between"
bg="bgSecondary"
- sx={{ borderRadius: "default" }}
+ sx={{
+ borderRadius: "default",
+ }}
>
- <Text variant="subtitle" color="primary">
+ <Text
+ variant="subtitle"
+ fontSize={isCompact ? "body" : "subtitle"}
+ color={"primary"}
+ >
{title}
</Text>
@@ -190,7 +197,7 @@ function IconButton(props) {
>
{text && <Text variant="body">{text}</Text>}
{props.icon && (
- <props.icon size={isMobile ? 20 : 16} sx={{ ml: text ? 1 : 0 }} />
+ <props.icon size={isMobile ? 20 : 14} sx={{ ml: text ? 1 : 0 }} />
)}
</Button>
);
diff --git a/apps/web/src/components/icons/index.js b/apps/web/src/components/icons/index.js
index 11e0c6390..12103b2fa 100644
--- a/apps/web/src/components/icons/index.js
+++ b/apps/web/src/components/icons/index.js
@@ -2,7 +2,6 @@ import React, { useState } from "react";
import MDIIcon from "@mdi/react";
import {
mdiPlus,
- mdiHomeVariantOutline,
mdiMinus,
mdiBookOutline,
mdiNotebookOutline,
@@ -11,11 +10,9 @@ import {
mdiArrowDown,
mdiBookPlusMultipleOutline,
mdiBookmarkOutline,
- mdiAlert,
mdiShieldOutline,
mdiLockOpenOutline,
mdiLockOutline,
- mdiStar,
mdiStarOutline,
mdiCircle,
mdiCircleOutline,
diff --git a/apps/web/src/components/list-item/index.js b/apps/web/src/components/list-item/index.js
index 108362529..df2399ed2 100644
--- a/apps/web/src/components/list-item/index.js
+++ b/apps/web/src/components/list-item/index.js
@@ -152,9 +152,8 @@ function ListItem(props) {
openContextMenu(e, menuItems, props.menu?.extraData, false)
}
p={2}
- py={isCompact ? 2 : 3}
+ py={isCompact ? 1 : 2}
tabIndex={0}
- justifyContent="center"
sx={{
height: "inherit",
cursor: "pointer",
@@ -175,7 +174,9 @@ function ListItem(props) {
onKeyPress={(e) => {
if (e.key === "Enter") e.target.click();
}}
- flexDirection="column"
+ flexDirection={isCompact ? "row" : "column"}
+ justifyContent={isCompact ? "space-between" : "center"}
+ alignItems={isCompact ? "center" : undefined}
onClick={() => {
//e.stopPropagation();
if (isSelectionMode) {
@@ -186,17 +187,15 @@ function ListItem(props) {
}}
data-test-id={`${props.item.type}-${props.index}`}
>
- {props.header}
+ {!isCompact && props.header}
<Text
data-test-id={`${props.item.type}-${props.index}-title`}
variant={isCompact ? "subtitle" : "title"}
- fontWeight={"bold"}
+ fontWeight={isCompact ? "body" : "bold"}
color={text}
display={isSelectionMode ? "flex" : "block"}
sx={{
- lineHeight: "1.4rem",
- maxHeight: "1.4rem", // 1 lines, i hope
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis",
@@ -229,7 +228,11 @@ function ListItem(props) {
{props.body}
</Text>
)}
- {props.footer && <Box mt={isCompact ? 0 : 1}>{props.footer}</Box>}
+ {props.footer ? (
+ <Box flexShrink={0} ml={isCompact ? 1 : 0} mt={isCompact ? 0 : 1}>
+ {props.footer}
+ </Box>
+ ) : null}
</Flex>
);
}
diff --git a/apps/web/src/components/note/index.js b/apps/web/src/components/note/index.js
index b0f82dc1e..c5b06a13b 100644
--- a/apps/web/src/components/note/index.js
+++ b/apps/web/src/components/note/index.js
@@ -1,7 +1,7 @@
import React, { useMemo } from "react";
import { Flex, Text } from "rebass";
import * as Icon from "../icons";
-import TimeAgo from "timeago-react";
+import TimeAgo from "../time-ago";
import ListItem from "../list-item";
import { showMoveNoteDialog } from "../../common/dialog-controller";
import { store, useStore } from "../../stores/note-store";
@@ -35,11 +35,13 @@ function Note(props) {
return notebook;
}, [note.notebooks]);
+ const isCompact = useMemo(() => viewMode === "compact", [viewMode]);
+
return (
<ListItem
selectable
isFocused={isOpened}
- isCompact={viewMode === "compact"}
+ isCompact={isCompact}
item={note}
title={note.title}
body={note.headline}
@@ -101,37 +103,56 @@ function Note(props) {
color: isOpened ? "bgSecondaryText" : "fontTertiary",
}}
>
- {note.conflicted && (
- <Text
- display="flex"
- mr={1}
- fontSize="subBody"
- color="error"
- fontWeight="bold"
- sx={{ borderRadius: "default" }}
- >
- <Icon.Alert size={15} color="error" sx={{ mr: "2px" }} />{" "}
- Conflicted
- </Text>
- )}
- <TimeAgo
- live={false}
- datetime={note.dateCreated}
- style={{ marginRight: 5 }}
- />
- {note.pinned && !props.context && (
- <Icon.Pin size={13} color={primary} sx={{ mr: 1 }} />
- )}
- {note.locked && (
- <Icon.Lock
- size={13}
- color={"fontTertiary"}
- sx={{ mr: 1 }}
- data-test-id={`note-${index}-locked`}
- />
- )}
- {note.favorite && (
- <Icon.Star color={primary} size={15} sx={{ mr: 1 }} />
+ {isCompact ? (
+ <>
+ {note.conflicted && (
+ <Icon.Alert size={15} color="error" sx={{ mr: 1 }} />
+ )}
+ {note.locked && (
+ <Icon.Lock
+ size={11}
+ color={"fontTertiary"}
+ sx={{ mr: 1 }}
+ data-test-id={`note-${index}-locked`}
+ />
+ )}
+ <TimeAgo
+ live={false}
+ datetime={note.dateCreated}
+ locale="short"
+ />
+ </>
+ ) : (
+ <>
+ {note.conflicted && (
+ <Text
+ display="flex"
+ mr={1}
+ fontSize="subBody"
+ color="error"
+ fontWeight="bold"
+ sx={{ borderRadius: "default" }}
+ >
+ <Icon.Alert size={15} color="error" sx={{ mr: "2px" }} />{" "}
+ Conflicted
+ </Text>
+ )}
+ <TimeAgo live={false} datetime={note.dateCreated} mr={1} />
+ {note.pinned && !props.context && (
+ <Icon.Pin size={13} color={primary} sx={{ mr: 1 }} />
+ )}
+ {note.locked && (
+ <Icon.Lock
+ size={13}
+ color={"fontTertiary"}
+ sx={{ mr: 1 }}
+ data-test-id={`note-${index}-locked`}
+ />
+ )}
+ {note.favorite && (
+ <Icon.Star color={primary} size={15} sx={{ mr: 1 }} />
+ )}
+ </>
)}
</Flex>
}
diff --git a/apps/web/src/components/notebook/index.js b/apps/web/src/components/notebook/index.js
index 3a099bc1e..d7023c996 100644
--- a/apps/web/src/components/notebook/index.js
+++ b/apps/web/src/components/notebook/index.js
@@ -14,13 +14,12 @@ import { showToast } from "../../utils/toast";
function Notebook(props) {
const { item, index } = props;
const notebook = item;
-
- const viewMode = useStore((store) => store.viewMode);
+ const isCompact = useStore((store) => store.viewMode === "compact");
return (
<ListItem
selectable
- isCompact={viewMode === "compact"}
+ isCompact={isCompact}
item={notebook}
onClick={() => {
navigate(`/notebooks/${notebook.id}`);
@@ -30,45 +29,53 @@ function Notebook(props) {
index={index}
menu={{ items: menuItems, extraData: { notebook } }}
footer={
- <>
- {notebook?.topics && (
- <Flex mb={1}>
- {notebook?.topics.slice(0, 3).map((topic) => (
- <IconTag
- key={topic.id}
- text={topic.title}
- icon={Icon.Topic}
- onClick={(e) => {
- navigate(`/notebooks/${notebook.id}/${topic.id}`);
- }}
- />
- ))}
- </Flex>
- )}
- <Flex
- sx={{ fontSize: "subBody", color: "fontTertiary" }}
- alignItems="center"
- >
- {notebook.pinned && (
- <Icon.PinFilled color="primary" size={13} sx={{ mr: 1 }} />
- )}
- <Text variant="subBody" color="primary">
- Notebook
- </Text>
- <Text as="span" mx={1}>
- •
+ isCompact ? (
+ <>
+ <Text fontSize="subBody" color="fontTertiary">
+ {getTotalNotes(notebook)} Notes
</Text>
- {new Date(notebook.dateCreated).toLocaleDateString("en", {
- month: "long",
- day: "2-digit",
- year: "numeric",
- })}
- <Text as="span" mx={1}>
- •
- </Text>
- <Text>{getTotalNotes(notebook)} Notes</Text>
- </Flex>
- </>
+ </>
+ ) : (
+ <>
+ {notebook?.topics && (
+ <Flex mb={1}>
+ {notebook?.topics.slice(0, 3).map((topic) => (
+ <IconTag
+ key={topic.id}
+ text={topic.title}
+ icon={Icon.Topic}
+ onClick={(e) => {
+ navigate(`/notebooks/${notebook.id}/${topic.id}`);
+ }}
+ />
+ ))}
+ </Flex>
+ )}
+ <Flex
+ sx={{ fontSize: "subBody", color: "fontTertiary" }}
+ alignItems="center"
+ >
+ {notebook.pinned && (
+ <Icon.PinFilled color="primary" size={13} sx={{ mr: 1 }} />
+ )}
+ <Text variant="subBody" color="primary">
+ Notebook
+ </Text>
+ <Text as="span" mx={1}>
+ •
+ </Text>
+ {new Date(notebook.dateCreated).toLocaleDateString("en", {
+ month: "long",
+ day: "2-digit",
+ year: "numeric",
+ })}
+ <Text as="span" mx={1}>
+ •
+ </Text>
+ <Text>{getTotalNotes(notebook)} Notes</Text>
+ </Flex>
+ </>
+ )
}
/>
);
diff --git a/apps/web/src/components/status-bar/index.js b/apps/web/src/components/status-bar/index.js
index 0abfb0ac3..4a10c79b3 100644
--- a/apps/web/src/components/status-bar/index.js
+++ b/apps/web/src/components/status-bar/index.js
@@ -3,7 +3,7 @@ import EditorFooter from "../editor/footer";
import { Circle, Sync, Loading, Update, SyncError, Checkmark } from "../icons";
import { useStore as useUserStore } from "../../stores/user-store";
import { useStore as useAppStore } from "../../stores/app-store";
-import TimeAgo from "timeago-react";
+import TimeAgo from "../time-ago";
import { hardNavigate, hashNavigate, navigate } from "../../navigation";
import useAutoUpdater from "../../hooks/use-auto-updater";
import downloadUpdate from "../../commands/download-update";
diff --git a/apps/web/src/components/time-ago/index.js b/apps/web/src/components/time-ago/index.js
new file mode 100644
index 000000000..015d956a8
--- /dev/null
+++ b/apps/web/src/components/time-ago/index.js
@@ -0,0 +1,65 @@
+import React, { useEffect, useRef } from "react";
+import { Text } from "rebass";
+import { register, format, cancel, render } from "timeago.js";
+
+const shortLocale = [
+ ["now", "now"],
+ ["%ss", "in %ss"],
+ ["1m", "in 1m"],
+ ["%sm", "in %sm"],
+ ["1h", "in 1h"],
+ ["%sh", "in %sh"],
+ ["1d", "in 1d"],
+ ["%sd", "in %sd"],
+ ["1w", "in 1w"],
+ ["%sw", "in %sw"],
+ ["1mo", "in 1mo"],
+ ["%smo", "in %smo"],
+ ["1yr", "in 1yr"],
+ ["%syr", "in %syr"],
+];
+register("short", (_n, index) => shortLocale[index]);
+
+function TimeAgo({ datetime, live, locale, opts, ...restProps }) {
+ const timeRef = useRef();
+ useEffect(() => {
+ const element = timeRef.current;
+ if (!element) return;
+
+ // cancel all the interval
+ cancel(element);
+ // if is live
+ if (live !== false) {
+ // live render
+ element.setAttribute("datetime", toTime(datetime));
+ render(element, locale, opts);
+ }
+
+ return () => {
+ cancel(element);
+ };
+ }, [datetime, live, locale, opts]);
+
+ return (
+ <Text {...restProps} as="time" dateTime={toTime(datetime)}>
+ {format(datetime, locale, opts)}
+ </Text>
+ );
+}
+
+export default React.memo(TimeAgo);
+
+/**
+ * Convert input to a valid datetime string of <time> tag
+ * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time
+ * @param input
+ * @returns datetime string
+ */
+const toTime = (input) => {
+ let date = null; // new Date();
+ if (input instanceof Date) {
+ date = input;
+ } else date = new Date(input);
+
+ return date.getTime();
+};
diff --git a/apps/web/src/components/trash-item/index.js b/apps/web/src/components/trash-item/index.js
index 18c33139e..1d48d083b 100644
--- a/apps/web/src/components/trash-item/index.js
+++ b/apps/web/src/components/trash-item/index.js
@@ -4,7 +4,7 @@ import { confirm } from "../../common/dialog-controller";
import * as Icon from "../icons";
import { store } from "../../stores/trash-store";
import { Flex, Text } from "rebass";
-import TimeAgo from "timeago-react";
+import TimeAgo from "../time-ago";
import { toTitleCase } from "../../utils/string";
import { showToast } from "../../utils/toast";
import { showPermanentDeleteToast } from "../../common/toasts";