Skip to content

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

feat: add compact/detailed view mode toggle

thecodrr7a4ceb9a4000
diff --git a/apps/web/src/components/group-header/index.js b/apps/web/src/components/group-header/index.js
index 19b237f18..e7ec951f9 100644
--- a/apps/web/src/components/group-header/index.js
+++ b/apps/web/src/components/group-header/index.js
@@ -4,7 +4,8 @@ import { Button, Flex, Text } from "rebass";
import Animated from "../animated";
import { db } from "../../common/db";
import { useOpenContextMenu } from "../../utils/useContextMenu";
-import { useStore as useSettingsStore } from "../../stores/setting-store";
+import { useStore as useNoteStore } from "../../stores/note-store";
+import { useStore as useNotebookStore } from "../../stores/notebook-store";
import useMobile from "../../utils/use-mobile";
const groupByToTitleMap = {
@@ -49,7 +50,7 @@ function changeGroupOptions({ groupOptions, type, refresh }, { key: itemKey }) {
if (key === "groupBy") {
if (value === "abc") groupOptions.sortBy = "title";
else groupOptions.sortBy = "dateEdited";
-}
+ }
db.settings.setGroupOptions(type, groupOptions);
refresh();
}
@@ -76,6 +77,24 @@ function GroupHeader(props) {
const { title, groups, onJump, index, type, refresh } = props;
const groupOptions = useMemo(() => db.settings.getGroupOptions(type), [type]);
const openContextMenu = useOpenContextMenu();
+ const notesViewMode = useNoteStore((store) => store.viewMode);
+ const setNotesViewMode = useNoteStore((store) => store.setViewMode);
+ const notebooksViewMode = useNotebookStore((store) => store.viewMode);
+ const setNotebooksViewMode = useNotebookStore((store) => store.setViewMode);
+
+ const [viewMode, setViewMode] = useMemo(() => {
+ if (type === "home" || type === "notes" || type === "favorites") {
+ return [notesViewMode, setNotesViewMode];
+ } else if (type === "notebooks")
+ return [notebooksViewMode, setNotebooksViewMode];
+ else return null;
+ }, [
+ type,
+ notesViewMode,
+ notebooksViewMode,
+ setNotesViewMode,
+ setNotebooksViewMode,
+ ]);
if (!title) return null;
@@ -99,16 +118,16 @@ function GroupHeader(props) {
mx={1}
my={1}
py={index > 0 ? [2, "8px"] : 1}
- alignItems="center"
- justifyContent="space-between"
+ alignItems="center"
+ justifyContent="space-between"
bg="bgSecondary"
sx={{ borderRadius: "default" }}
- >
- <Text variant="subtitle" color="primary">
- {title}
- </Text>
+ >
+ <Text variant="subtitle" color="primary">
+ {title}
+ </Text>
- {index === 0 && (
+ {index === 0 && (
<Flex mr={1}>
<IconButton
icon={
@@ -127,37 +146,22 @@ function GroupHeader(props) {
});
}}
/>
- )}
- </Flex>
- <Flex
- flexDirection="column"
- p={menuType === "jumpto" ? 2 : 0}
- pt={2}
- style={{
- display: isExpanded ? "flex" : "none",
- }}
- justifyContent="center"
- sx={{
- position: "absolute",
- zIndex: 1,
- bg: "bgSecondary",
- width: "100%",
- top: "29px",
- borderBottom: "1px solid",
- borderBottomColor: "border",
- borderBottomWidth: 1,
- boxShadow: "0px 3px 6px 0px #0000005e",
- }}
- >
- <JumpToGroupMenu
- onJump={(title) => {
- setIsExpanded(false);
- onJump(title);
- }}
- isVisible={menuType === "jumpto"}
- groups={groups}
- />
- </Flex>
+ {viewMode && (
+ <IconButton
+ icon={
+ viewMode === "compact" ? Icon.DetailedView : Icon.CompactView
+ }
+ title={
+ viewMode === "compact"
+ ? "Switch to detailed view"
+ : "Switch to compact view"
+ }
+ onClick={(e) =>
+ setViewMode(viewMode === "compact" ? "detailed" : "compact")
+ }
+ />
+ )}
+ </Flex>
)}
</Animated.Flex>
);
@@ -185,7 +189,7 @@ function IconButton(props) {
{text && <Text variant="body">{text}</Text>}
{props.icon && (
<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 d7b25521a..bcf8ba3d9 100644
--- a/apps/web/src/components/icons/index.js
+++ b/apps/web/src/components/icons/index.js
@@ -158,3 +158,6 @@ export const Rocket = createIcon(Icons.mdiRocketLaunchOutline);
export const Share = createIcon(Icons.mdiShareVariantOutline);
export const Password = createIcon(Icons.mdiFormTextboxPassword);
export const Destruct = createIcon(Icons.mdiBomb);
+
+export const CompactView = createIcon(Icons.mdiViewHeadline);
+export const DetailedView = createIcon(Icons.mdiViewSequentialOutline);
diff --git a/apps/web/src/components/list-item/index.js b/apps/web/src/components/list-item/index.js
index d92bdb61e..f6689a13b 100644
--- a/apps/web/src/components/list-item/index.js
+++ b/apps/web/src/components/list-item/index.js
@@ -69,6 +69,7 @@ function ListItem(props) {
background: "background",
},
isFocused,
+ isCompact,
} = props;
const isSelectionMode = useSelectionStore((store) => store.isSelectionMode);
@@ -123,12 +124,11 @@ function ListItem(props) {
openContextMenu(e, menuItems, props.menu?.extraData, false)
}
p={2}
+ py={isCompact ? 2 : 3}
tabIndex={props.index}
justifyContent="center"
sx={{
height: "inherit",
- borderBottom: "1px solid",
- borderBottomColor: "border",
cursor: "pointer",
position: "relative",
borderLeft: isFocused ? "3px solid" : "none",
@@ -160,47 +160,48 @@ function ListItem(props) {
>
{props.header}
- <Text
+ <Text
data-test-id={`${props.item.type}-${props.index}-title`}
- fontWeight={"bold"}
+ variant={isCompact ? "subtitle" : "title"}
+ fontWeight={"bold"}
color={text}
display={isSelectionMode ? "flex" : "block"}
- sx={{
- lineHeight: "1.4rem",
- maxHeight: "1.4rem", // 1 lines, i hope
- whiteSpace: "nowrap",
- overflow: "hidden",
- textOverflow: "ellipsis",
- }}
- >
+ sx={{
+ lineHeight: "1.4rem",
+ maxHeight: "1.4rem", // 1 lines, i hope
+ whiteSpace: "nowrap",
+ overflow: "hidden",
+ textOverflow: "ellipsis",
+ }}
+ >
{isSelectionMode && (
<ItemSelector
isSelected={isSelected}
toggleSelection={toggleSelection}
/>
)}
- {props.title}
- </Text>
+ {props.title}
+ </Text>
- {props.body && (
- <Text
- as="p"
- variant="body"
+ {!isCompact && props.body && (
+ <Text
+ as="p"
+ variant="body"
data-test-id={`${props.item.type}-${props.index}-body`}
- sx={{
+ sx={{
lineHeight: `1.2rem`,
- overflow: "hidden",
- textOverflow: "ellipsis",
+ overflow: "hidden",
+ textOverflow: "ellipsis",
position: "relative",
display: "-webkit-box",
WebkitLineClamp: 4,
WebkitBoxOrient: "vertical",
- }}
- >
- {props.body}
- </Text>
+ }}
+ >
+ {props.body}
+ </Text>
)}
- {props.footer && <Box mt={1}>{props.footer}</Box>}
+ {props.footer && <Box mt={isCompact ? 0 : 1}>{props.footer}</Box>}
</Flex>
);
}
diff --git a/apps/web/src/components/note/index.js b/apps/web/src/components/note/index.js
index cbaacc7c6..59f080c84 100644
--- a/apps/web/src/components/note/index.js
+++ b/apps/web/src/components/note/index.js
@@ -21,6 +21,7 @@ function Note(props) {
const { item, index, context } = props;
const note = item;
const selectedNote = useStore((store) => store.selectedNote);
+ const viewMode = useStore((store) => store.viewMode);
const isOpened = selectedNote === note.id;
const [shade, primary] = useMemo(() => {
@@ -40,6 +41,7 @@ function Note(props) {
<ListItem
selectable
isFocused={isOpened}
+ isCompact={viewMode === "compact"}
item={note}
title={note.title}
body={note.headline}
diff --git a/apps/web/src/components/notebook/index.js b/apps/web/src/components/notebook/index.js
index 9fcda0f08..ab23536b2 100644
--- a/apps/web/src/components/notebook/index.js
+++ b/apps/web/src/components/notebook/index.js
@@ -1,7 +1,7 @@
import React from "react";
import { Flex, Text } from "rebass";
import ListItem from "../list-item";
-import { store } from "../../stores/notebook-store";
+import { useStore, store } from "../../stores/notebook-store";
import { store as appStore } from "../../stores/app-store";
import { showItemDeletedToast, showUnpinnedToast } from "../../common/toasts";
import { db } from "../../common/db";
@@ -10,72 +10,72 @@ import { hashNavigate, navigate } from "../../navigation";
import { getTotalNotes } from "../../common";
import IconTag from "../icon-tag";
-class Notebook extends React.Component {
- shouldComponentUpdate(nextProps) {
- const prevItem = this.props.item;
- const nextItem = nextProps.item;
- return (
- prevItem.pinned !== nextItem.pinned ||
- prevItem.title !== nextItem.title ||
- prevItem.description !== nextItem.description ||
- prevItem.topics.length !== nextItem.topics.length
- );
- }
- render() {
- const { item, index } = this.props;
- const notebook = item;
+function Notebook(props) {
+ const { item, index } = props;
+ const notebook = item;
- return (
- <ListItem
- selectable
- item={notebook}
- onClick={() => {
- navigate(`/notebooks/${notebook.id}`);
- }}
- title={notebook.title}
- body={notebook.description}
- 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 }} />
- )}
- {new Date(notebook.dateCreated).toLocaleDateString("en", {
- month: "long",
- day: "2-digit",
- year: "numeric",
- })}
- <Text as="span" mx={1}>
- •
- </Text>
- <Text>{getTotalNotes(notebook)} Notes</Text>
+ const viewMode = useStore((store) => store.viewMode);
+
+ return (
+ <ListItem
+ selectable
+ isCompact={viewMode === "compact"}
+ item={notebook}
+ onClick={() => {
+ navigate(`/notebooks/${notebook.id}`);
+ }}
+ title={notebook.title}
+ body={notebook.description}
+ 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 }} />
+ )}
+ {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>
+ </>
+ }
+ />
+ );
}
-export default Notebook;
+export default React.memo(Notebook, (prev, next) => {
+ const prevItem = prev.item;
+ const nextItem = next.item;
+ return (
+ prevItem.pinned === nextItem.pinned ||
+ prevItem.title === nextItem.title ||
+ prevItem.description === nextItem.description ||
+ prevItem.topics.length === nextItem.topics.length
+ );
+});
const pin = async (notebook) => {
await store.pin(notebook);
diff --git a/apps/web/src/stores/note-store.js b/apps/web/src/stores/note-store.js
index d0fd442b5..6169339b1 100644
--- a/apps/web/src/stores/note-store.js
+++ b/apps/web/src/stores/note-store.js
@@ -16,6 +16,12 @@ class NoteStore extends BaseStore {
notes = [];
context = undefined;
selectedNote = 0;
+ viewMode = Config.get("notes:viewMode", "detailed");
+
+ setViewMode = (viewMode) => {
+ this.set((state) => (state.viewMode = viewMode));
+ Config.set("notes:viewMode", viewMode);
+ };
init = () => {
EV.subscribe(EVENTS.noteRemoved, (id) => {
diff --git a/apps/web/src/stores/notebook-store.js b/apps/web/src/stores/notebook-store.js
index 7f2026691..d1cb8cba5 100644
--- a/apps/web/src/stores/notebook-store.js
+++ b/apps/web/src/stores/notebook-store.js
@@ -5,11 +5,18 @@ import { store as noteStore } from "./note-store";
import BaseStore from "./index";
import { showToast } from "../utils/toast";
import { groupArray } from "notes-core/utils/grouping";
+import Config from "../utils/config";
class NotebookStore extends BaseStore {
notebooks = [];
selectedNotebookTopics = [];
selectedNotebookId = 0;
+ viewMode = Config.get("notebooks:viewMode", "detailed");
+
+ setViewMode = (viewMode) => {
+ this.set((state) => (state.viewMode = viewMode));
+ Config.set("notebooks:viewMode", viewMode);
+ };
refresh = () => {
this.set((state) => {