Skip to content

Commit 1dd8f4e

Browse files
author
Sebastian Benjamin
committed
Reload appropriately on back/forward browser navigation
1 parent f160db1 commit 1dd8f4e

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

jbrowse/src/client/JBrowse/VariantSearch/components/VariantTableWidget.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,14 @@ const VariantTableWidget = observer(props => {
6565
session.hideWidget(widget)
6666
}
6767

68-
function handleQuery(passedFilters) {
68+
function handleQuery(passedFilters, pushToHistory) {
6969
const encodedSearchString = createEncodedFilterString(passedFilters, false);
7070
const currentUrl = new URL(window.location.href);
7171
currentUrl.searchParams.set("searchString", encodedSearchString);
72-
window.history.pushState(null, "", currentUrl.toString());
72+
73+
if (pushToHistory) {
74+
window.history.pushState(null, "", currentUrl.toString());
75+
}
7376

7477
setFilters(passedFilters);
7578
setDataLoaded(false)
@@ -121,6 +124,7 @@ const VariantTableWidget = observer(props => {
121124
);
122125
};
123126

127+
124128
window.addEventListener('resize', truncateDisplayValue)
125129
truncateDisplayValue()
126130

@@ -231,6 +235,11 @@ const VariantTableWidget = observer(props => {
231235

232236
// API call to retrieve the requested features.
233237
useEffect(() => {
238+
const handlePopState = () => {
239+
window.location.reload();
240+
};
241+
window.addEventListener('popstate', handlePopState);
242+
234243
async function fetch() {
235244
await fetchFieldTypeInfo(sessionId, trackGUID,
236245
(fields: FieldModel[], groups: string[], promotedFilters: Map<string, Filter[]>) => {
@@ -248,7 +257,7 @@ const VariantTableWidget = observer(props => {
248257
setAllowedGroupNames(groups)
249258
setPromotedFilters(promotedFilters)
250259

251-
handleQuery(searchStringToInitialFilters(fields.map((x) => x.name)))
260+
handleQuery(searchStringToInitialFilters(fields.map((x) => x.name)), false)
252261
},
253262
(error) => {
254263
setError(error)
@@ -257,6 +266,9 @@ const VariantTableWidget = observer(props => {
257266

258267
fetch()
259268

269+
return () => {
270+
window.removeEventListener('popstate', handlePopState);
271+
};
260272
}, [pluginManager, parsedLocString, session.visibleWidget])
261273

262274
if (!view) {
@@ -397,7 +409,7 @@ const VariantTableWidget = observer(props => {
397409
fieldTypeInfo: fieldTypeInfo,
398410
allowedGroupNames: allowedGroupNames,
399411
promotedFilters: promotedFilters,
400-
handleQuery: (filters) => handleQuery(filters)
412+
handleQuery: (filters) => handleQuery(filters, true)
401413
}}
402414
/>
403415
);

0 commit comments

Comments
 (0)