-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from CovOpen/persist_questionnaire_selection
fix: persist questionnaire selection
- Loading branch information
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { QuestionnaireSelection } from "../components/questionnaireSelection/QuestionnaireSelection"; | ||
|
||
let persistedParameters = ["id", "version", "language"]; | ||
|
||
export function getQueryParams(): QuestionnaireSelection { | ||
const queryParams = new URLSearchParams(window.location.search); | ||
return persistedParameters.reduce((obj, key) => { | ||
return { ...obj, [key]: queryParams.get(key) }; | ||
}, {}); | ||
} | ||
|
||
export function setQueryParams(selection: QuestionnaireSelection): void { | ||
const queryParams = new URLSearchParams(window.location.search); | ||
persistedParameters.forEach((key) => { | ||
if ((selection as any)[key] != null) { | ||
queryParams.set(key, (selection as any)[key]); | ||
} | ||
}); | ||
window.history.replaceState({}, "", `${window.location.pathname}?${queryParams}`); | ||
} |