-
Notifications
You must be signed in to change notification settings - Fork 7
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
Nikita Kakuev
committed
Sep 21, 2023
1 parent
2844c95
commit 0823491
Showing
4 changed files
with
16 additions
and
13 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
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 |
---|---|---|
@@ -1,17 +1,17 @@ | ||
import { generate } from 'random-words'; | ||
|
||
const getSpaceNameFromUrl = () => { | ||
const getParamNameFromUrl = (paramName: string = 'space', length = 3, join = '-' ) => { | ||
const url = new URL(window.location.href); | ||
const spaceNameInParams = url.searchParams.get('space'); | ||
const spaceNameInParams = url.searchParams.get(paramName); | ||
|
||
if (spaceNameInParams) { | ||
return spaceNameInParams; | ||
} else { | ||
const generatedName = generate({ exactly: 3, join: '-' }); | ||
url.searchParams.set('space', generatedName); | ||
const generatedName = generate({ exactly: length, join }); | ||
url.searchParams.set(paramName, generatedName); | ||
window.history.replaceState({}, '', `?${url.searchParams.toString()}`); | ||
return generatedName; | ||
} | ||
}; | ||
|
||
export { getSpaceNameFromUrl }; | ||
export { getParamNameFromUrl }; |