-
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 utility function for generating poll path from poll ID, and another one from getting poll ID from url params, abstracting away all the meddling with slug. - proposalIdToSlug: accept both the pure and the 0x hex form of id
- Loading branch information
Showing
8 changed files
with
33 additions
and
19 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
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { proposalIdToSlug, slugToProposalId } from './slug' | ||
import { Params } from 'react-router-dom' | ||
|
||
/** | ||
* Get the poll path from a poll or proposal id. | ||
*/ | ||
export const getPollPath = (pollId: string): string => `/${proposalIdToSlug(pollId!)}` | ||
|
||
/** | ||
* Get the poll ID from the parameters found in the URL, coming from the router. | ||
*/ | ||
export const getPollIdFromRouter = (params: Params): string => { | ||
const { slug } = params | ||
if (!slug) throw new Error("Slug should be among router parameters, but it isn't!") | ||
return slugToProposalId(slug) | ||
} |
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