-
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.
Merge branch 'master' into 7-teachers-page
- Loading branch information
Showing
26 changed files
with
158 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import {MouseEvent} from 'react'; | ||
import clsx from 'clsx'; | ||
import Image from 'next/image'; | ||
import {forwardRef} from 'react'; | ||
import {useHotkeys} from 'react-hotkeys-hook'; | ||
import {customCursorClickableClass} from '@/lib/customCursor/customCursorClickableClass'; | ||
import useDisableRightClick from '@/lib/shared/useDisableRightClick'; | ||
import {useAssignRefs} from '@/lib/shared/useAssignRefs'; | ||
import useNetworkSpeed from '@/lib/shared/useNetworkSpeed'; | ||
import AppearInViewport from '../AppearInViewport/AppearInViewport'; | ||
|
||
/** | ||
* Props. | ||
*/ | ||
type GalleryItemProps = { | ||
src: string; | ||
blurDataURL: string; | ||
open: (e: MouseEvent) => void; | ||
}; | ||
|
||
const imgCn = clsx('rounded-md', 'overflow-hidden'); | ||
const overflowCn = clsx( | ||
customCursorClickableClass, | ||
'relative', | ||
'after:absolute', | ||
'after:content-[""]', | ||
'after:w-full', | ||
'after:h-full', | ||
'after:top-0', | ||
'after:left-0', | ||
'after:bg-[radial-gradient(circle,_var(--tw-gradient-stops))] from-white to-transparent', | ||
'after:transition-opacity', | ||
'after:duration-300', | ||
'after:ease-out', | ||
'after:opacity-0', | ||
'hover:after:opacity-20', | ||
'transition-transform', | ||
'duration-500', | ||
'ease-out', | ||
'hover:translate-y-1', | ||
'rounded-md', | ||
'focus-ring', | ||
); | ||
|
||
/** | ||
* @returns React component. | ||
*/ | ||
const GalleryImage = forwardRef<HTMLImageElement, GalleryItemProps>(function GalleryItem( | ||
{open, src, blurDataURL}, | ||
ref, | ||
) { | ||
const hotkeysRef = useHotkeys<HTMLDivElement>(['enter', 'space'], open as any, { | ||
preventDefault: true, | ||
}); | ||
const disableRef = useDisableRightClick(); | ||
const finalRef = useAssignRefs(hotkeysRef, disableRef); | ||
const [, isFast] = useNetworkSpeed(); | ||
|
||
return ( | ||
<AppearInViewport> | ||
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */} | ||
<div | ||
className={overflowCn} | ||
style={{height: 300, width: 400}} | ||
onClick={open} | ||
tabIndex={0} | ||
role="link" | ||
ref={finalRef} | ||
> | ||
<Image | ||
className={imgCn} | ||
ref={ref} | ||
src={src} | ||
placeholder="blur" | ||
blurDataURL={blurDataURL} | ||
quality={isFast ? 75 : 25} | ||
alt="" | ||
fill | ||
/> | ||
</div> | ||
</AppearInViewport> | ||
); | ||
}); | ||
|
||
export default GalleryImage; |
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,78 +1,46 @@ | ||
import {MouseEvent} from 'react'; | ||
import clsx from 'clsx'; | ||
import Image from 'next/image'; | ||
import {forwardRef} from 'react'; | ||
import {useHotkeys} from 'react-hotkeys-hook'; | ||
import {customCursorClickableClass} from '@/lib/customCursor/customCursorClickableClass'; | ||
import AppearInViewport from '../AppearInViewport/AppearInViewport'; | ||
import {MutableRefObject} from 'react'; | ||
import {Item} from 'react-photoswipe-gallery'; | ||
import 'photoswipe/dist/photoswipe.css'; | ||
import GalleryImage from './GalleryImage'; | ||
|
||
/** | ||
* Props. | ||
*/ | ||
type GalleryItemProps = { | ||
src: string; | ||
blurDataURL: string; | ||
open: (e: MouseEvent) => void; | ||
dimensions: { | ||
width: number; | ||
height: number; | ||
}; | ||
}; | ||
|
||
const imgCn = clsx('rounded-md', 'overflow-hidden'); | ||
const overflowCn = clsx( | ||
customCursorClickableClass, | ||
'relative', | ||
'after:absolute', | ||
'after:content-[""]', | ||
'after:w-full', | ||
'after:h-full', | ||
'after:top-0', | ||
'after:left-0', | ||
'after:bg-[radial-gradient(circle,_var(--tw-gradient-stops))] from-white to-transparent', | ||
'after:transition-opacity', | ||
'after:duration-300', | ||
'after:ease-out', | ||
'after:opacity-0', | ||
'hover:after:opacity-20', | ||
'transition-transform', | ||
'duration-500', | ||
'ease-out', | ||
'hover:translate-y-1', | ||
'rounded-md', | ||
'focus-ring', | ||
); | ||
|
||
/** | ||
* @param {GalleryItemProps} props Props. | ||
* @returns React component. | ||
*/ | ||
const GalleryItem = forwardRef<HTMLImageElement, GalleryItemProps>(function GalleryItem( | ||
{open, src, blurDataURL}, | ||
ref, | ||
) { | ||
const hotkeysRef = useHotkeys<HTMLDivElement>(['enter', 'space'], open as any, { | ||
preventDefault: true, | ||
}); | ||
|
||
export default function GalleryItem({ | ||
src, | ||
blurDataURL, | ||
dimensions: {width, height}, | ||
}: GalleryItemProps) { | ||
return ( | ||
<AppearInViewport> | ||
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */} | ||
<div | ||
className={overflowCn} | ||
style={{height: 300, width: 400}} | ||
onClick={open} | ||
tabIndex={0} | ||
role="link" | ||
ref={hotkeysRef} | ||
> | ||
<Image | ||
className={imgCn} | ||
ref={ref} | ||
src={src} | ||
placeholder="blur" | ||
<Item | ||
original={src} | ||
thumbnail={src} | ||
alt="" | ||
width={width} | ||
height={height} | ||
key={src} | ||
> | ||
{({open, ref}) => ( | ||
<GalleryImage | ||
open={open} | ||
ref={ref as MutableRefObject<HTMLImageElement>} | ||
blurDataURL={blurDataURL} | ||
alt="" | ||
fill | ||
src={src} | ||
/> | ||
</div> | ||
</AppearInViewport> | ||
)} | ||
</Item> | ||
); | ||
}); | ||
|
||
export default GalleryItem; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {useEffect, useRef} from 'react'; | ||
|
||
/** | ||
* @returns Ref to register. | ||
*/ | ||
export default function useDisableRightClick<T extends HTMLElement>() { | ||
const ref = useRef<T>(null); | ||
|
||
useEffect(() => { | ||
const node = ref.current; | ||
|
||
if (node) { | ||
// eslint-disable-next-line jsdoc/require-jsdoc | ||
const handleContextMenu = (e: Event) => { | ||
e.preventDefault(); | ||
e.stopImmediatePropagation(); | ||
}; | ||
|
||
node.addEventListener('contextmenu', handleContextMenu); | ||
|
||
return () => { | ||
node.removeEventListener('contextmenu', handleContextMenu); | ||
}; | ||
} | ||
}, [ref]); | ||
|
||
return ref; | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.