Skip to content

Commit c300f10

Browse files
committed
Try to simplify view list scroll-restore logic
1 parent ebeb8a2 commit c300f10

File tree

1 file changed

+6
-24
lines changed

1 file changed

+6
-24
lines changed

src/components/view/view-page.tsx

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,6 @@ class ViewPage extends React.Component<ViewPageProps> {
171171

172172
private listRef = React.createRef<ViewEventList>();
173173
private splitPaneRef = React.createRef<SplitPane>();
174-
175-
@observable
176-
private shouldRestoreViewStateOnRefSet = false;
177174

178175
@observable
179176
private searchFiltersUnderConsideration: FilterSet | undefined;
@@ -214,7 +211,7 @@ class ViewPage extends React.Component<ViewPageProps> {
214211
get selectedEvent() {
215212
// First try to use the URL-based eventId, then fallback to the persisted selection
216213
const targetEventId = this.props.eventId || this.props.uiStore.selectedEventId;
217-
214+
218215
return _.find(this.props.eventsStore.events, {
219216
id: targetEventId
220217
});
@@ -245,15 +242,13 @@ class ViewPage extends React.Component<ViewPageProps> {
245242
this.onBuildRuleFromExchange,
246243
this.onPrepareToResendRequest
247244
);
245+
248246
componentDidMount() {
249247
// After first render, scroll to the selected event (or the end of the list) by default:
250248
requestAnimationFrame(() => {
251-
if (this.props.eventId && this.selectedEvent) {
249+
if ((this.props.eventId || this.props.uiStore.selectedEventId) && this.selectedEvent) {
252250
this.onScrollToCenterEvent(this.selectedEvent);
253-
} else if (!this.props.eventId && this.props.uiStore.selectedEventId) {
254-
// If no URL eventId but we have a persisted selection, restore it when ref is set
255-
this.shouldRestoreViewStateOnRefSet = true;
256-
} else {
251+
} else if (!this.props.uiStore.viewScrollPosition) {
257252
this.onScrollToEnd();
258253
}
259254
});
@@ -466,7 +461,7 @@ class ViewPage extends React.Component<ViewPageProps> {
466461
contextMenuBuilder={this.contextMenuBuilder}
467462
uiStore={this.props.uiStore}
468463

469-
ref={this.setListRef}
464+
ref={this.listRef}
470465
/>
471466
</LeftPane>
472467
<PaneOuterContainer
@@ -508,7 +503,7 @@ class ViewPage extends React.Component<ViewPageProps> {
508503
onSelected(event: CollectedEvent | undefined) {
509504
// Persist the selected event to UiStore for tab switching
510505
this.props.uiStore.setSelectedEventId(event?.id);
511-
506+
512507
this.props.navigate(event
513508
? `/view/${event.id}`
514509
: '/view'
@@ -640,19 +635,6 @@ class ViewPage extends React.Component<ViewPageProps> {
640635
onScrollToEnd() {
641636
this.listRef.current?.scrollToEnd();
642637
}
643-
644-
@action.bound
645-
setListRef = (ref: ViewEventList | null) => {
646-
if (ref) {
647-
(this.listRef as any).current = ref;
648-
if (this.shouldRestoreViewStateOnRefSet) {
649-
this.shouldRestoreViewStateOnRefSet = false;
650-
ref.restoreViewState();
651-
}
652-
} else {
653-
(this.listRef as any).current = null;
654-
}
655-
};
656638
}
657639

658640
const LeftPane = styled.div`

0 commit comments

Comments
 (0)