Skip to content

Commit 297e32e

Browse files
committed
Changed function to check if its a deskop or not
1 parent a8bf92c commit 297e32e

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed

src/pages/general/navigation/Navigation.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Third party
2-
import React, { useMemo, useState } from 'react'
2+
import React, { useState } from 'react'
33
import { Navbar, NavLink, NavDropdown } from 'react-bootstrap'
44
import { Link } from 'react-router-dom'
55

@@ -21,24 +21,30 @@ const Navigation = (): React.ReactElement => {
2121

2222
// State for handling dropdown visibility
2323
const [showDropdown, setShowDropdown] = useState(false)
24-
const isDesktop = useMemo(() => {
25-
if (typeof window === 'undefined') return false
26-
return window.matchMedia('(hover: hover) and (pointer: fine)').matches
27-
}, [])
24+
// const isDesktop = useMemo(() => {
25+
// if (typeof window === 'undefined') return false
26+
// return window.matchMedia('(hover: hover) and (pointer: fine)').matches
27+
// }, [])
28+
29+
const isDesktop = (): boolean => {
30+
if(width < Constants.MOBILE_SIZE)
31+
return false
32+
return true
33+
}
2834
// Timeout variable to prevent flickering
2935
let hideDropdownTimeout: NodeJS.Timeout
3036

3137
// Open dropdown when hovering over "Projects"
3238
const handleMouseEnter = (): void => {
33-
if(isDesktop){
39+
if(isDesktop()){
3440
clearTimeout(hideDropdownTimeout) // Cancel hide if mouse enters again
3541
setShowDropdown(true)
3642
}
3743
}
3844

3945
// Close dropdown when mouse leaves (with small delay)
4046
const handleMouseLeave = (): void => {
41-
if(isDesktop){
47+
if(isDesktop()){
4248
hideDropdownTimeout = setTimeout(() => {
4349
setShowDropdown(false)
4450
}, 400) // Small delay before closing
@@ -82,7 +88,7 @@ const Navigation = (): React.ReactElement => {
8288
show={showDropdown}
8389
className='nav-link'
8490
onToggle={(nextShow /* boolean */) => {
85-
if (!isDesktop) setShowDropdown(nextShow)
91+
if (!isDesktop()) setShowDropdown(nextShow)
8692
}}
8793
// Close on any item selection
8894
onSelect={() => setShowDropdown(false)}>

src/setupTests.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,3 @@
55
* learn more: https://github.com/testing-library/jest-dom
66
*/
77
import '@testing-library/jest-dom'
8-
9-
// Add this before your tests run
10-
Object.defineProperty(window, 'matchMedia', {
11-
writable: true,
12-
value: jest.fn().mockImplementation(query => ({
13-
matches: false,
14-
media: query,
15-
onchange: null,
16-
addListener: jest.fn(), // deprecated
17-
removeListener: jest.fn(), // deprecated
18-
addEventListener: jest.fn(),
19-
removeEventListener: jest.fn(),
20-
dispatchEvent: jest.fn(),
21-
})),
22-
});

0 commit comments

Comments
 (0)