diff --git a/src/components/Dashboard/common/ThreeDPreview.jsx b/src/components/Dashboard/common/ThreeDPreview.jsx
index 20f19d1..d80ab9e 100644
--- a/src/components/Dashboard/common/ThreeDPreview.jsx
+++ b/src/components/Dashboard/common/ThreeDPreview.jsx
@@ -10,10 +10,7 @@ function ThreeDPreview(props) {
width = 500,
height = 500,
style = {},
- backgroundColor = '#ffffff',
- showGrid = true,
- showAxes = true,
- enableControls = true
+ backgroundColor = '#ffffff'
} = props
const containerRef = useRef(null)
const viewer = useRef(null)
@@ -34,6 +31,9 @@ function ThreeDPreview(props) {
}, [viewer, width, height])
useEffect(() => {
+ // Variable to track the viewer instance created in this effect
+ let currentViewer = null
+
const initializeViewer = async () => {
if (!containerRef.current) return
@@ -42,7 +42,10 @@ function ThreeDPreview(props) {
setError(null)
// Clear any existing viewer
- if (viewer) {
+ if (viewer.current) {
+ if (viewer.current.dispose) {
+ viewer.current.dispose()
+ }
containerRef.current.innerHTML = ''
}
@@ -71,6 +74,10 @@ function ThreeDPreview(props) {
environmentSettings: new OV.EnvironmentSettings([], false)
})
+ // Store the viewer instance in the ref and local variable
+ viewer.current = newViewer
+ currentViewer = newViewer
+
try {
setIsLoading(true)
setError(null)
@@ -105,11 +112,11 @@ function ThreeDPreview(props) {
return () => {
window.removeEventListener('resize', resizeViewer)
- if (viewer.current && viewer.current.dispose) {
- viewer.current.dispose()
+ if (currentViewer && currentViewer.dispose) {
+ currentViewer.dispose()
}
}
- }, [width, height, backgroundColor, showGrid, showAxes, enableControls, src])
+ }, [width, height, src, extension, resizeViewer])
const containerStyle = {
width: width + 'px',
diff --git a/src/components/Dashboard/context/ApiServerContext.jsx b/src/components/Dashboard/context/ApiServerContext.jsx
index bf4ea75..2c3c3fa 100644
--- a/src/components/Dashboard/context/ApiServerContext.jsx
+++ b/src/components/Dashboard/context/ApiServerContext.jsx
@@ -8,7 +8,7 @@ import {
useCallback
} from 'react'
import io from 'socket.io-client'
-import { message, notification, Modal, Space, Button } from 'antd'
+import { message, Modal, Space, Button } from 'antd'
import PropTypes from 'prop-types'
import { AuthContext } from './AuthContext'
@@ -30,7 +30,6 @@ const ApiServerProvider = ({ children }) => {
const [connecting, setConnecting] = useState(false)
const [error, setError] = useState(null)
const [messageApi, contextHolder] = message.useMessage()
- const [notificationApi] = notification.useNotification()
const [fetchLoading, setFetchLoading] = useState(false)
const [showErrorModal, setShowErrorModal] = useState(false)
const [errorModalContent, setErrorModalContent] = useState('')
@@ -125,7 +124,7 @@ const ApiServerProvider = ({ children }) => {
socketRef.current = newSocket
}
- }, [token, authenticated, messageApi, notificationApi, handleLockUpdate])
+ }, [token, authenticated, messageApi, handleLockUpdate, clearSubscriptions])
useEffect(() => {
if (token && authenticated == true) {
@@ -539,7 +538,7 @@ const ApiServerProvider = ({ children }) => {
return () => offObjectEventEvent(id, objectType, eventType, callback)
}
},
- [offObjectUpdatesEvent]
+ [offObjectEventEvent]
)
const offModelStats = useCallback((objectType, callback) => {
diff --git a/src/components/Dashboard/context/AuthContext.jsx b/src/components/Dashboard/context/AuthContext.jsx
index 58b49a4..b65e93c 100644
--- a/src/components/Dashboard/context/AuthContext.jsx
+++ b/src/components/Dashboard/context/AuthContext.jsx
@@ -338,12 +338,12 @@ const AuthProvider = ({ children }) => {
}
},
[
- isElectron,
navigate,
location.search,
location.pathname,
messageApi,
- persistSession
+ persistSession,
+ redirectType
]
)
diff --git a/src/components/Dashboard/context/ElectronContext.jsx b/src/components/Dashboard/context/ElectronContext.jsx
index 3db5329..d8630f5 100644
--- a/src/components/Dashboard/context/ElectronContext.jsx
+++ b/src/components/Dashboard/context/ElectronContext.jsx
@@ -7,6 +7,7 @@ const electron = window.require ? window.require('electron') : null
const ipcRenderer = electron ? electron.ipcRenderer : null
// Utility to check if running in Electron
+// eslint-disable-next-line react-refresh/only-export-components
export function isElectron() {
// Renderer process
@@ -88,6 +89,7 @@ const ElectronProvider = ({ children }) => {
// Listen for navigate
const navigateHandler = (event, url) => {
console.log('Navigating to:', url)
+
navigate(url)
}
ipcRenderer.on('navigate', navigateHandler)
@@ -96,7 +98,7 @@ const ElectronProvider = ({ children }) => {
ipcRenderer.removeListener('navigate', navigateHandler)
ipcRenderer.removeListener('window-state', windowStateHandler)
}
- }, [])
+ }, [navigate])
// Window control handler
const handleWindowControl = (action) => {
diff --git a/src/components/Dashboard/context/MessageContext.jsx b/src/components/Dashboard/context/MessageContext.jsx
index 5f0cfd5..cdea2c8 100644
--- a/src/components/Dashboard/context/MessageContext.jsx
+++ b/src/components/Dashboard/context/MessageContext.jsx
@@ -47,6 +47,7 @@ MessageProvider.propTypes = {
children: PropTypes.node.isRequired
}
+// eslint-disable-next-line react-refresh/only-export-components
export const useMessageContext = () => {
const context = useContext(MessageContext)
if (!context) {
diff --git a/src/components/Dashboard/context/SpotlightContext.jsx b/src/components/Dashboard/context/SpotlightContext.jsx
index 0c1f87f..9dda2bb 100644
--- a/src/components/Dashboard/context/SpotlightContext.jsx
+++ b/src/components/Dashboard/context/SpotlightContext.jsx
@@ -17,7 +17,8 @@ import {
useState,
useRef,
createElement,
- useContext
+ useContext,
+ useCallback
} from 'react'
import axios from 'axios'
import { LoadingOutlined } from '@ant-design/icons'
@@ -608,7 +609,7 @@ const ElectronSpotlightContentPage = () => {
const { resizeSpotlightWindow, isElectron } = useContext(ElectronContext)
// Function to measure and resize window
- const updateWindowHeight = () => {
+ const updateWindowHeight = useCallback(() => {
if (!cardRef.current || !isElectron || !resizeSpotlightWindow) return
// Clear any pending resize
@@ -639,7 +640,7 @@ const ElectronSpotlightContentPage = () => {
console.warn('Failed to update spotlight window height:', error)
}
}, 100) // 100ms debounce
- }
+ }, [isElectron, resizeSpotlightWindow])
// Use ResizeObserver to watch for content changes
useEffect(() => {
@@ -666,7 +667,7 @@ const ElectronSpotlightContentPage = () => {
}
clearTimeout(initialTimeout)
}
- }, [isElectron, resizeSpotlightWindow])
+ }, [isElectron, resizeSpotlightWindow, updateWindowHeight])
return (
{
const context = useContext(ThemeContext)
if (!context) {