fix: Unneccessary requests made on share links

This commit is contained in:
Tom Moor
2022-08-27 20:45:07 +02:00
parent 3cc3cd8cf8
commit 6fc1cbc0ce
3 changed files with 12 additions and 5 deletions

View File

@@ -59,7 +59,7 @@ function Editor(props: Props, ref: React.RefObject<SharedEditor> | null) {
const { documents } = useStores();
const { showToast } = useToasts();
const dictionary = useDictionary();
const embeds = useEmbeds();
const embeds = useEmbeds(!shareId);
const [
activeLinkEvent,
setActiveLinkEvent,

View File

@@ -6,7 +6,14 @@ import Integration from "~/models/Integration";
import Logger from "~/utils/Logger";
import useStores from "./useStores";
export default function useEmbedIntegrations() {
/**
* Hook to get all embed configuration for the current team
*
* @param loadIfMissing Should we load integration settings if they are not
* locally available
* @returns A list of embed descriptors
*/
export default function useEmbeds(loadIfMissing = false) {
const { integrations } = useStores();
React.useEffect(() => {
@@ -21,8 +28,8 @@ export default function useEmbedIntegrations() {
}
}
!integrations.isLoaded && fetchEmbedIntegrations();
}, [integrations]);
!integrations.isLoaded && loadIfMissing && fetchEmbedIntegrations();
}, [integrations, loadIfMissing]);
return React.useMemo(
() =>

View File

@@ -100,7 +100,7 @@ function DocumentHeader({
}, [onSave]);
const { isDeleted, isTemplate } = document;
const can = usePolicy(document);
const can = usePolicy(document?.id);
const canToggleEmbeds = team?.documentEmbeds;
const canEdit = can.update && !isEditing;
const toc = (