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 ability to change notes grouping
thecodrr9f6d770b8549
diff --git a/apps/web/src/components/group-header/index.js b/apps/web/src/components/group-header/index.jsindex 471063adf..4d3e99836 100644--- a/apps/web/src/components/group-header/index.js+++ b/apps/web/src/components/group-header/index.js@@ -1,15 +1,100 @@-import React from "react";-import { Box, Text } from "rebass";+import * as Icon from "../icons";+import React, { useState } from "react";+import { Flex, Text } from "rebass";+import { usePersistentState } from "../../utils/hooks";+import { useStore as useNoteStore } from "../../stores/note-store";++const groups = [+ { type: undefined, title: "Default" },+ { type: "abc", title: "Alphabetic" },+ { type: "year", title: "Year" },+ { type: "week", title: "Week" },+ { type: "month", title: "Month" },+];function GroupHeader(props) {- const { title } = props;+ const { title, onExpand, isExpanded } = props;+ const [selectedGroup, setSelectedGroup] = usePersistentState(+ "selectedGroup",+ undefined+ );+ const refresh = useNoteStore((store) => store.refresh);if (!title) return null;+return (- <Box my={2} bg="bgSecondary" px={2} py={1}>- <Text variant="heading" color="primary" fontSize="subtitle">- {title}- </Text>- </Box>+ <Flex+ bg="bgSecondary"+ flexDirection="column"+ sx={{+ borderBottom: "1px solid",+ borderBottomColor: "border",+ borderBottomWidth: isExpanded ? 1 : 0,+ }}+ >+ <Flex+ //my={2}+ pl={2}+ py={1}+ alignItems="center"+ justifyContent="space-between"+ sx={{ borderBottom: "1px solid", borderBottomColor: "border" }}+ >+ <Text variant="subtitle" color="primary">+ {title}+ </Text>+ <Flex+ onClick={onExpand}+ px={1}+ sx={{+ borderRadius: "default",+ cursor: "pointer",+ ":hover": { bg: "hover" },+ }}+ >+ <Text variant="subtitle" fontWeight="normal">+ Default+ </Text>+ {isExpanded ? (+ <Icon.ChevronUp size={18} />+ ) : (+ <Icon.ChevronDown size={18} />+ )}+ </Flex>+ </Flex>+ {isExpanded && (+ <Flex flexDirection="column" py={2}>+ <Flex+ px={2}+ mb={1}+ justifyContent="space-between"+ alignItems="center"+ >+ <Text color="primary" variant="title">+ Group by+ </Text>+ <Text variant="body">Descending</Text>+ </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>);}export default GroupHeader;diff --git a/apps/web/src/components/icons/index.js b/apps/web/src/components/icons/index.jsindex d3307c15d..03ace31e4 100644--- a/apps/web/src/components/icons/index.js+++ b/apps/web/src/components/icons/index.js@@ -118,3 +118,6 @@ export const Undo = createIcon(Icons.mdiUndoVariant);export const Redo = createIcon(Icons.mdiRedoVariant);export const Filter = createIcon(Icons.mdiTune);++export const ChevronDown = createIcon(Icons.mdiChevronDown);+export const ChevronUp = createIcon(Icons.mdiChevronUp);diff --git a/apps/web/src/components/list-container/index.js b/apps/web/src/components/list-container/index.jsindex 1a20851c2..7530afc76 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 } from "react";+import React, { useEffect, useMemo, useRef, useState } from "react";import { Flex } from "rebass";import Button from "../button";import * as Icon from "../icons";@@ -13,6 +13,7 @@ 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(() => {@@ -56,33 +57,39 @@ function ListContainer(props) {overscanCount={3}estimatedItemSize={profile.estimatedItemHeight}itemSize={(index) => {- switch (index) {- default:- const item = props.items[index];- if (item.type === "header") {- if (!item.title) return 0;- return 50;- } else {- return profile.itemHeight(item);- }+ const item = props.items[index];+ if (item.type === "header") {+ if (!item.title) return 0;+ return index === expandedGroup ? 203 : 29;+ } else {+ return profile.itemHeight(item);}}}itemCount={props.items.length}>{({ index, style }) => {- switch (index) {- default:- const item = props.items[index];- return (- <div key={item.id} style={style}>- {item.type === "header" ? (- <GroupHeader title={item.title} />- ) : (- profile.item(index, item, context)- )}- </div>- );- }+ const item = props.items[index];+ return (+ <div key={item.id} style={style}>+ {item.type === "header" ? (+ <GroupHeader+ title={item.title}+ isExpanded={expandedGroup === index}+ onExpand={() => {+ setExpandedGroup((s) =>+ s === -1 ? index : -1+ );+ listRef.current.resetAfterIndex(+ index - 1,+ true+ );+ }}+ />+ ) : (+ profile.item(index, item, context)+ )}+ </div>+ );}}</List>)}diff --git a/apps/web/src/components/route-container/index.js b/apps/web/src/components/route-container/index.jsindex 1c0f2c697..c608583c0 100644--- a/apps/web/src/components/route-container/index.js+++ b/apps/web/src/components/route-container/index.js@@ -43,7 +43,7 @@ function Header(props) {if (!onlyBackButton && !title && !subtitle) return null;return (- <Flex mx={2} flexDirection="column">+ <Flex mx={2} flexDirection="column" justifyContent="center"><Flex alignItems="center" justifyContent="space-between"><Flex justifyContent="center" alignItems="center" py={2}>{canGoBack || onlyBackButton ? (diff --git a/apps/web/src/stores/note-store.js b/apps/web/src/stores/note-store.jsindex 423c5b3e8..0b4bbab38 100644--- a/apps/web/src/stores/note-store.js+++ b/apps/web/src/stores/note-store.js@@ -5,6 +5,7 @@ import { store as appStore } from "./app-store";import Vault from "../common/vault";import BaseStore from ".";import { EV } from "notes-core/common";+import Config from "../utils/config";class NoteStore extends BaseStore {notes = [];@@ -38,7 +39,9 @@ class NoteStore extends BaseStore {refresh = () => {this.refreshContext();- this.set((state) => (state.notes = db.notes.group()));+ this.set(+ (state) => (state.notes = db.notes.group(Config.get("selectedGroup")))+ );};refreshContext = () => {diff --git a/apps/web/src/theme/colorscheme/light.js b/apps/web/src/theme/colorscheme/light.jsindex 63dc9f534..b0c8059cf 100644--- a/apps/web/src/theme/colorscheme/light.js+++ b/apps/web/src/theme/colorscheme/light.js@@ -8,7 +8,7 @@ class LightColorSchemeFactory {background: "white",accent: "white",bgSecondary: "#f7f7f7",- border: "#f0f0f0",+ border: "#e7e7e7",hover: "#e0e0e0",fontSecondary: "white",text: "#202124",diff --git a/apps/web/src/utils/config.js b/apps/web/src/utils/config.jsindex 229a109e2..89756de62 100644--- a/apps/web/src/utils/config.js+++ b/apps/web/src/utils/config.js@@ -1,3 +1,5 @@+import { tryParse } from "./parse";+function set(key, value) {window.localStorage.setItem(key, JSON.stringify(value));}@@ -5,7 +7,8 @@ function set(key, value) {function get(key, def) {const value = window.localStorage.getItem(key);if (!value) return def;- return JSON.parse(value);++ return tryParse(value);}function clear() {diff --git a/apps/web/src/utils/hooks.js b/apps/web/src/utils/hooks.jsindex a454cc291..67c295448 100644--- a/apps/web/src/utils/hooks.js+++ b/apps/web/src/utils/hooks.js@@ -1,20 +1,13 @@import { useState } from "react";+import { tryParse } from "./parse";export const usePersistentState = (key, def) => {let value = window.localStorage.getItem(key) || def;const defState = tryParse(value);const [k, setKey] = useState(defState);- const _setKey = s => {+ const _setKey = (s) => {setKey(s);window.localStorage.setItem(key, s);};return [k, _setKey];};--function tryParse(val) {- try {- return JSON.parse(val);- } catch (e) {- return val;- }-}diff --git a/apps/web/src/utils/parse.js b/apps/web/src/utils/parse.jsnew file mode 100644index 000000000..c96f17880--- /dev/null+++ b/apps/web/src/utils/parse.js@@ -0,0 +1,9 @@+export function tryParse(val) {+ if (val === "undefined" || val === "null") return;++ try {+ return JSON.parse(val);+ } catch (e) {+ return val;+ }+}