mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-26 23:50:52 +01:00
Add buy one button
This commit is contained in:
parent
241348e5f2
commit
63cf84d872
@ -18,7 +18,7 @@ export const CatalogView: FC<CatalogViewProps> = props =>
|
||||
{
|
||||
const [ isVisible, setIsVisible ] = useState(false);
|
||||
const [ roomPreviewer, setRoomPreviewer ] = useState<RoomPreviewer>(null);
|
||||
const [ pendingPageLookup, setPendingPageLookup ] = useState<string>(null);
|
||||
const [ pendingPageLookup, setPendingPageLookup ] = useState<{ value: string, isOffer: boolean }>(null);
|
||||
const [ pendingTree, setPendingTree ] = useState<ICatalogPageData[]>(null);
|
||||
const [ catalogState, dispatchCatalogState ] = useReducer(CatalogReducer, initialCatalog);
|
||||
const [ currentTab, setCurrentTab ] = useState<ICatalogPageData>(null);
|
||||
@ -56,12 +56,24 @@ export const CatalogView: FC<CatalogViewProps> = props =>
|
||||
case 'open':
|
||||
if(parts.length > 2)
|
||||
{
|
||||
setPendingPageLookup(parts[2]);
|
||||
if(parts.length === 4)
|
||||
{
|
||||
switch(parts[2])
|
||||
{
|
||||
case 'offerId':
|
||||
setPendingPageLookup({ value: parts[3], isOffer: true });
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
setPendingPageLookup({ value: parts[2], isOffer: false });
|
||||
}
|
||||
else
|
||||
{
|
||||
setIsVisible(true);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}, []);
|
||||
@ -101,7 +113,7 @@ export const CatalogView: FC<CatalogViewProps> = props =>
|
||||
|
||||
if(pendingPageLookup !== null)
|
||||
{
|
||||
const tree = BuildCatalogPageTree(catalogState.root, pendingPageLookup);
|
||||
const tree = BuildCatalogPageTree(catalogState.root, pendingPageLookup.value, pendingPageLookup.isOffer);
|
||||
|
||||
setCurrentTab(tree.shift());
|
||||
setPendingPageLookup(null);
|
||||
|
@ -184,11 +184,33 @@ export function GetCatalogPageTreeById(page: ICatalogPageData, lookup: number, t
|
||||
}
|
||||
}
|
||||
|
||||
export function BuildCatalogPageTree(page: ICatalogPageData, lookup: string)
|
||||
export function GetCatalogPageTreeByOfferId(page: ICatalogPageData, lookup: number, tree: ICatalogPageData[])
|
||||
{
|
||||
if(page.offerIds.indexOf(lookup) >= 0) return page;
|
||||
|
||||
for(const pageData of page.children)
|
||||
{
|
||||
const foundPageData = GetCatalogPageTreeByOfferId(pageData, lookup, tree);
|
||||
|
||||
if(foundPageData)
|
||||
{
|
||||
tree.push(pageData);
|
||||
|
||||
return pageData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function BuildCatalogPageTree(page: ICatalogPageData, lookup: string, isOffer: boolean = false)
|
||||
{
|
||||
const pageTree: ICatalogPageData[] = [];
|
||||
|
||||
if(isNaN((lookup as unknown) as number))
|
||||
if(isOffer)
|
||||
{
|
||||
GetCatalogPageTreeByOfferId(page, parseInt(lookup), pageTree);
|
||||
}
|
||||
|
||||
else if(isNaN((lookup as unknown) as number))
|
||||
{
|
||||
GetCatalogPageTreeByName(page, lookup, pageTree);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { CrackableDataType, RoomControllerLevel, RoomWidgetEnumItemExtradataParameter, RoomWidgetFurniInfoUsagePolicyEnum, StringDataType } from 'nitro-renderer';
|
||||
import { FC, useCallback, useEffect, useState } from 'react';
|
||||
import { CreateLinkEvent } from '../../../../../../api';
|
||||
import { LocalizeText } from '../../../../../../utils/LocalizeText';
|
||||
import { BadgeImageView } from '../../../../../shared/badge-image/BadgeImageView';
|
||||
import { LimitedEditionCompactPlateView } from '../../../../../shared/limited-edition/compact-plate/LimitedEditionCompactPlateView';
|
||||
@ -150,6 +151,9 @@ export const InfoStandWidgetFurniView: FC<InfoStandWidgetFurniViewProps> = props
|
||||
|
||||
switch(action)
|
||||
{
|
||||
case 'buy_one':
|
||||
CreateLinkEvent(`catalog/open/offerId/${ furniData.purchaseOfferId }`);
|
||||
return;
|
||||
case 'move':
|
||||
messageType = RoomWidgetFurniActionMessage.MOVE;
|
||||
break;
|
||||
@ -198,6 +202,7 @@ export const InfoStandWidgetFurniView: FC<InfoStandWidgetFurniViewProps> = props
|
||||
<i className="icon icon-user-profile me-1 cursor-pointer" />
|
||||
<div className="small text-wrap">{ LocalizeText('furni.owner', [ 'name' ], [ furniData.ownerName ]) }</div>
|
||||
</div>
|
||||
{ (furniData.purchaseOfferId > 0) && <button type="button" className="btn btn-primary btn-sm mt-1" onClick={ event => processButtonAction('buy_one') }>{ LocalizeText('infostand.button.buy') }</button> }
|
||||
{ isCrackable &&
|
||||
<>
|
||||
<hr className="m-0 my-1" />
|
||||
|
Loading…
Reference in New Issue
Block a user