Skip to content

Commit

Permalink
fix(article): exclude current editing article on collection search
Browse files Browse the repository at this point in the history
refs:
- 2024-05-dev-1#RB-011
  • Loading branch information
robertu7 committed May 7, 2024
1 parent a0fdde4 commit 1772a93
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/components/Editor/BottomBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const BottomBar: React.FC<BottomBarProps> = ({
collection,
editCollection,
collectionSaving,
nodeExclude,

tags,
editTags,
Expand Down Expand Up @@ -210,6 +211,7 @@ const BottomBar: React.FC<BottomBarProps> = ({
}
searchType="Article"
searchExclude={SearchExclude.Blocked}
nodeExclude={nodeExclude}
onSave={(nodes: SearchSelectNode[]) =>
editCollection(nodes as ArticleDigestDropdownArticleFragment[])
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/Editor/Sidebar/Collection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const SidebarCollection = ({
collection,
editCollection,
collectionSaving,
nodeExclude,
disabled,
}: SidebarCollectionProps) => {
return (
Expand All @@ -38,6 +39,7 @@ const SidebarCollection = ({
}
searchType="Article"
searchExclude={SearchExclude.Blocked}
nodeExclude={nodeExclude}
onSave={(nodes: SearchSelectNode[]) =>
editCollection(nodes as ArticleDigestDropdownArticleFragment[])
}
Expand Down
1 change: 1 addition & 0 deletions src/components/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type SetCollectionProps = {
articles: ArticleDigestDropdownArticleFragment[]
) => Promise<any>
collectionSaving?: boolean
nodeExclude?: string
}

export type SetTagsProps = {
Expand Down
3 changes: 3 additions & 0 deletions src/components/Forms/EditorSearchSelectForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type EditorSearchSelectFormProps = {
searchType: SearchType
searchFilter?: SearchFilter
searchExclude?: SearchExclude
nodeExclude?: string

draggable?: boolean

Expand All @@ -80,6 +81,7 @@ const EditorSearchSelectForm = ({
searchType,
searchFilter,
searchExclude,
nodeExclude,

draggable,

Expand Down Expand Up @@ -187,6 +189,7 @@ const EditorSearchSelectForm = ({
searchType={searchType}
searchFilter={searchFilter}
searchExclude={searchExclude}
nodeExclude={nodeExclude}
stagingNodes={stagingNodes}
toStagingArea={toStagingArea}
toSearchingArea={toSearchingArea}
Expand Down
30 changes: 19 additions & 11 deletions src/components/SearchSelect/SearchingArea/EditorSearchingArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type SearchingAreaProps = {
searchType: SearchType
searchFilter?: SearchFilter
searchExclude?: SearchExclude
nodeExclude?: string
stagingNodes: StagingNode[]

inSearchingArea: boolean
Expand All @@ -78,6 +79,7 @@ const EditorSearchingArea: React.FC<SearchingAreaProps> = ({
searchType,
searchFilter,
searchExclude,
nodeExclude,
stagingNodes,

inSearchingArea,
Expand Down Expand Up @@ -164,13 +166,18 @@ const EditorSearchingArea: React.FC<SearchingAreaProps> = ({
})
}

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}
Expand Down Expand Up @@ -229,16 +236,16 @@ const EditorSearchingArea: React.FC<SearchingAreaProps> = ({
}

// use cache or fetch
if (listNode.length > 0) {
setSearchingNodes(listNode)
if (listNodes.length > 0) {
setSearchingNodes(listNodes)
} else {
loadList()
}
}, [isListMode])

useEffect(() => {
setSearching(listLoading)
setSearchingNodes(listNode)
setSearchingNodes(listNodes)
}, [listLoading, listNodeIds])

// article url
Expand All @@ -247,8 +254,9 @@ const EditorSearchingArea: React.FC<SearchingAreaProps> = ({
}, [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 &&
Expand Down Expand Up @@ -315,9 +323,9 @@ const EditorSearchingArea: React.FC<SearchingAreaProps> = ({
)}

{/* List */}
{isListMode && !searching && !haslistNode && <EmptySearch />}
{isListMode && !searching && !hasListNode && <EmptySearch />}

{isListMode && !searching && haslistNode && (
{isListMode && !searching && hasListNode && (
<InfiniteScroll
hasNextPage={!!listPageInfo?.hasNextPage}
loadMore={loadMoreList}
Expand Down
1 change: 1 addition & 0 deletions src/views/ArticleDetail/Edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ const BaseEdit = ({ article }: { article: Article }) => {
collectionSaving: false,
editCollection: async (c: ArticleDigestDropdownArticleFragment[]) =>
setCollection(c),
nodeExclude: article.id,
}

const setCommentProps: SetResponseProps = {
Expand Down

0 comments on commit 1772a93

Please sign in to comment.