A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
feat: add group jumping
thecodrr7ba746f79c81
diff --git a/apps/web/src/components/group-header/index.js b/apps/web/src/components/group-header/index.jsindex 29ae16c10..9c7f13398 100644--- a/apps/web/src/components/group-header/index.js+++ b/apps/web/src/components/group-header/index.js@@ -1,5 +1,5 @@import * as Icon from "../icons";-import React from "react";+import React, { useState } from "react";import { Flex, Text } from "rebass";import { usePersistentState } from "../../utils/hooks";import { useStore as useNoteStore } from "../../stores/note-store";@@ -17,26 +17,21 @@ function getGroupTitleByType(type) {}function GroupHeader(props) {- const { title, onExpand, isExpanded } = props;- const [selectedGroup, setSelectedGroup] = usePersistentState(- "selectedGroup",- undefined- );- const [sortDirection, setSortDirection] = usePersistentState(- "sortDirection",- "desc"- );- const refresh = useNoteStore((store) => store.refresh);+ const { title, groups, onJump } = props;+ const [selectedGroup] = usePersistentState("selectedGroup", undefined);+ const [isExpanded, setIsExpanded] = useState(false);+ const [menuType, setMenuType] = useState();if (!title) return null;return (<Flexbg="bgSecondary"flexDirection="column"- sx={{- borderBottom: "1px solid",- borderBottomColor: "border",- borderBottomWidth: isExpanded ? 1 : 0,+ sx={{ cursor: "pointer" }}+ onClick={() => {+ if (groups.length <= 0) return;+ setMenuType("jumpto");+ setIsExpanded((s) => !s);}}><Flex@@ -59,64 +54,46 @@ function GroupHeader(props) {<Icon.ChevronDown size={18} />)}- onClick={onExpand}+ onClick={(e) => {+ e.stopPropagation();+ setMenuType("groupby");+ setIsExpanded((s) => !s);+ }}/></Flex>- {isExpanded && (- <Flex flexDirection="column" py={2}>- <Flex- pl={2}- pr={1}- mb={1}- justifyContent="space-between"- alignItems="center"- >- <Text color="primary" variant="title">- Group by- </Text>- <IconButton- text={sortDirection === "desc" ? "Ascending" : "Descending"}- icon={- sortDirection === "desc" ? (- <Icon.SortDesc size={14} />- ) : (- <Icon.SortAsc size={14} />- )- }- textStyle={{ mr: 1 }}- onClick={() => {- setSortDirection(sortDirection === "desc" ? "asc" : "desc");- refresh();- }}- />- </Flex>- {groups.map((item) => (- <Flex- key={item.title}- justifyContent="space-between"- p={1}- px={2}- sx={{ cursor: "pointer", ":hover": { bg: "shade" } }}- onClick={() => {- setSelectedGroup(item.type);- refresh();- }}- >- <Text variant="body">{item.title}</Text>- {selectedGroup === item.type && (- <Icon.Checkmark size={16} color="primary" />- )}- </Flex>- ))}- </Flex>- )}+ <Flex+ flexDirection="column"+ p={menuType === "jumpto" ? 2 : 0}+ pt={2}+ style={{+ display: isExpanded ? "flex" : "none",+ }}+ 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={onJump}+ isVisible={menuType === "jumpto"}+ groups={groups}+ />+ <GroupByMenu isVisible={menuType === "groupby"} />+ </Flex></Flex>);}export default GroupHeader;function IconButton(props) {- const { text, icon, onClick, textStyle } = props;+ const { text, icon, onClick, textStyle, sx } = props;return (<FlexonClick={onClick}@@ -125,6 +102,7 @@ function IconButton(props) {borderRadius: "default",cursor: "pointer",":hover": { bg: "hover" },+ ...sx,}}><Text variant="subtitle" fontWeight="normal" sx={textStyle}>@@ -134,3 +112,89 @@ function IconButton(props) {</Flex>);}++function JumpToGroupMenu(props) {+ const { groups, isVisible, onJump } = props;+ if (!isVisible) return null;+ return (+ <>+ <Text color="primary" variant="title" mb={1}>+ Jump to+ </Text>+ <Flex flexWrap="wrap">+ {groups.map((group) => (+ <IconButton+ text={group.title}+ textStyle={{ fontSize: "body" }}+ onClick={() => onJump(group.title)}+ sx={{ bg: "shade", mr: 1, mt: 1 }}+ ></IconButton>+ ))}+ </Flex>+ </>+ );+}++function GroupByMenu(props) {+ const { isVisible } = props;++ const [sortDirection, setSortDirection] = usePersistentState(+ "sortDirection",+ "desc"+ );+ const [selectedGroup, setSelectedGroup] = usePersistentState(+ "selectedGroup",+ undefined+ );+ const refresh = useNoteStore((store) => store.refresh);++ if (!isVisible) return null;+ return (+ <>+ <Flex+ pl={2}+ pr={1}+ mb={1}+ justifyContent="space-between"+ alignItems="center"+ >+ <Text color="primary" variant="title">+ Group by+ </Text>+ <IconButton+ text={sortDirection === "desc" ? "Ascending" : "Descending"}+ icon={+ sortDirection === "desc" ? (+ <Icon.SortDesc size={14} />+ ) : (+ <Icon.SortAsc size={14} />+ )+ }+ textStyle={{ mr: 1 }}+ onClick={() => {+ setSortDirection(sortDirection === "desc" ? "asc" : "desc");+ refresh();+ }}+ />+ </Flex>+ {groups.map((item) => (+ <Flex+ key={item.title}+ justifyContent="space-between"+ p={1}+ px={2}+ sx={{ cursor: "pointer", ":hover": { bg: "shade" } }}+ onClick={() => {+ setSelectedGroup(item.type);+ refresh();+ }}+ >+ <Text variant="body">{item.title}</Text>+ {selectedGroup === item.type && (+ <Icon.Checkmark size={16} color="primary" />+ )}+ </Flex>+ ))}+ </>+ );+}diff --git a/apps/web/src/components/list-container/index.js b/apps/web/src/components/list-container/index.jsindex e22bacf7b..0cbf4e0ae 100644--- a/apps/web/src/components/list-container/index.js+++ b/apps/web/src/components/list-container/index.js@@ -1,4 +1,4 @@-import React, { useEffect, useMemo, useRef, useState } from "react";+import React, { useEffect, useMemo, useRef } from "react";import { Flex } from "rebass";import Button from "../button";import * as Icon from "../icons";@@ -13,7 +13,6 @@ function ListContainer(props) {const profile = useMemo(() => ListProfiles[type], [type]);const shouldSelectAll = useSelectionStore((store) => store.shouldSelectAll);const setSelectedItems = useSelectionStore((store) => store.setSelectedItems);- const [expandedGroup, setExpandedGroup] = useState(-1);const listRef = useRef();useEffect(() => {@@ -60,7 +59,7 @@ function ListContainer(props) {const item = props.items[index];if (item.type === "header") {if (!item.title) return 0;- return index === expandedGroup ? 208 : 29;+ return 29;} else {return profile.itemHeight(item);}@@ -70,18 +69,23 @@ function ListContainer(props) {{({ index, style }) => {const item = props.items[index];return (- <div key={item.id} style={style}>+ <div key={item.id || item.title} style={style}>{item.type === "header" ? (<GroupHeadertitle={item.title}- isExpanded={expandedGroup === index}- onExpand={() => {- setExpandedGroup((s) =>- s === -1 ? index : -1+ groups={props.items.filter(+ (v) =>+ v.type === "header" &&+ v.title !== item.title+ )}+ onJump={(title) => {+ const index = props.items.findIndex(+ (v) => v.title === title);- listRef.current.resetAfterIndex(+ if (index < 0) return;+ listRef.current.scrollToItem(index,- true+ "smart");}}/>