diff --git a/components/Loader/Preloader.tsx b/components/Loader/Preloader.tsx
index 0c1c2d31e..302018188 100644
--- a/components/Loader/Preloader.tsx
+++ b/components/Loader/Preloader.tsx
@@ -1,23 +1,38 @@
-import useLoader from 'hooks/useLoader'
+import { useEffect, useState } from 'react'
import { Spinner } from './Spinner'
+const LOADER_TIMEOUT = 2000
+
export const Preloader = ({
backgroundColor,
children,
- ...rest
+ ...spinnerProps
}: {
children: JSX.Element
backgroundColor: string
color: string
size: number
}): JSX.Element => {
- const { loader } = useLoader()
- if (!loader) return children
+ const [showLoader, setShowLoader] = useState(true)
+
+ useEffect(() => {
+ const timerId = setTimeout(() => {
+ setShowLoader(false)
+ }, LOADER_TIMEOUT)
+
+ return () => {clearTimeout(timerId)}
+ }, [])
+
return (
-
-
-
+ <>
+ {children}
+ {showLoader && (
+
+
+
+ )}
+ >
)
}
diff --git a/database/data.ts b/database/data.ts
index cf4b2f659..8305bafbf 100644
--- a/database/data.ts
+++ b/database/data.ts
@@ -269,3 +269,5 @@ export const sidebarData: ISidebar[] = [
],
},
]
+
+export const subCategories = sidebarData.flatMap(({ subcategory }) => subcategory.map(({ url }) => url.replace('/', '')))
\ No newline at end of file
diff --git a/hooks/useFilterDB.ts b/hooks/useFilterDB.ts
index ff1f2b861..b1918fcb6 100644
--- a/hooks/useFilterDB.ts
+++ b/hooks/useFilterDB.ts
@@ -1,15 +1,17 @@
import { database } from 'database/data'
import { useRouter } from 'next/router'
-import { IData, IUseFilterDBResponse } from 'types'
+import { IData } from 'types'
+import { useResults } from './ResultsContext'
-const useFilterDB = (): IUseFilterDBResponse => {
+const useFilterDB = (subcategory: string) => {
const router = useRouter()
- const { subcategory } = router.query
- if (typeof subcategory !== 'string') {
- throw new Error(
- 'UseFilterDB Error: Response of Router Query is not a string'
- )
+ const { results } = useResults()
+
+ let pageCategory = subcategory
+ if (typeof window !== 'undefined') {
+ pageCategory = router.asPath.slice(1)
}
+
// This filters trough the DB with the subcategory which results in an array of arrays
const filterSubCat = database?.map((item) =>
item?.filter((cat: IData) => cat.subcategory === subcategory)
@@ -23,6 +25,8 @@ const useFilterDB = (): IUseFilterDBResponse => {
return {
filterSubCat,
filterDB,
+ results,
+ pageCategory
}
}
diff --git a/hooks/useLoader.ts b/hooks/useLoader.ts
deleted file mode 100644
index d6f299ff2..000000000
--- a/hooks/useLoader.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import React, { useEffect, useState } from 'react'
-
-const useLoader = () => {
- const [loader, setLoader] = useState(true)
-
- useEffect(() => {
- setTimeout(() => {
- setLoader(false)
- }, 2000)
- })
-
- return { loader }
-}
-
-export default useLoader
diff --git a/pages/[subcategory]/index.tsx b/pages/[subcategory]/index.tsx
index 2c64e8ea2..89f0c6f7c 100644
--- a/pages/[subcategory]/index.tsx
+++ b/pages/[subcategory]/index.tsx
@@ -1,20 +1,23 @@
import React from 'react'
import { TopBar } from 'components/TopBar/TopBar'
-import { useRouter } from 'next/router'
import Head from 'next/head'
import useFilterDB from 'hooks/useFilterDB'
import CardsList from 'components/Cards/CardsList'
import ComingSoon from 'components/NewIssue/NewIssue'
-import { useResults } from 'hooks/ResultsContext'
-const SubCategory = () => {
- const router = useRouter()
- const { results } = useResults()
- const title = `LinksHub - ${router.asPath
- .charAt(1)
- .toUpperCase()}${router.asPath.slice(2)}`
- const { filterDB } = useFilterDB()
+import { subCategories } from 'database/data'
+import { GetStaticProps, NextPage } from 'next'
+import { ParsedUrlQuery } from 'querystring'
+interface PageProps {
+ subcategory: string
+}
+
+interface Params extends ParsedUrlQuery, PageProps{}
+
+const SubCategory: NextPage = ({subcategory}) => {
+ const {filterDB, results, pageCategory} = useFilterDB(subcategory)
+ const title = `LinksHub - ${pageCategory[0].toUpperCase() + pageCategory.slice(1)}`
let content: JSX.Element[] | JSX.Element
if (filterDB.length > 0) {
@@ -95,4 +98,20 @@ const SubCategory = () => {
)
}
+export const getStaticPaths = async () => {
+ const paths = subCategories.map(subcategory => ({
+ params: {subcategory}
+ }))
+
+ return {paths, fallback: false}
+}
+
+export const getStaticProps: GetStaticProps = async (context) => {
+ const {subcategory} = context.params as Params
+
+ return {props: {
+ subcategory
+ }}
+}
+
export default SubCategory
diff --git a/pages/index.tsx b/pages/index.tsx
index c6567a872..f95d0e303 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -3,6 +3,7 @@ import Head from 'next/head'
import Logo from 'components/logo/logo'
import TypewriterComponent from 'typewriter-effect'
import { sidebarData } from '../database/data'
+
export default function Home() {
//storing sub categories names for using in typewriter effect
const subCategoriesNames: string[] = []
diff --git a/types/index.ts b/types/index.ts
index d87f63a7c..b33b0eb37 100644
--- a/types/index.ts
+++ b/types/index.ts
@@ -68,11 +68,6 @@ export interface IContext {
toggleNav?: () => void
}
-export interface IUseFilterDBResponse {
- filterSubCat: IData[][]
- filterDB: IData[][]
-}
-
export const subcategoryArray = [
// devops
'cicd',