Skip to content

Commit

Permalink
adjust threshold instead of debouncing (#3578)
Browse files Browse the repository at this point in the history
  • Loading branch information
austenem authored Oct 22, 2024
1 parent bb07051 commit 8f136b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG-fix-shaking-viewport.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix bug where expanding a processed dataset section leads to a shaking viewport.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import useProcessedDataStore from '../store';
import { DetailPageSection } from '../../DetailPageSection';

const iconPlaceholder = <Skeleton variant="circular" width={24} height={24} animation="pulse" />;
const inViewThreshold = 0.1;

function LoadingFallback() {
return <Skeleton variant="rectangular" height={200} />;
Expand All @@ -27,19 +28,22 @@ export function ProcessedDatasetAccordion({ children }: PropsWithChildren) {
const { defaultExpanded, dataset, sectionDataset, conf, isLoading } = useProcessedDatasetContext();
const visualizationIcon = conf ? <VisualizationIcon /> : null;
const track = useTrackEntityPageEvent();
const [threshold, setThreshold] = useState(inViewThreshold);

const { setCurrentDataset, removeVisibleDataset } = useProcessedDataStore((state) => ({
setCurrentDataset: state.setCurrentDataset,
removeVisibleDataset: state.removeFromVisibleDatasets,
}));
const { ref } = useInView({
threshold: 0,
threshold,
initialInView: false,
onChange: (visible) => {
if (visible && dataset) {
setThreshold(0);
setCurrentDataset(dataset);
}
if (!visible) {
setThreshold(inViewThreshold);
removeVisibleDataset(sectionDataset.hubmap_id);
}
},
Expand Down

0 comments on commit 8f136b3

Please sign in to comment.