Skip to content

Commit

Permalink
fix: Remove Unnecessary Description Popup (#1953)
Browse files Browse the repository at this point in the history
* Remove Unnecessary Description Popup (#1945)

* Minor Fix

* Fix Build

* Apply Requested Suggestions

* Fix tooltip width for mobile

* Minor Fix
  • Loading branch information
aftabrehan authored Oct 30, 2023
1 parent 0a1ac44 commit ff022d8
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 236 deletions.
12 changes: 5 additions & 7 deletions components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import { GlobalContext } from 'context/GlobalContext'
import { ThemeToggler } from '../ThemeToggler/themeToggler'
import { TopBar } from '../TopBar/TopBar'
import { SocialMediaIconsList } from 'components/SocialMedia/SocialMediaIconsList'
import { useResults } from 'hooks/ResultsContext'

export const Header: FC = () => {
const { toggleNav } = useContext(GlobalContext)
const { results } = useResults()

return (
<header className="fixed top-0 left-0 z-30 row-start-1 row-end-2 flex h-[76px] w-screen items-center justify-between bg-light-primary dark:bg-dark border-b border-b-light-primary dark:border-b-dark-primary">
Expand All @@ -20,11 +18,11 @@ export const Header: FC = () => {
</Link>
</div>
<div className="bg-light-primary relative h-full grow px-8 dark:bg-dark lg:dark:bg-dark-primary">
<TopBar
className="absolute left-8 hidden h-full md:flex"
results={results}
/>
<div data-custom='restrict-click-outside' className="absolute right-8 flex h-full gap-4">
<TopBar className="absolute left-8 hidden h-full md:flex" />
<div
data-custom="restrict-click-outside"
className="absolute right-8 flex h-full gap-4"
>
<SocialMediaIconsList className="hidden lg:flex" />
<ThemeToggler />
<button
Expand Down
55 changes: 31 additions & 24 deletions components/TopBar/CategoryDescriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const categoryDescriptions: CategoryDescriptions = {
'UI libraries are collections of reusable components that can be used to build user interfaces. They are often used in conjunction with frameworks like React or Vue.js to create web applications.',

//backend
api: 'Interfaces that allow different software applications to communicate and share data with one another.',
architecture:
'Architecture is the art and technique of designing and building structures. It is both the process and the product of sketching, conceiving, planning, designing.',
authentication:
Expand All @@ -50,6 +51,8 @@ const categoryDescriptions: CategoryDescriptions = {
'Caching is the process of storing frequently accessed data in a cache so that it can be quickly retrieved when needed. Caching can improve the performance of applications by reducing the amount of time it takes to retrieve data from a database or other data source.',
database:
'A database is an organized collection of data that can be easily accessed, managed, and updated. Databases are used to store and manage data for various applications such as websites, mobile apps, and enterprise systems.',
'email providers':
'Platforms facilitating the exchange of electronic messages, allowing users to send, receive, and manage their emails efficiently.',
security:
'Security is the practice of protecting systems, networks, and data from unauthorized access, use, disclosure, disruption, modification, or destruction.',
'system design':
Expand Down Expand Up @@ -79,20 +82,18 @@ const categoryDescriptions: CategoryDescriptions = {
ruby: 'Ruby is a high-level, interpreted programming language that was developed in the mid-1990s by Yukihiro Matsumoto in Japan. Ruby is widely used for developing web applications, mobile applications, and desktop applications.',
typescript:
' TypeScript is a statically typed language that supports object-oriented and functional programming styles, used for developing web applications, mobile applications, and desktop applications.',
solidity:
'Solidity is an object-oriented programming language for implementing smart contracts on various blockchain platforms, most notably, Ethereum.',
solidity:
'Solidity is an object-oriented programming language for implementing smart contracts on various blockchain platforms, most notably, Ethereum.',

// Open-source
articles:
'There are many open source blogging platforms available for developers. Some of the most popular ones include WordPress, Joomla, and Drupal1. Other open source blogging platforms include Ghost, Serendipity, SilverStripe, and Jekyll',
'os programs':
'Anyone can attend Open Source events and programs; whether in-person or virtually. There are a wide variety of events and programs available to participate in, and learn more about Open Source.',
projects:
'Anyone can contribute to the projects are called OpenSource Projects. There are many open source projects available for developers. Some of the most popular ones include Linux, Git, and Apache1. Other open source projects include Kubernetes, TensorFlow, and React Native',
tools:
'There are various open source tools available for developers. Some of the most popular ones include Hadoop, VLC Media Player, and GIMP1. Other open source tools include TensorFlow, Eclipse Che, and OpenShift Do.',
'os tutorials':
'OS tutorials helps you to learn-by-watching. It contains the list most helping tutorials on open-source.',
tutorials:
'Tutorials helps you to learn-by-watching. It contains the list most helping tutorials on open-source.',

//devops
cicd: 'Continuous integration and continuous delivery (CI/CD) is a set of practices that combines continuous integration (CI) and continuous delivery (CD) to automate the process of software development and deployment.',
Expand All @@ -110,6 +111,8 @@ solidity:
'Microservices are a software development technique—a variant of the service-oriented architecture (SOA) architectural style that structures an application as a collection of loosely coupled services.',

// AI
'artificial intelligence':
'AI, or Artificial Intelligence, refers to the simulation of human intelligence in machines, enabling them to perform tasks that typically require human intelligence, such as learning, reasoning, problem-solving, and understanding natural language.',
'data science':
'Data science is an interdisciplinary field that involves the use of statistical, mathematical, and computational methods to extract insights and knowledge from data. Data science is widely used for machine learning, data analysis, and data visualization.',
'deep learning':
Expand All @@ -132,12 +135,11 @@ solidity:
//resources
blogs:
'The term “blog” is short for “weblog.” Blogs are usually maintained by an individual with regular entries of commentary, descriptions of events, or other material such as graphics or video.',
ebook:
'e book':
'An ebook (short for electronic book) is a book publication made available in digital form, consisting of text, images, or both readable on the flat-panel display of computers or other electronic devices.',
hosting:
'Web hosting is an online service that makes the content of your website accessible on the internet. When you purchase a hosting plan, you are renting space on a physical server to store all the files and data.',
dsa:
'Data Structures and Algorithms play an important role in tech placements. So here is a list of important and great dsa resources',
dsa: 'Data Structures and Algorithms play an important role in tech placements. So here is a list of important and great dsa resources',
officialdocs:
'Official docs is short for official documentation. Official documentation is an important resource for users of software products and services as it provides a comprehensive guide to using the software.',
'project ideas':
Expand Down Expand Up @@ -174,33 +176,38 @@ solidity:
devtools:
'This list of Development tools will help you boost your programming speed and modify your projects to the next level.',
github: 'Well, Github does not need description, devs know well!',
git: 'Your friendly neighborhood version control system to track the development activities.',
git: 'Your friendly neighborhood version control system to track the development activities.',
'other resources':
'Some extra resources to help you in your coding projects.',
podcasts: 'Coding podcasts to listen to when you feel demotivated.',
contributors:
'These are the people that have helped LinksHub come to life! Thank you for your support! Note: M = Maintainer and C = Contributors',

// Placement-Prep
'interview preparation' : 'Diverse resources for developers to enhance interview skills, including articles, videos, and mock interview platforms.',
'job portals' : 'Explore top job portals, their features, and expert tips for efficient job searching and connecting with employers.',
'resume building' : 'Providing resources to help developers create compelling resumes that showcase their skills and experience.',
'portfolio building' : 'Offer templates and examples to assist developers in building impressive portfolios that highlight their work and accomplishments.',
'career guidance' : 'Explore resources, articles, and guidance for career planning, goal setting, and professional growth in the tech industry.',
certifications : 'Curated list of globally recognized tech certifications, including requirements, benefits, and preparation strategies, emphasizing industry recognition and validity.',

'interview preparation':
'Diverse resources for developers to enhance interview skills, including articles, videos, and mock interview platforms.',
'job portals':
'Explore top job portals, their features, and expert tips for efficient job searching and connecting with employers.',
'resume building':
'Providing resources to help developers create compelling resumes that showcase their skills and experience.',
'portfolio building':
'Offer templates and examples to assist developers in building impressive portfolios that highlight their work and accomplishments.',
'career guidance':
'Explore resources, articles, and guidance for career planning, goal setting, and professional growth in the tech industry.',
certifications:
'Curated list of globally recognized tech certifications, including requirements, benefits, and preparation strategies, emphasizing industry recognition and validity.',

//technical-writing
'technical writing tools':
'This list provides the tools to suit your tech writing needs.',

//data-structures
'dsa articles':
'This section provides various important articles related to DSA problem solving skills, how to tackle them, how to think about it and many more.',
'dsa courses' :
'This section provides various online courses that can help you start with the fundamentals of data structures and algorithms and also ace your coding interviews.' ,
'This section provides various important articles related to DSA problem solving skills, how to tackle them, how to think about it and many more.',
'dsa courses':
'This section provides various online courses that can help you start with the fundamentals of data structures and algorithms and also ace your coding interviews.',
'dsa tutorials':
'This section provides you with YouTube tutorials that help you grasp concepts better by hands-on experience and learn better, practically!'

'This section provides you with YouTube tutorials that help you grasp concepts better by hands-on experience and learn better, practically!',
}

export default categoryDescriptions
171 changes: 49 additions & 122 deletions components/TopBar/TopBar.tsx
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
}
27 changes: 27 additions & 0 deletions components/TopBar/utils.ts
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
}
Loading

1 comment on commit ff022d8

@vercel
Copy link

@vercel vercel bot commented on ff022d8 Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.