Skip to content

Commit

Permalink
feat(docs): apply Renewal useViewport hook to Viewport docs
Browse files Browse the repository at this point in the history
  • Loading branch information
LTakhyunKim committed Jan 3, 2023
1 parent 2654854 commit 92ff2fd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
20 changes: 16 additions & 4 deletions apps/insight-viewer-docs/containers/Viewport/Image1.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import { useEffect, useCallback } from 'react'
import { useRef, useEffect, useCallback } from 'react'
import { Box, Stack, Switch, Button } from '@chakra-ui/react'
import InsightViewer, { useImage, useViewport, Viewport } from '@lunit/insight-viewer'
import InsightViewer, { useImage, Viewport } from '@lunit/insight-viewer'
import { useViewport } from '@lunit/insight-viewer/viewport'

import { IMAGES } from '@insight-viewer-library/fixtures'
import { ViewerWrapper } from '../../components/Wrapper'
import CustomProgress from '../../components/CustomProgress'
import OverlayLayer from '../../components/OverlayLayer'
import { INITIAL_VIEWPORT1 } from './const'

export default function Image1(): JSX.Element {
const viewerRef = useRef<HTMLDivElement>(null)

const { loadingState, image } = useImage({
wadouri: IMAGES[0],
})
const { viewport, setViewport, resetViewport, initialized } = useViewport({
initialViewport: INITIAL_VIEWPORT1,
image,
element: viewerRef.current,
options: { fitScale: false },
getInitialViewport: (prevViewport) => ({ ...prevViewport, ...INITIAL_VIEWPORT1 }),
})

const updateViewport = useCallback(
Expand Down Expand Up @@ -201,7 +207,13 @@ export default function Image1(): JSX.Element {
</Stack>
<Box data-cy-loaded={loadingState} data-cy-viewport={initialized}>
<ViewerWrapper className="viewer1">
<InsightViewer image={image} viewport={viewport} onViewportChange={setViewport} Progress={CustomProgress}>
<InsightViewer
viewerRef={viewerRef}
image={image}
viewport={viewport}
onViewportChange={setViewport}
Progress={CustomProgress}
>
<OverlayLayer viewport={viewport} />
</InsightViewer>
</ViewerWrapper>
Expand Down
25 changes: 19 additions & 6 deletions apps/insight-viewer-docs/containers/Viewport/Image2.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import { useEffect, useCallback } from 'react'
import { useRef, useEffect, useCallback } from 'react'
import { Box, Stack, Button } from '@chakra-ui/react'
import InsightViewer, { useImage, useViewport, Viewport } from '@lunit/insight-viewer'
import InsightViewer, { useImage, Viewport } from '@lunit/insight-viewer'
import { useViewport } from '@lunit/insight-viewer/viewport'
import { IMAGES } from '@insight-viewer-library/fixtures'
import { ViewerWrapper } from '../../components/Wrapper'
import CustomProgress from '../../components/CustomProgress'
import OverlayLayer from '../../components/OverlayLayer'
import { INITIAL_VIEWPORT2 } from './const'

export default function Image1(): JSX.Element {
export default function Image2(): JSX.Element {
const viewerRef = useRef<HTMLDivElement>(null)

const { image } = useImage({
wadouri: IMAGES[11],
})
const { viewport, setViewport, resetViewport } = useViewport({ initialViewport: INITIAL_VIEWPORT2 })

const { viewport, setViewport, resetViewport } = useViewport({
image,
element: viewerRef.current,
options: { fitScale: false },
getInitialViewport: (prevViewport) => ({ ...prevViewport, ...INITIAL_VIEWPORT2 }),
})
const updateViewport = useCallback(
(key: keyof Viewport, value: unknown) => {
setViewport((prev: Viewport) => ({
Expand Down Expand Up @@ -101,7 +108,13 @@ export default function Image1(): JSX.Element {
</Stack>
<Box>
<ViewerWrapper className="viewer2">
<InsightViewer image={image} viewport={viewport} onViewportChange={setViewport} Progress={CustomProgress}>
<InsightViewer
viewerRef={viewerRef}
image={image}
viewport={viewport}
onViewportChange={setViewport}
Progress={CustomProgress}
>
<OverlayLayer viewport={viewport} />
</InsightViewer>
</ViewerWrapper>
Expand Down

0 comments on commit 92ff2fd

Please sign in to comment.