-
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.
Add URL validation and saving functionality to PersonalPreferences co…
…mponent
- Loading branch information
Showing
3 changed files
with
70 additions
and
12 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,33 @@ | ||
import Cookies from 'js-cookie'; | ||
import isValidUrl from './isValidUrl'; | ||
|
||
/** | ||
* Get the default URL(s) from the environment | ||
* @returns {Array} URL(s) from the environment | ||
*/ | ||
export const getURlsFromEnv = () => { | ||
const presetUrlsString = | ||
process.env['RAZZLE_DEFAULT_IFRAME_URL'] || | ||
(typeof window !== 'undefined' && | ||
window.env['RAZZLE_DEFAULT_IFRAME_URL']) || | ||
'http://localhost:3002'; // fallback if env is not set | ||
|
||
const presetUrls = presetUrlsString.split(','); | ||
return presetUrls; | ||
}; | ||
|
||
/** | ||
* Get the saved URLs from the cookies | ||
* @returns {Array} Saved URLs | ||
*/ | ||
const getSavedURLs = () => { | ||
const urls = Cookies.get('saved_urls') | ||
? Cookies.get('saved_urls').split(',') | ||
: []; | ||
const savedUrls = [ | ||
...new Set([...urls, ...getURlsFromEnv()]), // Merge saved URLs with default URLs make sure they are unique | ||
]; | ||
return savedUrls.filter(isValidUrl); | ||
}; | ||
|
||
export default getSavedURLs; |
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