Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Entity type editor – persist changes, and related updates (#1194)
- Loading branch information
Showing
11 changed files
with
530 additions
and
350 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,18 +1,31 @@ | ||
import init from "@blockprotocol/type-system-web"; | ||
import { useEffect, useState } from "react"; | ||
import { useCallback, useEffect, useRef, useState } from "react"; | ||
|
||
export const useInitTypeSystem = () => { | ||
export const useAdvancedInitTypeSystem = () => { | ||
const [loadingTypeSystem, setLoadingTypeSystem] = useState(true); | ||
const loadingPromise = useRef<Promise<void> | null>(null); | ||
|
||
const loadTypeSystem = useCallback(() => { | ||
if (loadingPromise.current) { | ||
return loadingPromise.current; | ||
} | ||
|
||
loadingPromise.current = (async () => { | ||
await init().then(() => { | ||
setLoadingTypeSystem(false); | ||
}); | ||
})(); | ||
|
||
return loadingPromise.current; | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (loadingTypeSystem) { | ||
void (async () => { | ||
await init().then(() => { | ||
setLoadingTypeSystem(false); | ||
}); | ||
})(); | ||
void loadTypeSystem(); | ||
} | ||
}, [loadingTypeSystem, setLoadingTypeSystem]); | ||
}, [loadTypeSystem, loadingTypeSystem]); | ||
|
||
return loadingTypeSystem; | ||
return [loadingTypeSystem, loadTypeSystem] as const; | ||
}; | ||
|
||
export const useInitTypeSystem = () => useAdvancedInitTypeSystem()[0]; |
298 changes: 142 additions & 156 deletions
298
packages/hash/frontend/src/pages/[account-slug]/types/entity-type/[entity-type-id].page.tsx
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
Oops, something went wrong.