-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ui): add useBrowser hook and update image-block component
A new useBrowser hook is implemented to determine the user's browser. The image-block component from the web application has been updated to utilize this hook. A conditional transition feature is added to the image-block component, which allows image zooming transition only on Chrome desktop to prevent image flickering.
- Loading branch information
Showing
3 changed files
with
33 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './use-browser'; | ||
export * from './use-media-query'; | ||
export * from './use-time-distance'; |
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,23 @@ | ||
import * as React from 'react'; | ||
|
||
type Browser = 'internet explorer' | 'edge' | 'chrome' | 'safari' | 'firefox' | 'opera' | 'other'; | ||
|
||
export const useBrowser = () => { | ||
const [browser, setBrowser] = React.useState<Browser | null>(null); | ||
|
||
React.useEffect(() => { | ||
const userAgent = typeof window.navigator === 'undefined' ? '' : navigator.userAgent; | ||
const isOpera = !!window.opr; | ||
const isEdge = window.navigator.userAgent.indexOf('Edge') > -1; | ||
|
||
if (/Trident|MSIE/.test(userAgent)) setBrowser('internet explorer'); | ||
else if (isEdge) setBrowser('edge'); | ||
else if (/Chrome/.test(userAgent) && !isOpera && !isEdge) setBrowser('chrome'); | ||
else if (/Safari/.test(userAgent) && !isOpera && !isEdge) setBrowser('safari'); | ||
else if (/Firefox/.test(userAgent)) setBrowser('firefox'); | ||
else if (isOpera || /OPR/.test(userAgent)) setBrowser('opera'); | ||
else setBrowser('other'); | ||
}, []); | ||
|
||
return { browser }; | ||
}; |
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