Skip to content

Commit

Permalink
feat: disable medium-zoom for mobile layout
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Apr 17, 2023
1 parent 4e005d5 commit a6519df
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
3 changes: 0 additions & 3 deletions src/components/dashboard/PagesManager.tsx
Expand Up @@ -19,7 +19,6 @@ import { Tooltip } from "../ui/Tooltip"
import { Trans, useTranslation } from "next-i18next"
import { readFiles } from "~/lib/read-files"
import { PagesManagerMenu } from "./PagesManagerMenu"
import { useMobileLayout } from "~/hooks/useMobileLayout"

export const PagesManager: React.FC<{
isPost: boolean
Expand All @@ -38,8 +37,6 @@ export const PagesManager: React.FC<{
const { t } = useTranslation(["dashboard", "site"])
const date = useDate()

const isMobileLayout = useMobileLayout()

const pages = useGetPagesBySite({
type: isPost ? "post" : "page",
site: subdomain!,
Expand Down
35 changes: 19 additions & 16 deletions src/components/ui/Image.tsx
Expand Up @@ -46,23 +46,26 @@ export const Image: React.FC<TImageProps> = ({
useEffect(() => {
const $image = imageRefInternal.current
if (!$image) return
if (isMobileLayout) {
const clickHandler = () => {
window.open(getSrc(), "_blank")
}
$image.addEventListener("click", clickHandler)
return () => {
$image.removeEventListener("click", clickHandler)
}
}
if (zoom) {
import("medium-zoom").then(({ default: mediumZoom }) => {
mediumZoom($image, {
margin: 10,
background: "rgb(var(--tw-colors-i-white))",
scrollOffset: 0,
})
})
if (isMobileLayout !== undefined) {
if (isMobileLayout) {
const clickHandler = () => {
window.open(getSrc(), "_blank")
}
$image.addEventListener("click", clickHandler)
return () => {
$image.removeEventListener("click", clickHandler)
}
} else {
import("medium-zoom").then(({ default: mediumZoom }) => {
mediumZoom($image, {
margin: 10,
background: "rgb(var(--tw-colors-i-white))",
scrollOffset: 0,
})
})
}
}
}
}, [zoom, isMobileLayout])

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useMobileLayout.ts
Expand Up @@ -3,7 +3,7 @@ import { useCallback, useEffect, useState } from "react"
const mobileWidth = 1024

export function useMobileLayout() {
const [isMobile, setIsMobile] = useState(false)
const [isMobile, setIsMobile] = useState<boolean>()

const onResize = useCallback(() => {
setIsMobile(window.innerWidth < mobileWidth)
Expand Down

0 comments on commit a6519df

Please sign in to comment.