Skip to content

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

feat: add group sorting

thecodrra54e3b4f5937
diff --git a/apps/web/src/components/group-header/index.js b/apps/web/src/components/group-header/index.js
index 4d3e99836..45da527c6 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, { useState } from "react";
+import React from "react";
import { Flex, Text } from "rebass";
import { usePersistentState } from "../../utils/hooks";
import { useStore as useNoteStore } from "../../stores/note-store";
@@ -18,6 +18,10 @@ function GroupHeader(props) {
"selectedGroup",
undefined
);
+ const [sortDirection, setSortDirection] = usePersistentState(
+ "sortDirection",
+ "desc"
+ );
const refresh = useNoteStore((store) => store.refresh);
if (!title) return null;
@@ -42,29 +46,23 @@ function GroupHeader(props) {
<Text variant="subtitle" color="primary">
{title}
</Text>
- <Flex
+ <IconButton
+ text="Default"
+ icon={
+ isExpanded ? (
+ <Icon.ChevronUp size={18} />
+ ) : (
+ <Icon.ChevronDown size={18} />
+ )
+ }
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}
+ pl={2}
+ pr={1}
mb={1}
justifyContent="space-between"
alignItems="center"
@@ -72,7 +70,21 @@ function GroupHeader(props) {
<Text color="primary" variant="title">
Group by
</Text>
- <Text variant="body">Descending</Text>
+ <IconButton
+ text={sortDirection === "desc" ? "Ascending" : "Descending"}
+ icon={
+ sortDirection === "desc" ? (
+ <Icon.SortDesc size={18} />
+ ) : (
+ <Icon.SortAsc size={18} />
+ )
+ }
+ textStyle={{ mr: 1 }}
+ onClick={() => {
+ setSortDirection(sortDirection === "desc" ? "asc" : "desc");
+ refresh();
+ }}
+ />
</Flex>
{groups.map((item) => (
<Flex
@@ -98,3 +110,23 @@ function GroupHeader(props) {
);
}
export default GroupHeader;
+
+function IconButton(props) {
+ const { text, icon, onClick, textStyle } = props;
+ return (
+ <Flex
+ onClick={onClick}
+ px={1}
+ sx={{
+ borderRadius: "default",
+ cursor: "pointer",
+ ":hover": { bg: "hover" },
+ }}
+ >
+ <Text variant="subtitle" fontWeight="normal" sx={textStyle}>
+ {text}
+ </Text>
+ {icon}
+ </Flex>
+ );
+}
diff --git a/apps/web/src/components/icons/index.js b/apps/web/src/components/icons/index.js
index 03ace31e4..f4ddf3fac 100644
--- a/apps/web/src/components/icons/index.js
+++ b/apps/web/src/components/icons/index.js
@@ -121,3 +121,6 @@ export const Filter = createIcon(Icons.mdiTune);
export const ChevronDown = createIcon(Icons.mdiChevronDown);
export const ChevronUp = createIcon(Icons.mdiChevronUp);
+
+export const SortAsc = createIcon(Icons.mdiSortAscending);
+export const SortDesc = createIcon(Icons.mdiSortDescending);
diff --git a/apps/web/src/stores/note-store.js b/apps/web/src/stores/note-store.js
index 3eb8a4981..29fca34b7 100644
--- a/apps/web/src/stores/note-store.js
+++ b/apps/web/src/stores/note-store.js
@@ -41,7 +41,11 @@ class NoteStore extends BaseStore {
refresh = () => {
this.refreshContext();
this.set(
- (state) => (state.notes = db.notes.group(Config.get("selectedGroup")))
+ (state) =>
+ (state.notes = db.notes.group(
+ Config.get("selectedGroup"),
+ Config.get("sortDirection", "desc")
+ ))
);
};