generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: tabs hanging when more than 3 are open (#493)
- Loading branch information
1 parent
2983809
commit a5b573a
Showing
12 changed files
with
151 additions
and
223 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Code, ConnectError } from '@connectrpc/connect' | ||
import { useEffect, useState } from 'react' | ||
import { useClient } from '../hooks/use-client' | ||
import { useVisibility } from '../hooks/use-visibility.ts' | ||
import { ControllerService } from '../protos/xyz/block/ftl/v1/ftl_connect.ts' | ||
import { DeploymentChangeType, PullSchemaResponse } from '../protos/xyz/block/ftl/v1/ftl_pb' | ||
|
||
export const useSchema = () => { | ||
const client = useClient(ControllerService) | ||
const [schema, setSchema] = useState<PullSchemaResponse[]>([]) | ||
const isVisible = useVisibility() | ||
|
||
useEffect(() => { | ||
const abortController = new AbortController() | ||
|
||
const fetchSchema = async () => { | ||
try { | ||
if (!isVisible) { | ||
abortController.abort() | ||
return | ||
} | ||
|
||
const schemaMap = new Map<string, PullSchemaResponse>() | ||
for await (const response of client.pullSchema( | ||
{}, | ||
{ | ||
signal: abortController.signal, | ||
}, | ||
)) { | ||
const moduleName = response.moduleName ?? '' | ||
switch (response.changeType) { | ||
case DeploymentChangeType.DEPLOYMENT_ADDED: | ||
schemaMap.set(moduleName, response) | ||
break | ||
case DeploymentChangeType.DEPLOYMENT_CHANGED: | ||
schemaMap.set(moduleName, response) | ||
break | ||
case DeploymentChangeType.DEPLOYMENT_REMOVED: | ||
schemaMap.delete(moduleName) | ||
} | ||
|
||
if (!response.more) { | ||
setSchema( | ||
Array.from(schemaMap.values()).sort((a, b) => a.schema?.name?.localeCompare(b.schema?.name ?? '') ?? 0), | ||
) | ||
} | ||
} | ||
} catch (error) { | ||
if (error instanceof ConnectError) { | ||
if (error.code !== Code.Canceled) { | ||
console.error('Console service - streamEvents - Connect error:', error) | ||
} | ||
} else { | ||
console.error('Console service - streamEvents:', error) | ||
} | ||
} | ||
} | ||
|
||
fetchSchema() | ||
return () => { | ||
abortController.abort() | ||
} | ||
}, [client, isVisible]) | ||
|
||
return schema | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useEffect, useState } from 'react' | ||
|
||
export const useVisibility = () => { | ||
const [isVisible, setIsVisible] = useState(document.visibilityState === 'visible') | ||
|
||
useEffect(() => { | ||
const handleVisibilityChange = () => { | ||
setIsVisible(document.visibilityState === 'visible') | ||
} | ||
|
||
document.addEventListener('visibilitychange', handleVisibilityChange) | ||
|
||
return () => { | ||
document.removeEventListener('visibilitychange', handleVisibilityChange) | ||
} | ||
}, []) | ||
|
||
return isVisible | ||
} |
Oops, something went wrong.