fix: solved the issue of the sidebar favoritedList not being fully displayed (#1523)

Co-authored-by: Himself65 <himself65@outlook.com>
This commit is contained in:
sheben
2023-03-11 02:40:38 +08:00
committed by GitHub
parent f47a23b0b5
commit 1c89841d6f
7 changed files with 93 additions and 58 deletions

View File

@@ -21,7 +21,8 @@ import { useWorkspacesHelper } from '../../hooks/use-workspaces';
import { ThemeProvider } from '../../providers/ThemeProvider';
import { pathGenerator, RemWorkspaceFlavour } from '../../shared';
import { WorkSpaceSliderBar } from '../pure/workspace-slider-bar';
vi.mock('react-lottie', () => ({
vi.mock('../blocksuite/header/editor-mode-switch/CustomLottie', () => ({
default: (props: React.PropsWithChildren) => <>{props.children}</>,
}));

View File

@@ -0,0 +1,54 @@
import lottie from 'lottie-web';
import { FC, useEffect, useRef } from 'react';
type CustomLottieProps = {
options: {
loop?: boolean | number | undefined;
autoplay?: boolean | undefined;
animationData: any;
rendererSettings?: {
preserveAspectRatio?: string | undefined;
};
};
isStopped?: boolean | undefined;
speed?: number | undefined;
width?: number | string | undefined;
height?: number | string | undefined;
};
const CustomLottie: FC<CustomLottieProps> = ({
options,
isStopped,
speed,
width,
height,
}) => {
const element = useRef<HTMLDivElement>(null);
const lottieInstance = useRef<any>();
useEffect(() => {
if (element.current) {
lottieInstance.current = lottie.loadAnimation({
...options,
container: element.current,
});
}
return () => {
lottieInstance.current?.destroy();
};
}, [options]);
useEffect(() => {
if (speed) {
lottieInstance.current?.setSpeed(speed);
}
if (isStopped) {
lottieInstance.current?.stop();
} else {
lottieInstance.current?.play();
}
}, [isStopped, speed]);
return <div ref={element} style={{ width, height }}></div>;
};
export default CustomLottie;

View File

@@ -1,6 +1,6 @@
import React, { cloneElement, HTMLAttributes, useState } from 'react';
import Lottie from 'react-lottie';
import Lottie from './CustomLottie';
import { StyledSwitchItem } from './style';
type HoverAnimateControllerProps = {

View File

@@ -53,19 +53,20 @@ const FavoriteList: React.FC<FavoriteListProps> = ({
{favoriteList.map((pageMeta, index) => {
const active = router.query.pageId === pageMeta.id;
return (
<StyledSubListItem
data-testid={`favorite-list-item-${pageMeta.id}`}
active={active}
key={`${pageMeta}-${index}`}
onClick={() => {
if (active) {
return;
}
openPage(pageMeta.id);
}}
>
{pageMeta.title || 'Untitled'}
</StyledSubListItem>
<div key={`${pageMeta}-${index}`}>
<StyledSubListItem
data-testid={`favorite-list-item-${pageMeta.id}`}
active={active}
onClick={() => {
if (active) {
return;
}
openPage(pageMeta.id);
}}
>
{pageMeta.title || 'Untitled'}
</StyledSubListItem>
</div>
);
})}
{favoriteList.length === 0 && (