-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve mobile responsive for hero section and
- Loading branch information
1 parent
9ebf947
commit fdd3e68
Showing
11 changed files
with
111 additions
and
66 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
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,38 +1,43 @@ | ||
import { useEffect, useState } from "react" | ||
import CircularTile from "./CircularTile" | ||
import { useEffect, useState } from 'react' | ||
import CircularTile from '@/components/CircularTile' | ||
import { useMediaQuery } from '@/hooks/generic/useMediaQuery' | ||
|
||
const LoadingAnimation = ({className, isLoading}: {className?: string; isLoading: boolean}) => { | ||
const [rotations, setRotations] = useState([0, 0, 0, 0]); | ||
const LoadingAnimation = ({ className, isLoading }: { className?: string; isLoading: boolean }) => { | ||
const [rotations, setRotations] = useState([0, 0, 0, 0]) | ||
|
||
// Determine if the screen width is medium or larger | ||
const isMediumOrLarger = useMediaQuery('(min-width: 768px)') | ||
|
||
const getRandRotation = () => { | ||
const rand_index = Math.floor(Math.random() * 4) | ||
const rotation = [0, 90, 180, 270][rand_index] | ||
return rotation; | ||
return rotation | ||
} | ||
|
||
useEffect(() => { | ||
const interval = setInterval(() => { | ||
if(isLoading) { | ||
setRotations([getRandRotation(),getRandRotation(),getRandRotation(),getRandRotation()]); | ||
if (isLoading) { | ||
setRotations([getRandRotation(), getRandRotation(), getRandRotation(), getRandRotation()]) | ||
} | ||
}, 500); | ||
}, 500) | ||
|
||
if(!isLoading) { | ||
if (!isLoading) { | ||
clearInterval(interval) | ||
} | ||
|
||
return () => clearInterval(interval); | ||
}, [rotations, isLoading]); | ||
return () => clearInterval(interval) | ||
}, [rotations, isLoading]) | ||
|
||
// Adjust size based on screen width | ||
const sizeClasses = isMediumOrLarger ? 'w-10 h-10' : 'w-6 h-6' | ||
|
||
return ( | ||
<div className={`grid grid-cols-2 gap-1 w-10 h-10 ${className}`}> | ||
<div className={`grid grid-cols-2 gap-6 md:gap-1 ${sizeClasses} ${className}`}> | ||
{rotations.map((rotation, i) => { | ||
return ( | ||
<CircularTile key={i} className="!fill-slate-600 duration-500 ease-in-out" rotation={rotation}/> | ||
) | ||
return <CircularTile key={i} className='!fill-slate-600 duration-500 ease-in-out' rotation={rotation} /> | ||
})} | ||
</div> | ||
) | ||
} | ||
|
||
export default LoadingAnimation | ||
export default LoadingAnimation |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { useEffect, useState } from 'react' | ||
|
||
export const useMediaQuery = (query: string): boolean => { | ||
const [matches, setMatches] = useState<boolean>(false) | ||
|
||
useEffect(() => { | ||
const media = window.matchMedia(query) | ||
const listener = (event: MediaQueryListEvent) => { | ||
setMatches(event.matches) | ||
} | ||
|
||
media.addEventListener('change', listener) | ||
|
||
if (media.matches !== matches) { | ||
setMatches(media.matches) | ||
} | ||
|
||
return () => { | ||
media.removeEventListener('change', listener) | ||
} | ||
}, [matches, query]) | ||
|
||
return matches | ||
} |
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
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