From 91396148ae9a4fd49b4b659d3583abaf855a07cf Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 8 Oct 2024 19:20:40 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20=E2=80=9CShare=20to=20web=E2=80=9D=20con?= =?UTF-8?q?trol=20is=20unresponsive=20when=20opening=20via=20=E2=80=9CPerm?= =?UTF-8?q?issions=E2=80=9D=20menu=20item?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/actions/definitions/documents.tsx | 4 ---- app/components/Sharing/Document/PublicAccess.tsx | 10 ++-------- app/components/Sharing/Document/SharePopover.tsx | 16 ++++------------ app/scenes/Document/components/ShareButton.tsx | 2 -- 4 files changed, 6 insertions(+), 26 deletions(-) diff --git a/app/actions/definitions/documents.tsx b/app/actions/definitions/documents.tsx index 3d9e18c89a..99d289b6af 100644 --- a/app/actions/definitions/documents.tsx +++ b/app/actions/definitions/documents.tsx @@ -358,8 +358,6 @@ export const shareDocument = createAction({ } const document = stores.documents.get(activeDocumentId); - const share = stores.shares.getByDocumentId(activeDocumentId); - const sharedParent = stores.shares.getByDocumentParents(activeDocumentId); if (!document) { return; } @@ -370,8 +368,6 @@ export const shareDocument = createAction({ content: ( diff --git a/app/components/Sharing/Document/PublicAccess.tsx b/app/components/Sharing/Document/PublicAccess.tsx index 4855cb2b5b..38353e7099 100644 --- a/app/components/Sharing/Document/PublicAccess.tsx +++ b/app/components/Sharing/Document/PublicAccess.tsx @@ -1,4 +1,3 @@ -import invariant from "invariant"; import debounce from "lodash/debounce"; import isEmpty from "lodash/isEmpty"; import { observer } from "mobx-react"; @@ -17,7 +16,6 @@ import Input, { NativeInput } from "~/components/Input"; import Switch from "~/components/Switch"; import env from "~/env"; import usePolicy from "~/hooks/usePolicy"; -import useStores from "~/hooks/useStores"; import { AvatarSize } from "../../Avatar"; import CopyToClipboard from "../../CopyToClipboard"; import NudeButton from "../../NudeButton"; @@ -39,7 +37,6 @@ type Props = { }; function PublicAccess({ document, share, sharedParent }: Props) { - const { shares } = useStores(); const { t } = useTranslation(); const theme = useTheme(); const [validationError, setValidationError] = React.useState(""); @@ -55,18 +52,15 @@ function PublicAccess({ document, share, sharedParent }: Props) { const handlePublishedChange = React.useCallback( async (event) => { - const share = shares.getByDocumentId(document.id); - invariant(share, "Share must exist"); - try { - await share.save({ + await share?.save({ published: event.currentTarget.checked, }); } catch (err) { toast.error(err.message); } }, - [document.id, shares] + [share] ); const handleUrlChange = React.useMemo( diff --git a/app/components/Sharing/Document/SharePopover.tsx b/app/components/Sharing/Document/SharePopover.tsx index 6ab0f6262e..007633977c 100644 --- a/app/components/Sharing/Document/SharePopover.tsx +++ b/app/components/Sharing/Document/SharePopover.tsx @@ -8,7 +8,6 @@ import { toast } from "sonner"; import { DocumentPermission } from "@shared/types"; import Document from "~/models/Document"; import Group from "~/models/Group"; -import Share from "~/models/Share"; import User from "~/models/User"; import { Avatar, GroupAvatar, AvatarSize } from "~/components/Avatar"; import NudeButton from "~/components/NudeButton"; @@ -32,26 +31,19 @@ import { AccessControlList } from "./AccessControlList"; type Props = { /** The document to share. */ document: Document; - /** The existing share model, if any. */ - share: Share | null | undefined; - /** The existing share parent model, if any. */ - sharedParent: Share | null | undefined; /** Callback fired when the popover requests to be closed. */ onRequestClose: () => void; /** Whether the popover is visible. */ visible: boolean; }; -function SharePopover({ - document, - share, - sharedParent, - onRequestClose, - visible, -}: Props) { +function SharePopover({ document, onRequestClose, visible }: Props) { const team = useCurrentTeam(); const { t } = useTranslation(); const can = usePolicy(document); + const { shares } = useStores(); + const share = shares.getByDocumentId(document.id); + const sharedParent = shares.getByDocumentParents(document.id); const [hasRendered, setHasRendered] = React.useState(visible); const { users, userMemberships, groups, groupMemberships } = useStores(); const [query, setQuery] = React.useState(""); diff --git a/app/scenes/Document/components/ShareButton.tsx b/app/scenes/Document/components/ShareButton.tsx index 4df7ba7515..290a9c2cb4 100644 --- a/app/scenes/Document/components/ShareButton.tsx +++ b/app/scenes/Document/components/ShareButton.tsx @@ -53,8 +53,6 @@ function ShareButton({ document }: Props) { >