Files
flipper/desktop/plugins/public/navigation/components/Timeline.tsx
Anton Nikolaev d782f19001 Refactor plugin to make it fast refreshable
Summary: Refactored Navigation plugin to make it fast-refreshable: moved the main component into a separate file and exported all components as named functions. Without these changes every change of UI triggered full reload.

Reviewed By: timur-valiev

Differential Revision: D29814077

fbshipit-source-id: 5285bdc5f14a5163f9501c0d45a3affefb08fc8e
2021-07-21 07:25:06 -07:00

96 lines
2.4 KiB
TypeScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import {FlexCenter, styled} from 'flipper';
import {NavigationInfoBox} from './';
import {Bookmark, NavigationEvent, URI} from '../types';
import React, {useRef} from 'react';
import {theme} from 'flipper-plugin';
type Props = {
bookmarks: Map<string, Bookmark>;
events: Array<NavigationEvent>;
onNavigate: (uri: URI) => void;
onFavorite: (uri: URI) => void;
};
const TimelineLine = styled.div({
width: 2,
backgroundColor: theme.textColorActive,
position: 'absolute',
top: 38,
bottom: 0,
});
const TimelineContainer = styled.div({
position: 'relative',
paddingLeft: 25,
overflowY: 'scroll',
flexGrow: 1,
backgroundColor: theme.backgroundWash,
scrollBehavior: 'smooth',
'&>div': {
position: 'relative',
minHeight: '100%',
'&:last-child': {
paddingBottom: 25,
},
},
});
const NavigationEventContainer = styled.div({
display: 'flex',
paddingTop: 25,
paddingLeft: 25,
marginRight: 25,
});
const NoData = styled(FlexCenter)({
height: '100%',
fontSize: 18,
backgroundColor: theme.backgroundWash,
color: theme.textColorSecondary,
});
export function Timeline(props: Props) {
const {bookmarks, events, onNavigate, onFavorite} = props;
const timelineRef = useRef<HTMLDivElement>(null);
return events.length === 0 ? (
<NoData>No Navigation Events to Show</NoData>
) : (
<TimelineContainer ref={timelineRef}>
<div>
<TimelineLine />
{events.map((event: NavigationEvent, idx: number) => {
return (
<NavigationEventContainer key={idx}>
<NavigationInfoBox
isBookmarked={
event.uri != null ? bookmarks.has(event.uri) : false
}
className={event.className}
uri={event.uri}
onNavigate={(uri) => {
if (timelineRef.current != null) {
timelineRef.current.scrollTo(0, 0);
}
onNavigate(uri);
}}
onFavorite={onFavorite}
screenshot={event.screenshot}
date={event.date}
/>
</NavigationEventContainer>
);
})}
</div>
</TimelineContainer>
);
}