-
+
diff --git a/src/features/Posts/pages/PostDetailsPage/PostDetailsPage.tsx b/src/features/Posts/pages/PostDetailsPage/PostDetailsPage.tsx
index 5c12e93..2bfd33a 100644
--- a/src/features/Posts/pages/PostDetailsPage/PostDetailsPage.tsx
+++ b/src/features/Posts/pages/PostDetailsPage/PostDetailsPage.tsx
@@ -4,6 +4,7 @@ import { useParams } from 'react-router-dom'
import LoadingPage from 'src/Components/LoadingPage/LoadingPage'
import NotFoundPage from 'src/features/Shared/pages/NotFoundPage/NotFoundPage'
import { usePostDetailsQuery } from 'src/graphql'
+import { capitalize } from 'src/utils/helperFunctions'
import { useAppSelector, } from 'src/utils/hooks'
import TrendingCard from '../../Components/TrendingCard/TrendingCard'
import AuthorCard from './Components/AuthorCard/AuthorCard'
@@ -14,7 +15,9 @@ import styles from './styles.module.scss'
export default function PostDetailsPage() {
- const { type, id } = useParams()
+ const { type: _type, id } = useParams();
+ const type = capitalize(_type);
+
const postDetailsQuery = usePostDetailsQuery({
variables: {
id: Number(id!),
diff --git a/src/utils/helperFunctions.tsx b/src/utils/helperFunctions.tsx
index b774510..8729817 100644
--- a/src/utils/helperFunctions.tsx
+++ b/src/utils/helperFunctions.tsx
@@ -92,4 +92,14 @@ export function generateList(component: React.ReactElement, cnt: number) {
return Array(cnt).fill(0).map((_, idx) => React.cloneElement(component, { key: idx }))
}
+export function toSlug(title: string) {
+ return title.toLowerCase()
+ .replace(/[^\w ]+/g, '')
+ .replace(/ +/g, '-');
+}
+
+export function capitalize(s?: string) {
+ return s && s[0].toUpperCase() + s.slice(1);
+}
+
export const withHttp = (url: string) => !/^https?:\/\//i.test(url) ? `http://${url}` : url;
\ No newline at end of file
diff --git a/src/utils/routing/index.ts b/src/utils/routing/index.ts
new file mode 100644
index 0000000..7256eea
--- /dev/null
+++ b/src/utils/routing/index.ts
@@ -0,0 +1 @@
+export * from './routes'
\ No newline at end of file
diff --git a/src/utils/routing/routes.ts b/src/utils/routing/routes.ts
new file mode 100644
index 0000000..b94a3ac
--- /dev/null
+++ b/src/utils/routing/routes.ts
@@ -0,0 +1,61 @@
+import { toSlug } from "../helperFunctions";
+
+type RouteOptions =
+ | {
+ type: 'post',
+ id: string | number,
+ postType: string,
+ title?: string,
+ username?: string,
+ }
+ | {
+ type: 'story',
+ id: string | number,
+ title?: string,
+ username?: string,
+ }
+ | {
+ type: 'bounty',
+ id: string | number,
+ title?: string,
+ username?: string,
+ }
+ | {
+ type: 'question',
+ id: string | number,
+ title?: string,
+ username?: string,
+ }
+ | {
+ type: 'profile',
+ id: string | number,
+ username?: string,
+ }
+
+export function createRoute(options: RouteOptions) {
+
+
+ if (options.type === 'post')
+ return `/blog/post/${options.postType}/${options.id}`
+ + (options.title ? `/${toSlug(options.title)}` : "");
+
+ if (options.type === 'story')
+ return `/blog/post/story/${options.id}`
+ + (options.title ? `/${toSlug(options.title)}` : "");
+
+ if (options.type === 'bounty')
+ return `/blog/post/bounty/${options.id}`
+ + (options.title ? `/${toSlug(options.title)}` : "");
+
+
+ if (options.type === 'question')
+ return `/blog/post/question/${options.id}`
+ + (options.title ? `/${toSlug(options.title)}` : "");
+
+
+ if (options.type === 'profile')
+ return `/profile/${options.id}`
+ + (options.username ? `/${toSlug(options.username)}` : "");
+
+ return ''
+}
\ No newline at end of file