From e3e68469794881014e85a4a047a46ca75306eb73 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 3 May 2025 22:05:04 -0400 Subject: [PATCH] fix: Cannot create document through @mention on collection overview --- .../Collection/components/Overview.tsx} | 30 ++++++++++++++++--- app/scenes/Collection/index.tsx | 4 +-- shared/i18n/locales/en_US/translation.json | 4 +-- 3 files changed, 30 insertions(+), 8 deletions(-) rename app/{components/CollectionDescription.tsx => scenes/Collection/components/Overview.tsx} (76%) diff --git a/app/components/CollectionDescription.tsx b/app/scenes/Collection/components/Overview.tsx similarity index 76% rename from app/components/CollectionDescription.tsx rename to app/scenes/Collection/components/Overview.tsx index 4b16a3b4fe..80461e9fc6 100644 --- a/app/components/CollectionDescription.tsx +++ b/app/scenes/Collection/components/Overview.tsx @@ -6,15 +6,18 @@ import { toast } from "sonner"; import styled from "styled-components"; import { richExtensions } from "@shared/editor/nodes"; import { s } from "@shared/styles"; +import { ProsemirrorHelper } from "@shared/utils/ProsemirrorHelper"; import { CollectionValidation } from "@shared/validations"; import Collection from "~/models/Collection"; +import Document from "~/models/Document"; import Editor from "~/components/Editor"; import LoadingIndicator from "~/components/LoadingIndicator"; +import Text from "~/components/Text"; import { withUIExtensions } from "~/editor/extensions"; import useCurrentUser from "~/hooks/useCurrentUser"; import usePolicy from "~/hooks/usePolicy"; import useStores from "~/hooks/useStores"; -import Text from "./Text"; +import { Properties } from "~/types"; const extensions = withUIExtensions(richExtensions); @@ -22,8 +25,8 @@ type Props = { collection: Collection; }; -function CollectionDescription({ collection }: Props) { - const { collections } = useStores(); +function Overview({ collection }: Props) { + const { documents, collections } = useStores(); const { t } = useTranslation(); const user = useCurrentUser({ rejectOnEmpty: true }); const can = usePolicy(collection); @@ -54,6 +57,24 @@ function CollectionDescription({ collection }: Props) { [childOffsetHeight] ); + const onCreateLink = React.useCallback( + async (params: Properties) => { + const newDocument = await documents.create( + { + collectionId: collection.id, + data: ProsemirrorHelper.getEmptyDocument(), + ...params, + }, + { + publish: true, + } + ); + + return newDocument.url; + }, + [collection, documents] + ); + return ( <> {collections.isSaving && } @@ -65,6 +86,7 @@ function CollectionDescription({ collection }: Props) { placeholder={`${t("Add a description")}…`} extensions={extensions} maxLength={CollectionValidation.maxDescriptionLength} + onCreateLink={onCreateLink} canUpdate={can.update} readOnly={!can.update} userId={user.id} @@ -83,4 +105,4 @@ const Placeholder = styled(Text)` min-height: 27px; `; -export default observer(CollectionDescription); +export default observer(Overview); diff --git a/app/scenes/Collection/index.tsx b/app/scenes/Collection/index.tsx index b3c5597714..8ee317bd2a 100644 --- a/app/scenes/Collection/index.tsx +++ b/app/scenes/Collection/index.tsx @@ -20,7 +20,6 @@ import Collection from "~/models/Collection"; import { Action } from "~/components/Actions"; import CenteredContent from "~/components/CenteredContent"; import { CollectionBreadcrumb } from "~/components/CollectionBreadcrumb"; -import CollectionDescription from "~/components/CollectionDescription"; import Heading from "~/components/Heading"; import CollectionIcon from "~/components/Icons/CollectionIcon"; import InputSearchPage from "~/components/InputSearchPage"; @@ -46,6 +45,7 @@ import DropToImport from "./components/DropToImport"; import Empty from "./components/Empty"; import MembershipPreview from "./components/MembershipPreview"; import Notices from "./components/Notices"; +import Overview from "./components/Overview"; import ShareButton from "./components/ShareButton"; const IconPicker = React.lazy(() => import("~/components/IconPicker")); @@ -259,7 +259,7 @@ const CollectionScene = observer(function _CollectionScene() { path={collectionPath(collection.path, CollectionPath.Overview)} > {hasOverview ? ( - + ) : ( {{collectionName}} collection is permanent and cannot be restored, however all published documents within will be moved to the trash.": "Are you sure about that? Deleting the {{collectionName}} collection is permanent and cannot be restored, however all published documents within will be moved to the trash.", "Also, {{collectionName}} is being used as the start view – deleting it will reset the start view to the Home page.": "Also, {{collectionName}} is being used as the start view – deleting it will reset the start view to the Home page.", - "Sorry, an error occurred saving the collection": "Sorry, an error occurred saving the collection", - "Add a description": "Add a description", "Type a command or search": "Type a command or search", "Choose a template": "Choose a template", "Are you sure you want to permanently delete this entire comment thread?": "Are you sure you want to permanently delete this entire comment thread?", @@ -618,6 +616,8 @@ "{{ groupsCount }} groups with access": "{{ groupsCount }} group with access", "{{ groupsCount }} groups with access_plural": "{{ groupsCount }} groups with access", "Archived by {{userName}}": "Archived by {{userName}}", + "Sorry, an error occurred saving the collection": "Sorry, an error occurred saving the collection", + "Add a description": "Add a description", "Share": "Share", "Overview": "Overview", "Recently updated": "Recently updated",