-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91dfd71
commit 4f37208
Showing
3 changed files
with
44 additions
and
7 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
32 changes: 32 additions & 0 deletions
32
library/src/components/List/useEncodedQueryStringParams.tsx
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,32 @@ | ||
/* eslint-disable no-script-url */ | ||
|
||
import { useState, useEffect } from 'react'; | ||
import { CriteriaFilterValues } from './Filter/ContentFilterDialog'; | ||
import { criteriaToArray, stringToCriteria } from './List.helpers'; | ||
|
||
const useEncodedQueryStringParams = function (): Array<string> { | ||
const [currentQueryParams, setCurrentQueryParams] = useState<Array<string>>( | ||
[] | ||
); | ||
const uri = location.search; | ||
|
||
useEffect(() => { | ||
const uriCriteria: CriteriaFilterValues = stringToCriteria(uri); | ||
|
||
const result = []; | ||
for (const criteria of uriCriteria) { | ||
const encodedValue = encodeURIComponent(criteria.value); | ||
|
||
result.push({ | ||
...criteria, | ||
value: encodedValue, | ||
}); | ||
} | ||
|
||
setCurrentQueryParams(criteriaToArray(result)); | ||
}, [uri]); | ||
|
||
return currentQueryParams; | ||
}; | ||
|
||
export default useEncodedQueryStringParams; |