Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/scenes/News/image-zoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ const Overlay = styled.div<{ visible: boolean }>`
opacity: ${({ visible }) => (visible ? 1 : 0)};
pointer-events: ${({ visible }) => (visible ? "auto" : "none")};
transition: opacity 0.2s ease-in-out;
cursor: pointer;
`

const Wrapper = styled.div`
z-index: 1001;
cursor: pointer;

img {
border: 1px solid ${({ theme }) => theme.color.offWhite};
Expand Down Expand Up @@ -72,9 +74,12 @@ export const ImageZoom = () => {

return (
<Root ref={rootRef} visible={imageToZoom !== undefined}>
<Overlay visible={imageToZoom !== undefined} />
<Overlay
visible={imageToZoom !== undefined}
onClick={() => dispatch(actions.console.setImageToZoom(undefined))}
/>
{imageToZoom && (
<Wrapper>
<Wrapper onClick={() => dispatch(actions.console.setImageToZoom(undefined))}>
<Thumbnail
{...imageToZoom}
containerWidth={rootWidth ? rootWidth * 0.9 : 460}
Expand Down
24 changes: 15 additions & 9 deletions src/scenes/News/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
PrimaryToggleButton,
} from "../../components"
import styled from "styled-components"
import React, { useEffect, useState, useContext } from "react"
import React, { useEffect, useState, useContext, useRef } from "react"
import { QuestContext } from "../../providers"
import { NewsItem } from "../../utils"
import { useDispatch, useSelector } from "react-redux"
Expand Down Expand Up @@ -93,8 +93,11 @@ const News = () => {
// This boolean is to animate the bell icon and display a bullet indicator
const [hasUnreadNews, setHasUnreadNews] = useState(false)
const activeSidebar = useSelector(selectors.console.getActiveSidebar)
const imageToZoom = useSelector(selectors.console.getImageToZoom)

let hoverTimeout: ReturnType<typeof setTimeout>
const hoverTimeoutRef = useRef<ReturnType<typeof setTimeout>>()
const imageToZoomRef = useRef(imageToZoom)
imageToZoomRef.current = imageToZoom

const getEnterpriseNews = async () => {
setIsLoading(true)
Expand Down Expand Up @@ -248,7 +251,7 @@ const News = () => {
? {
onMouseOver: () => {
if (newsItem.thumbnail) {
hoverTimeout = setTimeout(() => {
hoverTimeoutRef.current = setTimeout(() => {
if (newsItem && newsItem.thumbnail) {
dispatch(
actions.console.setImageToZoom({
Expand All @@ -268,12 +271,15 @@ const News = () => {
}
},
onMouseOut: () => {
clearTimeout(hoverTimeout)
setTimeout(() => {
dispatch(
actions.console.setImageToZoom(undefined),
)
}, 250)
clearTimeout(hoverTimeoutRef.current)
// Only dismiss if zoom isn't visible (overlay intercepts mouse when visible)
if (!imageToZoomRef.current) {
setTimeout(() => {
dispatch(
actions.console.setImageToZoom(undefined),
)
}, 250)
}
},
}
: {})}
Expand Down