|
@@ -1,6 +1,7 @@
|
|
|
-import React, { FC } from 'react';
|
|
|
|
|
-import { IPageInfoForEntity, IPageWithMeta, isIPageInfoForListing } from '~/interfaces/page';
|
|
|
|
|
|
|
+import React, { FC, useCallback, useState } from 'react';
|
|
|
|
|
+import { IPageWithMeta, isIPageInfoForListing } from '~/interfaces/page';
|
|
|
import { IPageSearchMeta } from '~/interfaces/search';
|
|
import { IPageSearchMeta } from '~/interfaces/search';
|
|
|
|
|
+import { useIsGuestUser } from '~/stores/context';
|
|
|
import { useSWRxPageInfoForList } from '~/stores/page';
|
|
import { useSWRxPageInfoForList } from '~/stores/page';
|
|
|
|
|
|
|
|
import { PageListItemL } from '../PageList/PageListItemL';
|
|
import { PageListItemL } from '../PageList/PageListItemL';
|
|
@@ -8,31 +9,44 @@ import PaginationWrapper from '../PaginationWrapper';
|
|
|
|
|
|
|
|
|
|
|
|
|
type Props = {
|
|
type Props = {
|
|
|
- pages: IPageWithMeta<IPageInfoForEntity & IPageSearchMeta>[],
|
|
|
|
|
- selectedPagesIdList: Set<string>
|
|
|
|
|
- isEnableActions: boolean,
|
|
|
|
|
|
|
+ pages: IPageWithMeta<IPageSearchMeta>[],
|
|
|
|
|
+ isCheckedAllItems?: boolean,
|
|
|
searchResultCount?: number,
|
|
searchResultCount?: number,
|
|
|
activePage?: number,
|
|
activePage?: number,
|
|
|
pagingLimit?: number,
|
|
pagingLimit?: number,
|
|
|
- focusedSearchResultData?: IPageWithMeta<IPageSearchMeta>,
|
|
|
|
|
onPagingNumberChanged?: (activePage: number) => void,
|
|
onPagingNumberChanged?: (activePage: number) => void,
|
|
|
- onClickItem?: (pageId: string) => void,
|
|
|
|
|
|
|
+ onPageSelected?: (page?: IPageWithMeta<IPageSearchMeta>) => void,
|
|
|
onClickCheckbox?: (pageId: string) => void,
|
|
onClickCheckbox?: (pageId: string) => void,
|
|
|
- onClickInvoked?: (pageId: string) => void,
|
|
|
|
|
- onClickDeleteButton?: (pageId: string) => void,
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const SearchResultList: FC<Props> = (props:Props) => {
|
|
const SearchResultList: FC<Props> = (props:Props) => {
|
|
|
const {
|
|
const {
|
|
|
- pages, focusedSearchResultData, selectedPagesIdList, isEnableActions,
|
|
|
|
|
|
|
+ pages, isCheckedAllItems,
|
|
|
|
|
+ onPageSelected,
|
|
|
} = props;
|
|
} = props;
|
|
|
|
|
|
|
|
|
|
+ const [selectedPageId, setSelectedPageId] = useState<string>();
|
|
|
|
|
+
|
|
|
const pageIdsWithNoSnippet = pages
|
|
const pageIdsWithNoSnippet = pages
|
|
|
.filter(page => (page.pageMeta?.elasticSearchResult?.snippet.length ?? 0) === 0)
|
|
.filter(page => (page.pageMeta?.elasticSearchResult?.snippet.length ?? 0) === 0)
|
|
|
.map(page => page.pageData._id);
|
|
.map(page => page.pageData._id);
|
|
|
|
|
|
|
|
|
|
+ const { data: isGuestUser } = useIsGuestUser();
|
|
|
const { data: idToPageInfo } = useSWRxPageInfoForList(pageIdsWithNoSnippet);
|
|
const { data: idToPageInfo } = useSWRxPageInfoForList(pageIdsWithNoSnippet);
|
|
|
|
|
|
|
|
|
|
+ const clickItemHandler = useCallback((pageId: string) => {
|
|
|
|
|
+ setSelectedPageId(pageId);
|
|
|
|
|
+
|
|
|
|
|
+ if (onPageSelected != null) {
|
|
|
|
|
+ const selectedPage = pages.find(page => page.pageData._id === pageId);
|
|
|
|
|
+ onPageSelected(selectedPage);
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [onPageSelected, pages]);
|
|
|
|
|
+
|
|
|
|
|
+ const clickDeleteButtonHandler = useCallback((pageId: string) => {
|
|
|
|
|
+ // TODO implement
|
|
|
|
|
+ }, []);
|
|
|
|
|
+
|
|
|
let injectedPage;
|
|
let injectedPage;
|
|
|
// inject data to list
|
|
// inject data to list
|
|
|
if (idToPageInfo != null) {
|
|
if (idToPageInfo != null) {
|
|
@@ -54,22 +68,19 @@ const SearchResultList: FC<Props> = (props:Props) => {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const focusedPageId = (focusedSearchResultData != null && focusedSearchResultData.pageData != null) ? focusedSearchResultData.pageData._id : '';
|
|
|
|
|
return (
|
|
return (
|
|
|
<ul className="page-list-ul list-group list-group-flush">
|
|
<ul className="page-list-ul list-group list-group-flush">
|
|
|
{ (injectedPage ?? pages).map((page) => {
|
|
{ (injectedPage ?? pages).map((page) => {
|
|
|
- const isChecked = selectedPagesIdList.has(page.pageData._id);
|
|
|
|
|
-
|
|
|
|
|
return (
|
|
return (
|
|
|
<PageListItemL
|
|
<PageListItemL
|
|
|
key={page.pageData._id}
|
|
key={page.pageData._id}
|
|
|
page={page}
|
|
page={page}
|
|
|
- isEnableActions={isEnableActions}
|
|
|
|
|
- onClickItem={props.onClickItem}
|
|
|
|
|
|
|
+ isCheckedAllItems={isCheckedAllItems}
|
|
|
|
|
+ isEnableActions={isGuestUser}
|
|
|
|
|
+ isSelected={page.pageData._id === selectedPageId}
|
|
|
|
|
+ onClickItem={clickItemHandler}
|
|
|
onClickCheckbox={props.onClickCheckbox}
|
|
onClickCheckbox={props.onClickCheckbox}
|
|
|
- isChecked={isChecked}
|
|
|
|
|
- isSelected={page.pageData._id === focusedPageId || false}
|
|
|
|
|
- onClickDeleteButton={props.onClickDeleteButton}
|
|
|
|
|
|
|
+ onClickDeleteButton={clickDeleteButtonHandler}
|
|
|
/>
|
|
/>
|
|
|
);
|
|
);
|
|
|
})}
|
|
})}
|