Skip to content

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

feat: improve jumped to group visibility

thecodrr3efb9063c2f5
diff --git a/apps/web/src/components/group-header/index.js b/apps/web/src/components/group-header/index.js
index 9c7f13398..1c7981783 100644
--- a/apps/web/src/components/group-header/index.js
+++ b/apps/web/src/components/group-header/index.js
@@ -1,8 +1,10 @@
import * as Icon from "../icons";
import React, { useState } from "react";
import { Flex, Text } from "rebass";
+import Animated from "../animated";
import { usePersistentState } from "../../utils/hooks";
import { useStore as useNoteStore } from "../../stores/note-store";
+import { useTheme } from "emotion-theming";
const groups = [
{ type: undefined, title: "Default" },
@@ -17,17 +19,24 @@ function getGroupTitleByType(type) {
}
function GroupHeader(props) {
- const { title, groups, onJump } = props;
+ const { title, groups, onJump, wasJumpedTo, index } = props;
const [selectedGroup] = usePersistentState("selectedGroup", undefined);
const [isExpanded, setIsExpanded] = useState(false);
const [menuType, setMenuType] = useState();
+ const theme = useTheme();
if (!title) return null;
return (
- <Flex
- bg="bgSecondary"
+ <Animated.Flex
+ bg={"bgSecondary"}
flexDirection="column"
sx={{ cursor: "pointer" }}
+ animate={{
+ backgroundColor: wasJumpedTo
+ ? theme.colors["dimPrimary"]
+ : "bgSecondary",
+ }}
+ transition={{ duration: 0.3, repeatType: "reverse", repeat: 3 }}
onClick={() => {
if (groups.length <= 0) return;
setMenuType("jumpto");
@@ -45,21 +54,22 @@ function GroupHeader(props) {
<Text variant="subtitle" color="primary">
{title}
</Text>
- <IconButton
- text={getGroupTitleByType(selectedGroup)}
- icon={
- isExpanded ? (
- <Icon.ChevronUp size={18} />
- ) : (
- <Icon.ChevronDown size={18} />
- )
- }
- onClick={(e) => {
- e.stopPropagation();
- setMenuType("groupby");
- setIsExpanded((s) => !s);
- }}
- />
+ {index === 0 && (
+ <IconButton
+ text={getGroupTitleByType(selectedGroup)}
+ icon={
+ isExpanded ? (
+ <Icon.ChevronUp size={18} />
+ ) : (
+ <Icon.ChevronDown size={18} />
+ )
+ }
+ onClick={() => {
+ setMenuType("groupby");
+ setIsExpanded((s) => !s);
+ }}
+ />
+ )}
</Flex>
<Flex
flexDirection="column"
@@ -81,13 +91,16 @@ function GroupHeader(props) {
}}
>
<JumpToGroupMenu
- onJump={onJump}
+ onJump={(title) => {
+ setIsExpanded(false);
+ onJump(title);
+ }}
isVisible={menuType === "jumpto"}
groups={groups}
/>
<GroupByMenu isVisible={menuType === "groupby"} />
</Flex>
- </Flex>
+ </Animated.Flex>
);
}
export default GroupHeader;
@@ -96,7 +109,10 @@ function IconButton(props) {
const { text, icon, onClick, textStyle, sx } = props;
return (
<Flex
- onClick={onClick}
+ onClick={(e) => {
+ e.stopPropagation();
+ onClick(e);
+ }}
px={1}
sx={{
borderRadius: "default",
diff --git a/apps/web/src/components/list-container/index.js b/apps/web/src/components/list-container/index.js
index 0cbf4e0ae..92faa3d74 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 [jumpToIndex, setJumpToIndex] = useState(-1);
const listRef = useRef();
useEffect(() => {
@@ -73,20 +74,26 @@ function ListContainer(props) {
{item.type === "header" ? (
<GroupHeader
title={item.title}
+ index={index}
groups={props.items.filter(
(v) =>
v.type === "header" &&
v.title !== item.title
)}
+ wasJumpedTo={index === jumpToIndex}
onJump={(title) => {
const index = props.items.findIndex(
(v) => v.title === title
);
if (index < 0) return;
+ setJumpToIndex(index);
listRef.current.scrollToItem(
index,
- "smart"
+ "center"
);
+ setTimeout(() => {
+ setJumpToIndex(-1);
+ }, 1900);
}}
/>
) : (