Skip to content

Commit

Permalink
save state between react and listener code
Browse files Browse the repository at this point in the history
  • Loading branch information
insmac committed Oct 23, 2024
1 parent 9a326ec commit ac7f5a3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/web-console/src/scenes/Schema/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ const Schema = ({
const [selectOpen, setSelectOpen] = useState(false)
const [selectedTables, setSelectedTables] = useState<string[]>([])
const [focusListenerActive, setFocusListenerActive] = useState(false)
const listenerActiveRef = useRef(false)

const handleChange = (name: string) => {
setOpened(name === opened ? undefined : name)
Expand Down Expand Up @@ -287,8 +288,10 @@ const Schema = ({
}, [])

const focusListener = () => {
void fetchTables()
void fetchColumns()
if (listenerActiveRef.current) {
void fetchTables()
void fetchColumns()
}
}

useEffect(() => {
Expand All @@ -300,11 +303,13 @@ const Schema = ({

window.addEventListener("focus", focusListener)
setFocusListenerActive(true)
listenerActiveRef.current = true
} else if (focusListenerActive) {
eventBus.unsubscribe(EventType.MSG_QUERY_SCHEMA)

window.removeEventListener("focus", focusListener)
setFocusListenerActive(false)
listenerActiveRef.current = false
}
}, [autoRefreshTables])

Expand Down

0 comments on commit ac7f5a3

Please sign in to comment.