diff --git a/src/components/Editor/BottomBar/index.tsx b/src/components/Editor/BottomBar/index.tsx index 2cab1ed875..8caf0dd432 100644 --- a/src/components/Editor/BottomBar/index.tsx +++ b/src/components/Editor/BottomBar/index.tsx @@ -58,6 +58,7 @@ const BottomBar: React.FC = ({ collection, editCollection, collectionSaving, + nodeExclude, tags, editTags, @@ -210,6 +211,7 @@ const BottomBar: React.FC = ({ } searchType="Article" searchExclude={SearchExclude.Blocked} + nodeExclude={nodeExclude} onSave={(nodes: SearchSelectNode[]) => editCollection(nodes as ArticleDigestDropdownArticleFragment[]) } diff --git a/src/components/Editor/Sidebar/Collection/index.tsx b/src/components/Editor/Sidebar/Collection/index.tsx index 02321f6f8c..6d54fa1bbf 100644 --- a/src/components/Editor/Sidebar/Collection/index.tsx +++ b/src/components/Editor/Sidebar/Collection/index.tsx @@ -25,6 +25,7 @@ const SidebarCollection = ({ collection, editCollection, collectionSaving, + nodeExclude, disabled, }: SidebarCollectionProps) => { return ( @@ -38,6 +39,7 @@ const SidebarCollection = ({ } searchType="Article" searchExclude={SearchExclude.Blocked} + nodeExclude={nodeExclude} onSave={(nodes: SearchSelectNode[]) => editCollection(nodes as ArticleDigestDropdownArticleFragment[]) } diff --git a/src/components/Editor/index.tsx b/src/components/Editor/index.tsx index 5bfcaeb694..544aaca3aa 100644 --- a/src/components/Editor/index.tsx +++ b/src/components/Editor/index.tsx @@ -13,6 +13,7 @@ export type SetCollectionProps = { articles: ArticleDigestDropdownArticleFragment[] ) => Promise collectionSaving?: boolean + nodeExclude?: string } export type SetTagsProps = { diff --git a/src/components/Forms/EditorSearchSelectForm/index.tsx b/src/components/Forms/EditorSearchSelectForm/index.tsx index 4749be617c..8dabf2086d 100644 --- a/src/components/Forms/EditorSearchSelectForm/index.tsx +++ b/src/components/Forms/EditorSearchSelectForm/index.tsx @@ -55,6 +55,7 @@ export type EditorSearchSelectFormProps = { searchType: SearchType searchFilter?: SearchFilter searchExclude?: SearchExclude + nodeExclude?: string draggable?: boolean @@ -80,6 +81,7 @@ const EditorSearchSelectForm = ({ searchType, searchFilter, searchExclude, + nodeExclude, draggable, @@ -187,6 +189,7 @@ const EditorSearchSelectForm = ({ searchType={searchType} searchFilter={searchFilter} searchExclude={searchExclude} + nodeExclude={nodeExclude} stagingNodes={stagingNodes} toStagingArea={toStagingArea} toSearchingArea={toSearchingArea} diff --git a/src/components/SearchSelect/SearchingArea/EditorSearchingArea.tsx b/src/components/SearchSelect/SearchingArea/EditorSearchingArea.tsx index 86db8ca63f..114271756b 100644 --- a/src/components/SearchSelect/SearchingArea/EditorSearchingArea.tsx +++ b/src/components/SearchSelect/SearchingArea/EditorSearchingArea.tsx @@ -60,6 +60,7 @@ type SearchingAreaProps = { searchType: SearchType searchFilter?: SearchFilter searchExclude?: SearchExclude + nodeExclude?: string stagingNodes: StagingNode[] inSearchingArea: boolean @@ -78,6 +79,7 @@ const EditorSearchingArea: React.FC = ({ searchType, searchFilter, searchExclude, + nodeExclude, stagingNodes, inSearchingArea, @@ -164,13 +166,18 @@ const EditorSearchingArea: React.FC = ({ }) } - const searchNodes = searchEdges?.map(({ node }) => node) || [] + const searchNodes = + searchEdges + ?.map(({ node }) => node) + .filter((node) => node.id !== nodeExclude) || [] const searchNodeIds = searchNodes.map((n) => n.id).join(',') - const listNode = + const listNodes = listEdges ?.map(({ node }) => node) - .filter((node) => node.articleState === 'active') || [] - const listNodeIds = listNode.map((n) => n.id).join(',') + .filter( + (node) => node.articleState === 'active' && node.id !== nodeExclude + ) || [] + const listNodeIds = listNodes.map((n) => n.id).join(',') const search = (key: string) => { // Used to match links of the format like👇 // https://matters.town/a/{shortHash} @@ -229,8 +236,8 @@ const EditorSearchingArea: React.FC = ({ } // use cache or fetch - if (listNode.length > 0) { - setSearchingNodes(listNode) + if (listNodes.length > 0) { + setSearchingNodes(listNodes) } else { loadList() } @@ -238,7 +245,7 @@ const EditorSearchingArea: React.FC = ({ useEffect(() => { setSearching(listLoading) - setSearchingNodes(listNode) + setSearchingNodes(listNodes) }, [listLoading, listNodeIds]) // article url @@ -247,8 +254,9 @@ const EditorSearchingArea: React.FC = ({ }, [articleUrlLoding]) const hasNodes = searchNodes.length > 0 - const haslistNode = listNode.length > 0 - const hasArticle = !!articleUrlData?.article + const hasListNode = listNodes.length > 0 + const hasArticle = + !!articleUrlData?.article && articleUrlData?.article.id !== nodeExclude const canCreateTag = isTag && searchKey && @@ -315,9 +323,9 @@ const EditorSearchingArea: React.FC = ({ )} {/* List */} - {isListMode && !searching && !haslistNode && } + {isListMode && !searching && !hasListNode && } - {isListMode && !searching && haslistNode && ( + {isListMode && !searching && hasListNode && ( { collectionSaving: false, editCollection: async (c: ArticleDigestDropdownArticleFragment[]) => setCollection(c), + nodeExclude: article.id, } const setCommentProps: SetResponseProps = {