-
-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Remove Unnecessary Description Popup (#1953)
* Remove Unnecessary Description Popup (#1945) * Minor Fix * Fix Build * Apply Requested Suggestions * Fix tooltip width for mobile * Minor Fix
- Loading branch information
1 parent
0a1ac44
commit ff022d8
Showing
10 changed files
with
125 additions
and
236 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,140 +1,67 @@ | ||
import { FC, useEffect, useState } from 'react' | ||
import { FC } from 'react' | ||
import { useRouter } from 'next/router' | ||
import { useTheme } from 'next-themes' | ||
import { FaSlackHash, FaInfoCircle } from 'react-icons/fa' | ||
import PopupDesc from 'components/popup/popupCategoryDesc' | ||
import { ICategoryData } from 'types' | ||
import categoryDescriptions from './CategoryDescriptions' | ||
import { useResults } from 'hooks/ResultsContext' | ||
import { Tooltip } from 'react-tooltip' | ||
import { isValidResource, regEx } from './utils' | ||
|
||
interface TopBarProps { | ||
className?: string | ||
results: number | ||
} | ||
|
||
export const TopBar: FC<TopBarProps> = ({ className }) => { | ||
const { results } = useResults() | ||
const [isSearchFound, setIsSearchFound] = useState(false) | ||
const [currentCategory, setCurrentCategory] = useState<ICategoryData | null>( | ||
null | ||
) | ||
const router = useRouter() | ||
const { theme } = useTheme() | ||
|
||
const category = router.asPath | ||
const categoryName = category.split('/')[1].split('-').join(' ') | ||
const subcategoryName = category?.split('/')[2]?.split('-').join(' ') | ||
const regEx = /[ `!@#$%^&*()_+\=\[\]{};':"\\|,.<>\/?~]/g | ||
let cleanedCategory = '' | ||
if (subcategoryName) { | ||
cleanedCategory = subcategoryName | ||
.replaceAll(regEx, ' ') | ||
.replaceAll('search query ', '') | ||
} else { | ||
cleanedCategory = categoryName | ||
.replaceAll(regEx, ' ') | ||
.replaceAll('search query ', '') | ||
} | ||
|
||
useEffect(() => { | ||
if (results > 0) { | ||
setIsSearchFound(true) | ||
} else if (results === 0) { | ||
setIsSearchFound(false) | ||
} | ||
}, [results]) | ||
const searchQuery = router.query.query?.toString() || '' | ||
|
||
if (router.pathname.length === 1) { | ||
return null | ||
} | ||
|
||
const handleCardClick: () => void = () => { | ||
const description = categoryDescriptions[subcategoryName] || '' | ||
const categoryInfo = { | ||
name: subcategoryName, | ||
description, | ||
} | ||
setCurrentCategory(categoryInfo) | ||
} | ||
let cleanedCategory = '' | ||
cleanedCategory = (subcategoryName || categoryName) | ||
.replaceAll(regEx, ' ') | ||
.replaceAll('search query ', '') | ||
|
||
const removeCurrentCard: () => void = () => { | ||
setCurrentCategory(null) | ||
} | ||
const description = categoryDescriptions[searchQuery || subcategoryName] || '' | ||
const isResourceSelected = isValidResource(searchQuery || subcategoryName) | ||
|
||
return ( | ||
<> | ||
{subcategoryName && ( | ||
<> | ||
{isSearchFound ? ( | ||
<div | ||
data-custom="restrict-click-outside" | ||
className={`flex items-center text-xl dark:text-gray-300 ${className}`} | ||
> | ||
<FaSlackHash className="mr-2 text-gray-600 dark:text-gray-300" /> | ||
<span className="flex uppercase text-gray-900 dark:text-gray-100"> | ||
{isSearchFound ? `${cleanedCategory}` : `No Results Found`} | ||
</span> | ||
<button> | ||
<FaInfoCircle | ||
data-tooltip-id="info-tooltip" | ||
data-tooltip-content="Description" | ||
data-tooltip-place="bottom" | ||
className="ml-4 mt-2 text-sm cursor-pointer hover:text-theme-primary" | ||
onClick={handleCardClick} | ||
/> | ||
</button> | ||
<Tooltip | ||
id="info-tooltip" | ||
style={{ | ||
backgroundColor: '#8b5cf6', | ||
fontSize: '13px', | ||
paddingLeft: '6px', | ||
paddingRight: '6px', | ||
paddingTop: '2px', | ||
paddingBottom: '2px', | ||
}} | ||
/> | ||
<PopupDesc | ||
currentCategory={currentCategory} | ||
onClose={removeCurrentCard} | ||
/> | ||
</div> | ||
) : ( | ||
<div | ||
data-custom="restrict-click-outside" | ||
className={`flex items-center text-xl dark:text-gray-300 ${className}`} | ||
> | ||
<FaSlackHash className="mr-2 text-gray-600 dark:text-gray-300" /> | ||
<span className="flex uppercase text-gray-900 dark:text-gray-100"> | ||
{subcategoryName} | ||
</span> | ||
<button> | ||
<FaInfoCircle | ||
// data-custom="restrict-click-outside" | ||
data-tooltip-id="info-tooltip" | ||
data-tooltip-content="Description" | ||
data-tooltip-place="bottom" | ||
className="ml-4 mt-2 text-sm cursor-pointer hover:text-theme-primary outline-none" | ||
onClick={handleCardClick} | ||
/> | ||
</button> | ||
<Tooltip | ||
id="info-tooltip" | ||
style={{ | ||
backgroundColor: '#8b5cf6', | ||
fontSize: '13px', | ||
paddingLeft: '6px', | ||
paddingRight: '6px', | ||
paddingTop: '2px', | ||
paddingBottom: '2px', | ||
}} | ||
/> | ||
<PopupDesc | ||
currentCategory={currentCategory} | ||
onClose={removeCurrentCard} | ||
/> | ||
</div> | ||
)} | ||
</> | ||
)} | ||
</> | ||
) | ||
if (router.pathname.length === 1) return null | ||
return isResourceSelected ? ( | ||
<div | ||
className={`flex items-center text-xl dark:text-gray-300 ${className}`} | ||
> | ||
<FaSlackHash className="mr-2 text-gray-600 dark:text-gray-300" /> | ||
<span className="flex uppercase text-gray-900 dark:text-gray-100"> | ||
{cleanedCategory} | ||
</span> | ||
<button> | ||
<FaInfoCircle | ||
data-tooltip-id="info-tooltip" | ||
data-tooltip-place="bottom" | ||
data-tooltip-content={description} | ||
className="ml-4 mt-2 text-sm cursor-pointer hover:text-theme-primary" | ||
/> | ||
</button> | ||
<Tooltip | ||
id="info-tooltip" | ||
opacity="1" | ||
style={{ | ||
backgroundColor: '#8b5cf6', | ||
fontSize: '13px', | ||
paddingLeft: '6px', | ||
paddingRight: '6px', | ||
paddingTop: '2px', | ||
paddingBottom: '2px', | ||
width: 'calc(100vw - 2rem)', | ||
maxWidth: '400px', | ||
boxShadow: | ||
theme === 'light' | ||
? '0 0 8px #bdbdbd' | ||
: '0 0 0 2px rgba(189, 189, 189, 0.25)', | ||
}} | ||
/> | ||
</div> | ||
) : null | ||
} |
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,27 @@ | ||
import { sidebarData } from 'database/data' | ||
|
||
export const regEx = /[ `!@#$%^&*()_+\=\[\]{};':"\\|,.<>\/?~]/g | ||
|
||
const cleanText = (text: string) => | ||
text | ||
.toLocaleLowerCase() | ||
.replaceAll(regEx, ' ') | ||
.replaceAll(' ', ' ') | ||
.replaceAll('-', ' ') | ||
|
||
export const isValidResource = (name: string) => { | ||
if (!name) return | ||
|
||
const subCategoryNames: string[] = [] | ||
sidebarData.forEach((category) => | ||
category.subcategory.forEach((subcategory) => | ||
subCategoryNames.push(subcategory.url?.replaceAll('/', '')) | ||
) | ||
) | ||
|
||
const isValid = !!subCategoryNames?.find( | ||
(n) => cleanText(n) === cleanText(name) | ||
) | ||
|
||
return isValid | ||
} |
Oops, something went wrong.
ff022d8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
linkshub – ./
linkshub.vercel.app
linkshub-git-main-rupali-codes.vercel.app
www.linkshub.dev
linkshub-rupali-codes.vercel.app
linkshub.dev