From 63cf84d8725893a4ce1ef223e9f77b81d8ef2f95 Mon Sep 17 00:00:00 2001 From: Bill Date: Wed, 28 Jul 2021 20:13:40 -0400 Subject: [PATCH] Add buy one button --- src/views/catalog/CatalogView.tsx | 18 ++++++++++--- src/views/catalog/common/CatalogUtilities.ts | 26 +++++++++++++++++-- .../views/furni/InfoStandWidgetFurniView.tsx | 13 +++++++--- 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/src/views/catalog/CatalogView.tsx b/src/views/catalog/CatalogView.tsx index 0eb6346e..06d5e17d 100644 --- a/src/views/catalog/CatalogView.tsx +++ b/src/views/catalog/CatalogView.tsx @@ -18,7 +18,7 @@ export const CatalogView: FC = props => { const [ isVisible, setIsVisible ] = useState(false); const [ roomPreviewer, setRoomPreviewer ] = useState(null); - const [ pendingPageLookup, setPendingPageLookup ] = useState(null); + const [ pendingPageLookup, setPendingPageLookup ] = useState<{ value: string, isOffer: boolean }>(null); const [ pendingTree, setPendingTree ] = useState(null); const [ catalogState, dispatchCatalogState ] = useReducer(CatalogReducer, initialCatalog); const [ currentTab, setCurrentTab ] = useState(null); @@ -56,12 +56,24 @@ export const CatalogView: FC = 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 = props => if(pendingPageLookup !== null) { - const tree = BuildCatalogPageTree(catalogState.root, pendingPageLookup); + const tree = BuildCatalogPageTree(catalogState.root, pendingPageLookup.value, pendingPageLookup.isOffer); setCurrentTab(tree.shift()); setPendingPageLookup(null); diff --git a/src/views/catalog/common/CatalogUtilities.ts b/src/views/catalog/common/CatalogUtilities.ts index 68a4beb8..dd7532a5 100644 --- a/src/views/catalog/common/CatalogUtilities.ts +++ b/src/views/catalog/common/CatalogUtilities.ts @@ -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); } diff --git a/src/views/room/widgets/infostand/views/furni/InfoStandWidgetFurniView.tsx b/src/views/room/widgets/infostand/views/furni/InfoStandWidgetFurniView.tsx index 7ffb7e30..1f1ea49e 100644 --- a/src/views/room/widgets/infostand/views/furni/InfoStandWidgetFurniView.tsx +++ b/src/views/room/widgets/infostand/views/furni/InfoStandWidgetFurniView.tsx @@ -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 = 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 = props
{ LocalizeText('furni.owner', [ 'name' ], [ furniData.ownerName ]) }
+ { (furniData.purchaseOfferId > 0) && } { isCrackable && <>
@@ -230,19 +235,19 @@ export const InfoStandWidgetFurniView: FC = props
{ canMove && - } { canRotate && - } { canUse && - } { (pickupMode !== PICKUP_MODE_NONE) && - } { ((furniSettingsKeys.length > 0 && furniSettingsValues.length > 0) && (furniSettingsKeys.length === furniSettingsValues.length)) &&