chore: Remove auto creation of share link (#11950)

* Remove share pre-creation

* Disable toggle while saving

* cleanup unused methods
This commit is contained in:
Tom Moor
2026-04-03 21:09:34 -04:00
committed by GitHub
parent 3421b5a8b5
commit d4f747b43d
5 changed files with 41 additions and 29 deletions
@@ -20,6 +20,7 @@ import Text from "~/components/Text";
import Tooltip from "~/components/Tooltip";
import env from "~/env";
import usePolicy from "~/hooks/usePolicy";
import useStores from "~/hooks/useStores";
import { ListItem } from "../components/ListItem";
import { DomainPrefix, ShareLinkInput, StyledInfoIcon } from "../components";
@@ -35,13 +36,15 @@ function InnerPublicAccess(
ref: React.RefObject<HTMLDivElement>
) {
const { t } = useTranslation();
const { shares } = useStores();
const theme = useTheme();
const [validationError, setValidationError] = React.useState("");
const [urlId, setUrlId] = React.useState(share?.urlId);
const inputRef = React.useRef<HTMLInputElement>(null);
const can = usePolicy(share);
const collectionAbilities = usePolicy(collection);
const canPublish = can.update && collectionAbilities.share;
const canPublish = share ? can.update : collectionAbilities.share;
const [creating, setCreating] = React.useState(false);
React.useEffect(() => {
setUrlId(share?.urlId);
@@ -102,14 +105,23 @@ function InnerPublicAccess(
const handlePublishedChange = React.useCallback(
async (checked: boolean) => {
try {
await share?.save({
published: checked,
});
if (checked && !share) {
setCreating(true);
await shares.create({
type: "collection",
collectionId: collection.id,
published: true,
});
} else if (share) {
await share.save({ published: checked });
}
} catch (err) {
toast.error(err.message);
} finally {
setCreating(false);
}
},
[share]
[share, shares, collection]
);
const handleUrlChange = React.useMemo(
@@ -172,7 +184,7 @@ function InnerPublicAccess(
aria-label={t("Publish to internet")}
checked={share?.published ?? false}
onChange={handlePublishedChange}
disabled={!canPublish}
disabled={!canPublish || creating}
width={26}
height={14}
/>
@@ -14,6 +14,7 @@ import type Share from "~/models/Share";
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";
@@ -45,13 +46,15 @@ function PublicAccess(
ref: React.RefObject<HTMLDivElement>
) {
const { t } = useTranslation();
const { shares } = useStores();
const theme = useTheme();
const [validationError, setValidationError] = React.useState("");
const [urlId, setUrlId] = React.useState(share?.urlId);
const inputRef = React.useRef<HTMLInputElement>(null);
const can = usePolicy(share);
const documentAbilities = usePolicy(document);
const canPublish = can.update && documentAbilities.share;
const canPublish = share ? can.update : documentAbilities.share;
const [creating, setCreating] = React.useState(false);
React.useEffect(() => {
setUrlId(share?.urlId);
@@ -112,14 +115,23 @@ function PublicAccess(
const handlePublishedChange = React.useCallback(
async (checked: boolean) => {
try {
await share?.save({
published: checked,
});
if (checked && !share) {
setCreating(true);
await shares.create({
type: "document",
documentId: document.id,
published: true,
});
} else if (share) {
await share.save({ published: checked });
}
} catch (err) {
toast.error(err.message);
} finally {
setCreating(false);
}
},
[share]
[share, shares, document]
);
const handleUrlChange = React.useMemo(
@@ -215,7 +227,7 @@ function PublicAccess(
aria-label={t("Publish to internet")}
checked={share?.published ?? false}
onChange={handlePublishedChange}
disabled={!canPublish}
disabled={!canPublish || creating}
width={26}
height={14}
/>
+5 -3
View File
@@ -16,7 +16,8 @@ type Params =
* @returns preload function, loading state, and reset function.
*/
export default function useShareDataLoader(params: Params) {
const { userMemberships, groupMemberships, memberships } = useStores();
const { shares, userMemberships, groupMemberships, memberships } =
useStores();
const [loading, setLoading] = useState(false);
const requestedRef = useRef(false);
const requestCountRef = useRef(0);
@@ -42,7 +43,7 @@ export default function useShareDataLoader(params: Params) {
if (params.document) {
const doc = params.document;
promises.push(
doc.share(),
shares.fetchOne({ documentId: doc.id }),
userMemberships.fetchDocumentMemberships({
id: doc.id,
limit: Pagination.defaultLimit,
@@ -52,7 +53,7 @@ export default function useShareDataLoader(params: Params) {
} else {
const col = params.collection;
promises.push(
col.share(),
shares.fetchOne({ collectionId: col.id }),
memberships.fetchAll({ id: col.id }),
groupMemberships.fetchAll({ collectionId: col.id })
);
@@ -66,6 +67,7 @@ export default function useShareDataLoader(params: Params) {
}, [
params.document,
params.collection,
shares,
userMemberships,
groupMemberships,
memberships,
-7
View File
@@ -318,13 +318,6 @@ export default class Collection extends ParanoidModel {
this.index = index;
}
@action
share = async () =>
this.store.rootStore.shares.create({
type: "collection",
collectionId: this.id,
});
getChildrenForDocument(documentId: string) {
let result: NavigationNode[] = [];
-7
View File
@@ -460,13 +460,6 @@ export default class Document extends ArchivableModel implements Searchable {
}
}
@action
share = async () =>
this.store.rootStore.shares.create({
type: "document",
documentId: this.id,
});
archive = () => this.store.archive(this);
restore = (options?: { revisionId?: string; collectionId?: string }) =>