Skip to content

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

web: make app loading animation smoother

Abdullah Atta82376c8c47c6
diff --git a/apps/web/src/app-effects.js b/apps/web/src/app-effects.js
index 345fd3a6b..485dc54b2 100644
--- a/apps/web/src/app-effects.js
+++ b/apps/web/src/app-effects.js
@@ -93,6 +93,8 @@ export default function AppEffects({ setShow }) {
initEditorStore();
(async function () {
+ await resetReminders();
+
await updateLastSynced();
if (await initUser()) {
showUpgradeReminderDialogs();
diff --git a/apps/web/src/app.js b/apps/web/src/app.js
index a0504ce58..4a5a06913 100644
--- a/apps/web/src/app.js
+++ b/apps/web/src/app.js
@@ -34,13 +34,13 @@ import NavigationMenu from "./components/navigation-menu";
import StatusBar from "./components/status-bar";
import { EditorLoader } from "./components/loaders/editor-loader";
import { FlexScrollContainer } from "./components/scroll-container";
+import CachedRouter from "./components/cached-router";
const GlobalMenuWrapper = React.lazy(() =>
import("./components/global-menu-wrapper")
);
const AppEffects = React.lazy(() => import("./app-effects"));
const MobileAppEffects = React.lazy(() => import("./app-effects.mobile"));
-const CachedRouter = React.lazy(() => import("./components/cached-router"));
const HashRouter = React.lazy(() => import("./components/hash-router"));
function App() {
@@ -136,14 +136,12 @@ function DesktopAppContents({ isAppLoaded, show, setShow }) {
visible={!isFocusMode}
priority={LayoutPriority.Low}
>
- <Flex sx={{ overflow: "hidden", flex: 1 }}>
- <NavigationMenu
- toggleNavigationContainer={(state) => {
- setShow(state || !show);
- }}
- isTablet={isNarrow}
- />
- </Flex>
+ <NavigationMenu
+ toggleNavigationContainer={(state) => {
+ setShow(state || !show);
+ }}
+ isTablet={isNarrow}
+ />
</Allotment.Pane>
<Allotment.Pane
className="pane middle-pane"
@@ -153,11 +151,7 @@ function DesktopAppContents({ isAppLoaded, show, setShow }) {
priority={LayoutPriority.Normal}
>
<Flex className="listMenu" variant="columnFill">
- <SuspenseLoader
- condition={isAppLoaded}
- component={CachedRouter}
- fallback={<ViewLoader />}
- />
+ {isAppLoaded && <CachedRouter />}
</Flex>
</Allotment.Pane>
<Allotment.Pane
@@ -171,11 +165,13 @@ function DesktopAppContents({ isAppLoaded, show, setShow }) {
flexDirection: "column"
}}
>
- <SuspenseLoader
- fallback={<EditorLoader />}
- component={HashRouter}
- condition={isAppLoaded}
- />
+ {isAppLoaded && (
+ <SuspenseLoader
+ fallback={<EditorLoader />}
+ component={HashRouter}
+ condition={isAppLoaded}
+ />
+ )}
</Flex>
</Allotment.Pane>
</Allotment>
diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsx
index fa0b0c432..cdd7759fb 100644
--- a/apps/web/src/components/editor/index.tsx
+++ b/apps/web/src/components/editor/index.tsx
@@ -47,6 +47,8 @@ import useMobile from "../../hooks/use-mobile";
import Titlebox from "./title-box";
import useTablet from "../../hooks/use-tablet";
import Config from "../../utils/config";
+import { AnimatedFlex } from "../animated";
+import { EditorLoader } from "../loaders/editor-loader";
type PreviewSession = {
content: { data: string; type: string };
@@ -241,6 +243,7 @@ export function Editor(props: EditorProps) {
focusMode: false,
isMobile: false
};
+ const [isLoading, setIsLoading] = useState(true);
const editor = useEditorInstance();
@@ -285,7 +288,7 @@ export function Editor(props: EditorProps) {
}, [editor]);
return (
- <EditorChrome {...props}>
+ <EditorChrome isLoading={isLoading} {...props}>
<Tiptap
isMobile={isMobile}
nonce={nonce}
@@ -297,6 +300,7 @@ export function Editor(props: EditorProps) {
}}
onLoad={() => {
if (onLoadMedia) onLoadMedia();
+ if (nonce && nonce > 0) setIsLoading(false);
}}
onContentChange={onContentChange}
onChange={onEditorChange}
@@ -320,8 +324,10 @@ export function Editor(props: EditorProps) {
);
}
-function EditorChrome(props: PropsWithChildren<EditorProps>) {
- const { options, children } = props;
+function EditorChrome(
+ props: PropsWithChildren<EditorProps & { isLoading: boolean }>
+) {
+ const { options, children, isLoading } = props;
const { readonly, focusMode, headless, onRequestFocus, isMobile } =
options || {
headless: false,
@@ -335,6 +341,23 @@ function EditorChrome(props: PropsWithChildren<EditorProps>) {
return (
<>
+ {isLoading ? (
+ <AnimatedFlex
+ sx={{
+ position: "absolute",
+ overflow: "hidden",
+ flex: 1,
+ flexDirection: "column",
+ width: "100%",
+ height: "100%",
+ zIndex: 999,
+ bg: "background"
+ }}
+ >
+ <EditorLoader />
+ </AnimatedFlex>
+ ) : null}
+
<Toolbar />
<FlexScrollContainer
className="editorScroll"
@@ -366,7 +389,13 @@ function EditorChrome(props: PropsWithChildren<EditorProps>) {
)}
<Titlebox readonly={readonly || false} />
<Header readonly={readonly} />
- {children}
+ <AnimatedFlex
+ initial={{ opacity: 0 }}
+ animate={{ opacity: isLoading ? 0 : 1 }}
+ transition={{ duration: 0.3, ease: "easeInOut" }}
+ >
+ {children}
+ </AnimatedFlex>
</Flex>
</FlexScrollContainer>
diff --git a/apps/web/src/components/list-container/index.tsx b/apps/web/src/components/list-container/index.tsx
index 4d404696a..d198a88f9 100644
--- a/apps/web/src/components/list-container/index.tsx
+++ b/apps/web/src/components/list-container/index.tsx
@@ -32,11 +32,12 @@ import {
Item,
ListProfiles
} from "./list-profiles";
-import ReminderBar from "../reminder-bar";
import Announcements from "../announcements";
import { ListLoader } from "../loaders/list-loader";
import ScrollContainer from "../scroll-container";
import { useKeyboardListNavigation } from "../../hooks/use-keyboard-list-navigation";
+import { AnimatedFlex } from "../animated";
+import { domAnimation, LazyMotion } from "framer-motion";
const CustomScrollbarsVirtualList = forwardRef<HTMLDivElement, ScrollerProps>(
function CustomScrollbarsVirtualList(props, ref) {
@@ -126,133 +127,148 @@ function ListContainer(props: ListContainerProps) {
const Component = ListProfiles[type];
return (
- <Flex variant="columnFill">
- {!props.items.length && props.placeholder ? (
- <>
- {props.isLoading ? (
- <ListLoader />
- ) : (
- <>
- {header || <ReminderBar />}
+ <LazyMotion features={domAnimation} strict>
+ <Flex variant="columnFill">
+ {!props.items.length && props.placeholder ? (
+ <>
+ {header}
+ {props.isLoading ? (
+ <ListLoader />
+ ) : (
<Flex variant="columnCenterFill" data-test-id="list-placeholder">
<props.placeholder />
</Flex>
- </>
- )}
- </>
- ) : (
- <>
- <Flex
- ref={listContainerRef}
- variant="columnFill"
- data-test-id="note-list"
- >
- <Virtuoso
- ref={listRef}
- data={items}
- computeItemKey={(index) => items[index].id || items[index].title}
- defaultItemHeight={DEFAULT_ITEM_HEIGHT}
- totalCount={items.length}
- onBlur={() => setFocusedGroupIndex(-1)}
- onKeyDown={(e) => onKeyDown(e.nativeEvent)}
- components={{
- Scroller: CustomScrollbarsVirtualList,
- Item: (props) => (
- <div
- {...props}
- style={{ paddingBottom: 1 }}
- onFocus={() => onFocus(props["data-item-index"])}
- onMouseDown={(e) =>
- onMouseDown(e.nativeEvent, props["data-item-index"])
- }
- >
- {props.children}
- </div>
- ),
- Header: () => (header ? header : <Announcements />)
+ )}
+ </>
+ ) : (
+ <>
+ <AnimatedFlex
+ initial={{
+ opacity: 0,
+ scale: 0.98
+ }}
+ animate={{
+ opacity: 1,
+ scale: 1
}}
- itemContent={(index, item) => {
- if (!item) return null;
+ transition={{ duration: 0.2, delay: 0.1, ease: "easeInOut" }}
+ ref={listContainerRef}
+ variant="columnFill"
+ data-test-id="note-list"
+ >
+ <Virtuoso
+ ref={listRef}
+ data={items}
+ computeItemKey={(index) =>
+ items[index].id || items[index].title
+ }
+ defaultItemHeight={DEFAULT_ITEM_HEIGHT}
+ totalCount={items.length}
+ onBlur={() => setFocusedGroupIndex(-1)}
+ onKeyDown={(e) => onKeyDown(e.nativeEvent)}
+ components={{
+ Scroller: CustomScrollbarsVirtualList,
+ Item: (props) => (
+ <div
+ {...props}
+ style={{ paddingBottom: 1 }}
+ onFocus={() => onFocus(props["data-item-index"])}
+ onMouseDown={(e) =>
+ onMouseDown(e.nativeEvent, props["data-item-index"])
+ }
+ >
+ {props.children}
+ </div>
+ ),
+ Header: () => (header ? header : <Announcements />)
+ }}
+ itemContent={(index, item) => {
+ if (!item) return null;
- switch (item.type) {
- case "header":
- return (
- <GroupHeader
- type={groupType}
- refresh={refresh}
- title={item.title}
- isFocused={index === focusedGroupIndex}
- index={index}
- onSelectGroup={() => {
- let endIndex;
- for (let i = index + 1; i < props.items.length; ++i) {
- if (props.items[i].type === "header") {
- endIndex = i;
- break;
+ switch (item.type) {
+ case "header":
+ return (
+ <GroupHeader
+ type={groupType}
+ refresh={refresh}
+ title={item.title}
+ isFocused={index === focusedGroupIndex}
+ index={index}
+ onSelectGroup={() => {
+ let endIndex;
+ for (
+ let i = index + 1;
+ i < props.items.length;
+ ++i
+ ) {
+ if (props.items[i].type === "header") {
+ endIndex = i;
+ break;
+ }
}
- }
- setSelectedItems([
- ...selectionStore.get().selectedItems,
- ...props.items.slice(
+ setSelectedItems([
+ ...selectionStore.get().selectedItems,
+ ...props.items.slice(
+ index,
+ endIndex || props.items.length
+ )
+ ]);
+ }}
+ groups={groups}
+ onJump={(title: string) => {
+ const index = props.items.findIndex(
+ (v) => v.title === title
+ );
+ if (index < 0) return;
+ listRef.current?.scrollToIndex({
index,
- endIndex || props.items.length
- )
- ]);
- }}
- groups={groups}
- onJump={(title: string) => {
- const index = props.items.findIndex(
- (v) => v.title === title
- );
- if (index < 0) return;
- listRef.current?.scrollToIndex({
- index,
- align: "center",
- behavior: "auto"
- });
- setFocusedGroupIndex(index);
- }}
- />
- );
- default:
- return (
- <Component
- item={item}
- context={context}
- index={index}
- type={type}
- compact={compact}
- />
- );
- }
- }}
- />
- </Flex>
- </>
- )}
- {button && (
- <Button
- variant="primary"
- data-test-id={`${props.type}-action-button`}
- onClick={button.onClick}
- sx={{
- position: "absolute",
- bottom: 0,
- display: ["block", "block", "none"],
- alignSelf: "end",
- borderRadius: 100,
- p: 0,
- m: 0,
- mb: 2,
- mr: 2,
- width: 45,
- height: 45
- }}
- >
- <Icon.Plus color="static" />
- </Button>
- )}
- </Flex>
+ align: "center",
+ behavior: "auto"
+ });
+ setFocusedGroupIndex(index);
+ }}
+ />
+ );
+ default:
+ return (
+ <Component
+ item={item}
+ context={context}
+ index={index}
+ type={type}
+ compact={compact}
+ />
+ );
+ }
+ }}
+ />
+ </AnimatedFlex>
+ </>
+ )}
+ {button && (
+ <Button
+ variant="primary"
+ data-test-id={`${props.type}-action-button`}
+ onClick={button.onClick}
+ sx={{
+ position: "absolute",
+ bottom: 0,
+ display: ["block", "block", "none"],
+ alignSelf: "end",
+ borderRadius: 100,
+ p: 0,
+ m: 0,
+ mb: 2,
+ mr: 2,
+ width: 45,
+ height: 45
+ }}
+ >
+ <Icon.Plus color="static" />
+ </Button>
+ )}
+ </Flex>
+ </LazyMotion>
);
}
export default ListContainer;
diff --git a/apps/web/src/components/loaders/editor-loader.tsx b/apps/web/src/components/loaders/editor-loader.tsx
index f655cecaf..d763d7a32 100644
--- a/apps/web/src/components/loaders/editor-loader.tsx
+++ b/apps/web/src/components/loaders/editor-loader.tsx
@@ -19,21 +19,93 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { memo } from "react";
import Skeleton from "react-loading-skeleton";
-import { Box, Flex } from "@theme-ui/components";
+import { Box, Flex, Text } from "@theme-ui/components";
import "react-loading-skeleton/dist/skeleton.css";
+import Config from "../../utils/config";
+import { TextScramble } from "../text-scramble";
+import useHashLocation from "../../hooks/use-hash-location";
+import makeMatcher from "wouter/matcher";
+import { Lock } from "../icons";
+const matcher = makeMatcher();
+const EDITOR_MARGINS = Config.get("editor:margins", true);
export const EditorLoader = memo(function EditorLoader() {
+ const [{ location }] = useHashLocation();
+ const [isNoteLoading] = matcher("/notes/:noteId/edit", location);
+ const [isNoteLocked] = matcher("/notes/:noteId/unlock", location);
+
+ if (isNoteLocked) {
+ return (
+ <Flex
+ sx={{
+ flexDirection: "column",
+ flex: 1,
+ alignItems: "center",
+ justifyContent: "center"
+ }}
+ >
+ <Lock size={100} sx={{ opacity: 0.2 }} />
+ </Flex>
+ );
+ }
+
return (
- <Flex sx={{ flexDirection: "column", p: 2, py: 1 }}>
- <Flex sx={{ alignItems: "end", justifyContent: "end" }}>
- <Skeleton width={45} height={30} style={{ marginRight: 5 }} />
- <Skeleton width={45} height={30} />
+ <Flex
+ sx={{
+ flexDirection: "column",
+ p: 2,
+ py: 1
+ }}
+ >
+ <Flex sx={{ alignItems: "end", justifyContent: "end", opacity: 0 }}>
+ <Skeleton enableAnimation={false} width={76} height={33} />
+ </Flex>
+ <Flex
+ sx={{
+ alignSelf: ["stretch", "stretch", "center"],
+ maxWidth: EDITOR_MARGINS ? "min(100%, 850px)" : "auto",
+ px: 6,
+ width: "100%",
+ flexDirection: "column"
+ }}
+ >
+ <Skeleton
+ enableAnimation={false}
+ height={32}
+ style={{ marginTop: 5, opacity: 0 }}
+ />
+ <Box sx={{ mt: 1 }}>
+ <Text
+ sx={{
+ p: 0,
+ fontFamily: "heading",
+ fontSize: ["1.625em", "1.625em", "2.625em"],
+ fontWeight: "heading",
+ width: "100%",
+ color: "placeholder",
+ opacity: 0.8
+ }}
+ >
+ {isNoteLoading ? (
+ <TextScramble text="Loading" nextLetterSpeed={50} />
+ ) : (
+ "Note title"
+ )}
+ </Text>
+ <Skeleton
+ enableAnimation={false}
+ height={22}
+ style={{ marginTop: 16 }}
+ count={2}
+ />
+ <Skeleton
+ enableAnimation={false}
+ height={22}
+ width={25}
+ style={{ marginTop: 16 }}
+ />
+ </Box>
</Flex>
- <Skeleton height={39} style={{ marginTop: 20 }} />
- <Box sx={{ mt: 4, mx: "5%" }}>
- <Skeleton height={56} width={300} />
- <Skeleton height={22} style={{ marginTop: 15 }} count={3} />
- </Box>
</Flex>
);
});
diff --git a/apps/web/src/components/loaders/list-loader.tsx b/apps/web/src/components/loaders/list-loader.tsx
index cad00619c..eb3fcf32f 100644
--- a/apps/web/src/components/loaders/list-loader.tsx
+++ b/apps/web/src/components/loaders/list-loader.tsx
@@ -23,7 +23,7 @@ import { Box, Flex } from "@theme-ui/components";
import "react-loading-skeleton/dist/skeleton.css";
import { getRandomArbitrary } from "../../utils/random";
-const Lines = [1, 2, 3, 4].map(() => getRandomArbitrary(40, 90));
+const Lines = [1, 2].map(() => getRandomArbitrary(40, 90));
export const ListLoader = memo(function ListLoader() {
return (
<>
@@ -31,7 +31,7 @@ export const ListLoader = memo(function ListLoader() {
sx={{ py: 1, alignItems: "center", justifyContent: "center", px: 1 }}
>
<Box sx={{ height: 38 }}>
- <Skeleton width={38} height={38} circle />
+ <Skeleton enableAnimation={false} width={38} height={38} circle />
</Box>
<Flex
sx={{
@@ -42,24 +42,26 @@ export const ListLoader = memo(function ListLoader() {
}}
>
<Box sx={{ height: 14 }}>
- <Skeleton inline height={14} />
+ <Skeleton enableAnimation={false} inline height={14} />
</Box>
<Box sx={{ mt: 1, height: 10 }}>
- <Skeleton inline height={10} />
+ <Skeleton enableAnimation={false} inline height={10} />
</Box>
</Flex>
</Flex>
{Lines.map((width) => (
<Box key={width} sx={{ py: 2, px: 1 }}>
<Skeleton
+ enableAnimation={false}
height={16}
width={`${width}%`}
style={{ marginBottom: 5 }}
/>
<Skeleton height={12} count={2} />
<Flex>
- <Skeleton height={10} inline width={50} />
+ <Skeleton enableAnimation={false} height={10} inline width={50} />
<Skeleton
+ enableAnimation={false}
height={10}
inline
width={10}
@@ -67,6 +69,7 @@ export const ListLoader = memo(function ListLoader() {
style={{ marginLeft: 5 }}
/>
<Skeleton
+ enableAnimation={false}
height={10}
inline
width={10}
diff --git a/apps/web/src/components/navigation-menu/index.tsx b/apps/web/src/components/navigation-menu/index.tsx
index 9fc5955d1..db490e411 100644
--- a/apps/web/src/components/navigation-menu/index.tsx
+++ b/apps/web/src/components/navigation-menu/index.tsx
@@ -144,108 +144,117 @@ function NavigationMenu(props: NavigationMenuProps) {
id="navigation-menu"
data-test-id="navigation-menu"
initial={{
- opacity: 1
+ opacity: 0
}}
animate={{
opacity: isFocusMode ? 0 : 1,
visibility: isFocusMode ? "collapse" : "visible"
}}
- transition={{ duration: 0.3, ease: "easeOut" }}
+ transition={{ duration: 0.2, ease: "easeInOut" }}
sx={{
zIndex: 1,
- height: "auto",
position: "relative",
flex: 1,
+ height: "100%",
+ overflow: "hidden",
flexDirection: "column",
justifyContent: "space-between"
}}
bg={"bgSecondary"}
px={0}
>
- <FlexScrollContainer>
- <Flex sx={{ flexDirection: "column" }}>
- {routes.map((item) => (
- <NavigationItem
- isTablet={isTablet}
- key={item.path}
- title={item.title}
- icon={item.icon}
- tag={item.tag}
- selected={
- item.path === "/"
- ? location === item.path
- : location.startsWith(item.path)
- }
- onClick={() => {
- if (!isMobile && location === item.path)
- return toggleNavigationContainer();
- _navigate(item.path);
- }}
- />
- ))}
- {colors.map((color) => (
- <NavigationItem
- isTablet={isTablet}
- key={color.id}
- title={db.colors?.alias(color.id)}
- icon={Circle}
- selected={location === `/colors/${color.id}`}
- color={color.title.toLowerCase()}
- onClick={() => {
- _navigate(`/colors/${color.id}`);
- }}
- menuItems={[
- {
- key: "rename",
- title: () => "Rename color",
- onClick: async () => {
- await showRenameColorDialog(color.id);
- }
- }
- ]}
- />
- ))}
- <Box
- bg="border"
- my={1}
- sx={{ width: "85%", height: "0.8px", alignSelf: "center" }}
+ <FlexScrollContainer
+ style={{
+ flexDirection: "column",
+ display: "flex"
+ }}
+ suppressScrollX={true}
+ >
+ {routes.map((item) => (
+ <NavigationItem
+ isTablet={isTablet}
+ key={item.path}
+ title={item.title}
+ icon={item.icon}
+ tag={item.tag}
+ selected={
+ item.path === "/"
+ ? location === item.path
+ : location.startsWith(item.path)
+ }
+ onClick={() => {
+ if (!isMobile && location === item.path)
+ return toggleNavigationContainer();
+ _navigate(item.path);
+ }}
/>
- {shortcuts.map((item) => (
- <NavigationItem
- isTablet={isTablet}
- key={item.id}
- title={item.type === "tag" ? db.tags?.alias(item.id) : item.title}
- menuItems={[
- {
- key: "removeshortcut",
- title: () => "Remove shortcut",
- onClick: async () => {
- await db.shortcuts?.remove(item.id);
- refreshNavItems();
- }
+ ))}
+ {colors.map((color, index) => (
+ <NavigationItem
+ animate
+ index={index}
+ isTablet={isTablet}
+ key={color.id}
+ title={db.colors?.alias(color.id)}
+ icon={Circle}
+ selected={location === `/colors/${color.id}`}
+ color={color.title.toLowerCase()}
+ onClick={() => {
+ _navigate(`/colors/${color.id}`);
+ }}
+ menuItems={[
+ {
+ key: "rename",
+ title: () => "Rename color",
+ onClick: async () => {
+ await showRenameColorDialog(color.id);
}
- ]}
- icon={
- item.type === "notebook"
- ? Notebook2
- : item.type === "tag"
- ? Tag2
- : Topic
}
- isShortcut
- selected={shouldSelectNavItem(location, item)}
- onClick={() => {
- if (item.type === "notebook") {
- _navigate(`/notebooks/${item.id}`);
- } else if (item.type === "topic") {
- _navigate(`/notebooks/${item.notebookId}/${item.id}`);
- } else if (item.type === "tag") {
- _navigate(`/tags/${item.id}`);
+ ]}
+ />
+ ))}
+ <Box
+ bg="border"
+ my={1}
+ sx={{ width: "85%", height: "0.8px", alignSelf: "center" }}
+ />
+ {shortcuts.map((item, index) => (
+ <NavigationItem
+ animate
+ index={colors.length - 1 + index}
+ isTablet={isTablet}
+ key={item.id}
+ title={item.type === "tag" ? db.tags?.alias(item.id) : item.title}
+ menuItems={[
+ {
+ key: "removeshortcut",
+ title: () => "Remove shortcut",
+ onClick: async () => {
+ await db.shortcuts?.remove(item.id);
+ refreshNavItems();
}
- }}
- />
- ))}
- </Flex>
+ }
+ ]}
+ icon={
+ item.type === "notebook"
+ ? Notebook2
+ : item.type === "tag"
+ ? Tag2
+ : Topic
+ }
+ isShortcut
+ selected={shouldSelectNavItem(location, item)}
+ onClick={() => {
+ if (item.type === "notebook") {
+ _navigate(`/notebooks/${item.id}`);
+ } else if (item.type === "topic") {
+ _navigate(`/notebooks/${item.notebookId}/${item.id}`);
+ } else if (item.type === "tag") {
+ _navigate(`/tags/${item.id}`);
+ }
+ }}
+ />
+ ))}
</FlexScrollContainer>
<Flex sx={{ flexDirection: "column" }}>
{isLoggedIn === false && (
@@ -274,8 +283,8 @@ function NavigationMenu(props: NavigationMenuProps) {
icon={settings.icon}
onClick={() => {
if (!isMobile && location === settings.path)
- return toggleNavigationContainer();
- _navigate(settings.path);
+ return toggleNavigationContainer();
+ _navigate(settings.path);
}}
selected={location.startsWith(settings.path)}
>
diff --git a/apps/web/src/components/navigation-menu/navigation-item.tsx b/apps/web/src/components/navigation-menu/navigation-item.tsx
index a814f4460..9d822d85a 100644
--- a/apps/web/src/components/navigation-menu/navigation-item.tsx
+++ b/apps/web/src/components/navigation-menu/navigation-item.tsx
@@ -17,13 +17,14 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import { Button, Flex, Text } from "@theme-ui/components";
+import { Button, Text } from "@theme-ui/components";
import { useStore as useAppStore } from "../../stores/app-store";
import { useMenuTrigger } from "../../hooks/use-menu";
import useMobile from "../../hooks/use-mobile";
import { PropsWithChildren } from "react";
import { Theme } from "@notesnook/theme";
import { Icon, Shortcut } from "../icons";
+import { AnimatedFlex } from "../animated";
type NavigationItemProps = {
icon: Icon;
@@ -36,6 +37,8 @@ type NavigationItemProps = {
selected?: boolean;
onClick?: () => void;
count?: number;
+ animate?: boolean;
+ index?: number;
// TODO: add proper typings here
menuItems?: any[];
};
@@ -53,14 +56,26 @@ function NavigationItem(props: PropsWithChildren<NavigationItemProps>) {
selected,
onClick,
menuItems,
- count
+ count,
+ animate = false,
+ index = 0
} = props;
const toggleSideMenu = useAppStore((store) => store.toggleSideMenu);
const { openMenu } = useMenuTrigger();
const isMobile = useMobile();
return (
- <Flex
+ <AnimatedFlex
+ initial={{
+ opacity: animate ? 0 : 1,
+ // y: animate ? 0 : 0,
+ x: animate ? (isTablet ? 0 : 10) : 0
+ }}
+ animate={{
+ opacity: 1,
+ x: 0
+ }}
+ transition={{ duration: 0.1, delay: index * 0.05, ease: "easeIn" }}
bg={selected ? "bgSecondaryHover" : "transparent"}
sx={{
borderRadius: "default",
@@ -125,13 +140,11 @@ function NavigationItem(props: PropsWithChildren<NavigationItemProps>) {
data-test-id="title"
>
{title}
- {tag && (
+ {/* {tag && (
<Text
variant="subBody"
as="span"
sx={{
- bg: "primary",
- color: "static",
ml: 1,
px: "small",
borderRadius: "default"
@@ -139,7 +152,7 @@ function NavigationItem(props: PropsWithChildren<NavigationItemProps>) {
>
{tag}
</Text>
- )}
+ )} */}
</Text>
</Button>
{children ? (
@@ -151,8 +164,18 @@ function NavigationItem(props: PropsWithChildren<NavigationItemProps>) {
>
{count > 100 ? "100+" : count}
</Text>
+ ) : !isTablet && tag ? (
+ <Text
+ variant="subBody"
+ sx={{
+ mr: 1,
+ borderRadius: "100px"
+ }}
+ >
+ {tag}
+ </Text>
) : null}
- </Flex>
+ </AnimatedFlex>
);
}
export default NavigationItem;
diff --git a/apps/web/src/components/scroll-container/index.tsx b/apps/web/src/components/scroll-container/index.tsx
index d9a113863..958411336 100644
--- a/apps/web/src/components/scroll-container/index.tsx
+++ b/apps/web/src/components/scroll-container/index.tsx
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import React, { PropsWithChildren } from "react";
-import { MacScrollbar } from "mac-scrollbar";
+import { MacScrollbar, MacScrollbarProps } from "mac-scrollbar";
import "mac-scrollbar/dist/mac-scrollbar.css";
type ScrollContainerProps = {
@@ -53,16 +53,23 @@ type FlexScrollContainerProps = {
id?: string;
className?: string;
style?: React.CSSProperties;
-};
+} & MacScrollbarProps;
export function FlexScrollContainer({
id,
children,
style,
- className
+ className,
+ ...restProps
}: PropsWithChildren<FlexScrollContainerProps>) {
return (
- <MacScrollbar id={id} className={className} style={style} minThumbSize={40}>
+ <MacScrollbar
+ {...restProps}
+ id={id}
+ className={className}
+ style={style}
+ minThumbSize={40}
+ >
{children}
</MacScrollbar>
);
diff --git a/apps/web/src/components/text-scramble/index.tsx b/apps/web/src/components/text-scramble/index.tsx
new file mode 100644
index 000000000..3eddad327
--- /dev/null
+++ b/apps/web/src/components/text-scramble/index.tsx
@@ -0,0 +1,116 @@
+/*
+This file is part of the Notesnook project (https://notesnook.com/)
+
+Copyright (C) 2023 Streetwriters (Private) Limited
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+import { useState, useEffect } from "react";
+
+type TextScrambleProps = {
+ text: string;
+ className?: string;
+ letterSpeed?: number;
+ nextLetterSpeed?: number;
+ paused?: boolean;
+ pauseTime?: number;
+};
+
+const randomItem = (array: Array<any>) =>
+ array[Math.floor(Math.random() * array.length)];
+
+const nextItem = (array: Array<any>, currentItem: any) => {
+ const currentIndex = array.indexOf(currentItem);
+ const bound = array.length;
+ const nextIndex = (currentIndex + bound + 1) % bound;
+ return array[nextIndex];
+};
+
+const symbols: string[] = "-=_+/.,<>;'!@#$%^&*()".split("");
+
+export function TextScramble(props: TextScrambleProps) {
+ const {
+ text,
+ className,
+ letterSpeed = 5,
+ nextLetterSpeed = 100,
+ paused = false,
+ pauseTime = 1500
+ } = props;
+
+ const initSymbols: string[] = Array(text.length)
+ .fill(0)
+ .map(() => randomItem(symbols));
+
+ const [displayedText, setDisplayedText] = useState<string[]>(initSymbols);
+
+ const leftIndexes: number[] = [];
+
+ const defaultLeftIndexes = (): void => {
+ text.split("").forEach((_, i) => {
+ leftIndexes.push(i);
+ });
+ };
+
+ let bakeLetterInterval: any = 0;
+ let bakeTextInterval: any = 0;
+
+ const bakeLetter = () => {
+ bakeLetterInterval = setInterval(() => {
+ if (!paused) {
+ const updatedText: string[] = [];
+
+ text.split("").forEach((_, i) => {
+ if (!leftIndexes.includes(i)) {
+ updatedText[i] = text[i];
+ return;
+ }
+
+ const randomSymbol = randomItem(symbols);
+ updatedText[i] = randomSymbol;
+ });
+
+ setDisplayedText(updatedText);
+ }
+ }, letterSpeed);
+ };
+
+ const bakeText = () => {
+ defaultLeftIndexes();
+ bakeLetter();
+
+ bakeTextInterval = setInterval(() => {
+ if (!paused) {
+ if (leftIndexes.length === 0) {
+ clearInterval(bakeLetterInterval);
+ clearInterval(bakeTextInterval);
+
+ setTimeout(() => {
+ // setCurrentText(text);
+ defaultLeftIndexes();
+ }, pauseTime);
+ }
+
+ leftIndexes.shift();
+ }
+ }, nextLetterSpeed);
+ };
+
+ useEffect(() => {
+ if (!paused) bakeText();
+ }, [text, paused]); // eslint-disable-line react-hooks/exhaustive-deps
+
+ return <div className={className}>{displayedText}</div>;
+}