mirror of
https://github.com/billsonnn/nitro-react.git
synced 2025-01-19 05:46:27 +01:00
Open catalog page by name working
This commit is contained in:
parent
2fc709511c
commit
c19810327d
@ -2,5 +2,7 @@ import { GetNitroInstance } from './GetNitroInstance';
|
||||
|
||||
export function CreateLinkEvent(link: string): void
|
||||
{
|
||||
link = (link.startsWith('event:') ? link.substring(6) : link);
|
||||
|
||||
GetNitroInstance().createLinkEvent(link);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ import { CatalogActions } from './reducers/CatalogReducer';
|
||||
|
||||
export const CatalogMessageHandler: FC<{}> = props =>
|
||||
{
|
||||
const { setIsBusy, pageId, currentType, setRootNode, setCurrentOffers, currentPage, setCurrentOffer, setPurchasableOffer, setFrontPageItems, resetState, showCatalogPage, catalogState, dispatchCatalogState } = useCatalogContext();
|
||||
const { setIsBusy, pageId, currentType, setRootNode, setOffersToNodes, currentPage, setCurrentOffer, setPurchasableOffer, setFrontPageItems, resetState, showCatalogPage, catalogState, dispatchCatalogState } = useCatalogContext();
|
||||
|
||||
const onCatalogPagesListEvent = useCallback((event: CatalogPagesListEvent) =>
|
||||
{
|
||||
@ -54,9 +54,9 @@ export const CatalogMessageHandler: FC<{}> = props =>
|
||||
BatchUpdates(() =>
|
||||
{
|
||||
setRootNode(getCatalogNode(parser.root, 0, null));
|
||||
setCurrentOffers(offers);
|
||||
setOffersToNodes(offers);
|
||||
});
|
||||
}, [ setRootNode, setCurrentOffers ]);
|
||||
}, [ setRootNode, setOffersToNodes ]);
|
||||
|
||||
const onCatalogPageMessageEvent = useCallback((event: CatalogPageMessageEvent) =>
|
||||
{
|
||||
@ -273,8 +273,6 @@ export const CatalogMessageHandler: FC<{}> = props =>
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
console.log(parser);
|
||||
|
||||
dispatchCatalogState({
|
||||
type: CatalogActions.SET_MARKETPLACE_CONFIGURATION,
|
||||
|
@ -42,7 +42,6 @@ export const CatalogView: FC<{}> = props =>
|
||||
const [ currentPage, setCurrentPage ] = useState<ICatalogPage>(null);
|
||||
const [ currentOffer, setCurrentOffer ] = useState<IPurchasableOffer>(null);
|
||||
const [ purchasableOffer, setPurchasableOffer ] = useState<IPurchasableOffer>(null);
|
||||
const [ currentTab, setCurrentTab ] = useState<ICatalogNode>(null);
|
||||
const [ activeNodes, setActiveNodes ] = useState<ICatalogNode[]>([]);
|
||||
const [ searchResult, setSearchResult ] = useState<SearchResult>(null);
|
||||
const [ frontPageItems, setFrontPageItems ] = useState<FrontPageItem[]>([]);
|
||||
@ -60,7 +59,6 @@ export const CatalogView: FC<{}> = props =>
|
||||
setCurrentPage(null);
|
||||
setCurrentOffer(null);
|
||||
setPurchasableOffer(null);
|
||||
setCurrentTab(null);
|
||||
setActiveNodes([]);
|
||||
setSearchResult(null);
|
||||
setFrontPageItems([]);
|
||||
@ -68,6 +66,20 @@ export const CatalogView: FC<{}> = props =>
|
||||
});
|
||||
}, []);
|
||||
|
||||
const getFirstNodeByName = useCallback((name: string, node: ICatalogNode) =>
|
||||
{
|
||||
if((node.pageName === name) && (node !== rootNode)) return node;
|
||||
|
||||
for(const child of node.children)
|
||||
{
|
||||
const found = (getFirstNodeByName(name, child) as ICatalogNode);
|
||||
|
||||
if(found) return found;
|
||||
}
|
||||
|
||||
return null;
|
||||
}, [ rootNode ]);
|
||||
|
||||
const getNodesByOfferId = useCallback((offerId: number, flag: boolean = false) =>
|
||||
{
|
||||
if(!offersToNodes || !offersToNodes.size) return null;
|
||||
@ -194,6 +206,27 @@ export const CatalogView: FC<{}> = props =>
|
||||
if(targetNode.pageId > -1) loadCatalogPage(targetNode.pageId, offerId);
|
||||
}, [ setActiveNodes, loadCatalogPage ]);
|
||||
|
||||
const openPageByName = useCallback((name: string) =>
|
||||
{
|
||||
BatchUpdates(() =>
|
||||
{
|
||||
setSearchResult(null);
|
||||
|
||||
if(!isVisible)
|
||||
{
|
||||
REQUESTED_PAGE.requestByName = name;
|
||||
|
||||
setIsVisible(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
const node = getFirstNodeByName(name, rootNode);
|
||||
|
||||
if(node) activateNode(node);
|
||||
}
|
||||
});
|
||||
}, [ isVisible, rootNode, getFirstNodeByName, activateNode ]);
|
||||
|
||||
const openPageByOfferId = useCallback((offerId: number) =>
|
||||
{
|
||||
BatchUpdates(() =>
|
||||
@ -258,6 +291,12 @@ export const CatalogView: FC<{}> = props =>
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
openPageByName(parts[2]);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -266,7 +305,7 @@ export const CatalogView: FC<{}> = props =>
|
||||
|
||||
return;
|
||||
}
|
||||
}, [ openPageByOfferId ]);
|
||||
}, [ openPageByOfferId, openPageByName ]);
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
@ -335,10 +374,11 @@ export const CatalogView: FC<{}> = props =>
|
||||
REQUESTED_PAGE.resetRequest();
|
||||
return;
|
||||
case RequestedPage.REQUEST_TYPE_NAME:
|
||||
openPageByName(REQUESTED_PAGE.requestByName);
|
||||
REQUESTED_PAGE.resetRequest();
|
||||
return;
|
||||
}
|
||||
}, [ isVisible, rootNode, activeNodes, activateNode, openPageByOfferId ]);
|
||||
}, [ isVisible, rootNode, activeNodes, activateNode, openPageByOfferId, openPageByName ]);
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
@ -348,7 +388,7 @@ export const CatalogView: FC<{}> = props =>
|
||||
}, [ currentPage ]);
|
||||
|
||||
return (
|
||||
<CatalogContextProvider value={ { isVisible, isBusy, setIsBusy, pageId, currentType, setCurrentType, rootNode, setRootNode, currentOffers: offersToNodes, setCurrentOffers: setOffersToNodes, currentPage, setCurrentPage, currentOffer, setCurrentOffer, purchasableOffer, setPurchasableOffer, activeNodes, setActiveNodes, searchResult, setSearchResult, frontPageItems, setFrontPageItems, roomPreviewer, resetState, loadCatalogPage, showCatalogPage, activateNode, catalogState, dispatchCatalogState } }>
|
||||
<CatalogContextProvider value={ { isVisible, isBusy, setIsBusy, pageId, currentType, setCurrentType, rootNode, setRootNode, offersToNodes, setOffersToNodes, currentPage, setCurrentPage, currentOffer, setCurrentOffer, purchasableOffer, setPurchasableOffer, activeNodes, setActiveNodes, searchResult, setSearchResult, frontPageItems, setFrontPageItems, roomPreviewer, resetState, loadCatalogPage, showCatalogPage, activateNode, catalogState, dispatchCatalogState } }>
|
||||
<CatalogMessageHandler />
|
||||
{ isVisible &&
|
||||
<NitroCardView uniqueKey="catalog" className="nitro-catalog">
|
||||
|
@ -17,8 +17,8 @@ export interface ICatalogContext
|
||||
setCurrentType: Dispatch<SetStateAction<string>>;
|
||||
rootNode: ICatalogNode;
|
||||
setRootNode: Dispatch<SetStateAction<ICatalogNode>>;
|
||||
currentOffers: Map<number, ICatalogNode[]>;
|
||||
setCurrentOffers: Dispatch<SetStateAction<Map<number, ICatalogNode[]>>>;
|
||||
offersToNodes: Map<number, ICatalogNode[]>;
|
||||
setOffersToNodes: Dispatch<SetStateAction<Map<number, ICatalogNode[]>>>;
|
||||
currentPage: ICatalogPage;
|
||||
setCurrentPage: Dispatch<SetStateAction<ICatalogPage>>;
|
||||
currentOffer: IPurchasableOffer;
|
||||
@ -50,8 +50,8 @@ const CatalogContext = createContext<ICatalogContext>({
|
||||
setCurrentType: null,
|
||||
rootNode: null,
|
||||
setRootNode: null,
|
||||
currentOffers: null,
|
||||
setCurrentOffers: null,
|
||||
offersToNodes: null,
|
||||
setOffersToNodes: null,
|
||||
currentPage: null,
|
||||
setCurrentPage: null,
|
||||
currentOffer: null,
|
||||
|
@ -2,6 +2,7 @@ import { NitroToolbarAnimateIconEvent, TextureUtils, ToolbarIconEnum } from '@ni
|
||||
import { FC, useCallback, useRef, useState } from 'react';
|
||||
import { GetRoomEngine } from '../../../../api';
|
||||
import { CatalogEvent, CatalogSelectProductEvent } from '../../../../events';
|
||||
import { CatalogWidgetEvent } from '../../../../events/catalog/CatalogWidgetEvent';
|
||||
import { useUiEvent } from '../../../../hooks';
|
||||
import { RoomPreviewerView } from '../../../../views/shared/room-previewer/RoomPreviewerView';
|
||||
import { RoomPreviewerViewProps } from '../../../../views/shared/room-previewer/RoomPreviewerView.types';
|
||||
@ -18,7 +19,7 @@ export const CatalogRoomPreviewerView: FC<RoomPreviewerViewProps> = props =>
|
||||
setOffer(event.offer);
|
||||
}, []);
|
||||
|
||||
useUiEvent(CatalogSelectProductEvent.SELECT_PRODUCT, onCatalogSelectProductEvent)
|
||||
useUiEvent(CatalogWidgetEvent.SELECT_PRODUCT, onCatalogSelectProductEvent)
|
||||
|
||||
const animatePurchase = useCallback(() =>
|
||||
{
|
||||
|
@ -48,3 +48,10 @@
|
||||
width: $marketplace-post-offer-width;
|
||||
height: $marketplace-post-offer-height;
|
||||
}
|
||||
|
||||
.nitro-catalog-layout-bundle-grid {
|
||||
|
||||
.layout-grid-item {
|
||||
background-color: transparent;
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ import { useCatalogContext } from '../../context/CatalogContext';
|
||||
export const CatalogSearchView: FC<{}> = props =>
|
||||
{
|
||||
const [ searchValue, setSearchValue ] = useState('');
|
||||
const { currentType = null, rootNode = null, setActiveNodes = null, currentOffers = null, searchResult = null, setSearchResult = null, setCurrentPage = null } = useCatalogContext();
|
||||
const { currentType = null, rootNode = null, setActiveNodes = null, offersToNodes = null, searchResult = null, setSearchResult = null, setCurrentPage = null } = useCatalogContext();
|
||||
|
||||
const processSearch = useCallback((search: string) =>
|
||||
{
|
||||
@ -54,8 +54,8 @@ export const CatalogSearchView: FC<{}> = props =>
|
||||
else
|
||||
{
|
||||
const foundNodes = [
|
||||
...GetOfferNodes(currentOffers, furniture.purchaseOfferId),
|
||||
...GetOfferNodes(currentOffers, furniture.rentOfferId)
|
||||
...GetOfferNodes(offersToNodes, furniture.purchaseOfferId),
|
||||
...GetOfferNodes(offersToNodes, furniture.rentOfferId)
|
||||
];
|
||||
|
||||
if(foundNodes.length)
|
||||
@ -81,7 +81,7 @@ export const CatalogSearchView: FC<{}> = props =>
|
||||
setSearchResult(new SearchResult(search, offers, nodes.filter(node => (node.isVisible))));
|
||||
setActiveNodes(prevValue => prevValue.slice(0, 1));
|
||||
});
|
||||
}, [ currentOffers, currentType, rootNode, setCurrentPage, setSearchResult, setActiveNodes ]);
|
||||
}, [ offersToNodes, currentType, rootNode, setCurrentPage, setSearchResult, setActiveNodes ]);
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
|
@ -182,7 +182,7 @@ export class NotificationUtilities
|
||||
}
|
||||
else
|
||||
{
|
||||
CreateLinkEvent(url.substring(6));
|
||||
CreateLinkEvent(url);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user