From e485797d3507054265fa8485fed6e16fb0bf789b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anne=20L=27H=C3=B4te?= Date: Thu, 14 Nov 2024 13:53:04 +0100 Subject: [PATCH] fix(openalex): Change view URLSearchParams --- client/src/pages/openalex-ror/openalexView.jsx | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/client/src/pages/openalex-ror/openalexView.jsx b/client/src/pages/openalex-ror/openalexView.jsx index 33afe99..baaa670 100644 --- a/client/src/pages/openalex-ror/openalexView.jsx +++ b/client/src/pages/openalex-ror/openalexView.jsx @@ -4,6 +4,7 @@ import { DataTable } from 'primereact/datatable'; import { InputTextarea } from 'primereact/inputtextarea'; import PropTypes from 'prop-types'; import { useState } from 'react'; +import { useSearchParams } from 'react-router-dom'; import useToast from '../../hooks/useToast'; import { getAffiliationsCorrections } from '../../utils/curations'; @@ -26,8 +27,7 @@ export default function OpenalexView({ undo, }) { const [selectionPageOnly, setSelectionPageOnly] = useState(true); - const urlParams = new URLSearchParams(window.location.search); - const view = urlParams.get('view') || 'table'; + const [searchParams, setSearchParams] = useSearchParams(); const cellEditor = (options) => ( { - const url = new URL(window.location); - url.searchParams.set('view', _view); - window.history.pushState({}, '', url); + const changeView = (view) => { + searchParams.set('view', view); + setSearchParams(searchParams); }; const onRowEditComplete = async (edit) => { @@ -106,7 +105,6 @@ export default function OpenalexView({