From aac9f4e038fc8f4dcbd392a79a0ba39d60d661f9 Mon Sep 17 00:00:00 2001 From: oobjectt Date: Sat, 10 Dec 2022 02:24:22 +0100 Subject: [PATCH] Issue #17 - Catalog room events --- .../page/layout/CatalogLayoutRoomAdsView.tsx | 59 +++++++++++++------ src/components/right-side/RightSideView.tsx | 2 + .../room-promotes/RoomPromotesWidgetView.tsx | 55 +++++++++++++++++ .../views/RoomPromoteEditWidgetView.tsx | 44 ++++++++++++++ .../views/RoomPromoteMyOwnEventWidgetView.tsx | 35 +++++++++++ .../views/RoomPromoteOtherEventWidgetView.tsx | 30 ++++++++++ .../room/widgets/room-promotes/views/index.ts | 3 + src/hooks/rooms/index.ts | 1 + src/hooks/rooms/promotes/index.ts | 1 + src/hooks/rooms/promotes/useRoomPromote.ts | 23 ++++++++ 10 files changed, 234 insertions(+), 19 deletions(-) create mode 100644 src/components/room/widgets/room-promotes/RoomPromotesWidgetView.tsx create mode 100644 src/components/room/widgets/room-promotes/views/RoomPromoteEditWidgetView.tsx create mode 100644 src/components/room/widgets/room-promotes/views/RoomPromoteMyOwnEventWidgetView.tsx create mode 100644 src/components/room/widgets/room-promotes/views/RoomPromoteOtherEventWidgetView.tsx create mode 100644 src/components/room/widgets/room-promotes/views/index.ts create mode 100644 src/hooks/rooms/promotes/index.ts create mode 100644 src/hooks/rooms/promotes/useRoomPromote.ts diff --git a/src/components/catalog/views/page/layout/CatalogLayoutRoomAdsView.tsx b/src/components/catalog/views/page/layout/CatalogLayoutRoomAdsView.tsx index d9fc7635..92dd4bff 100644 --- a/src/components/catalog/views/page/layout/CatalogLayoutRoomAdsView.tsx +++ b/src/components/catalog/views/page/layout/CatalogLayoutRoomAdsView.tsx @@ -1,8 +1,8 @@ -import { GetRoomAdPurchaseInfoComposer, GetUserEventCatsMessageComposer, PurchaseRoomAdMessageComposer, RoomAdPurchaseInfoEvent, RoomEntryData, UserEventCatsEvent } from '@nitrots/nitro-renderer'; +import { GetRoomAdPurchaseInfoComposer, GetUserEventCatsMessageComposer, PurchaseRoomAdMessageComposer, RoomAdPurchaseInfoEvent, RoomEntryData } from '@nitrots/nitro-renderer'; import { FC, useEffect, useState } from 'react'; import { LocalizeText, SendMessageComposer } from '../../../../../api'; import { Base, Button, Column, Text } from '../../../../../common'; -import { useMessageEvent } from '../../../../../hooks'; +import { useCatalog, useMessageEvent, useNavigator, useRoomPromote } from '../../../../../hooks'; import { CatalogLayoutProps } from './CatalogLayout.types'; export const CatalogLayoutRoomAdsView: FC = props => @@ -14,7 +14,33 @@ export const CatalogLayoutRoomAdsView: FC = props => const [ availableRooms, setAvailableRooms ] = useState([]); const [ extended, setExtended ] = useState(false); const [ categoryId, setCategoryId ] = useState(1); - const [ categories, setCategories ] = useState(null); + const { categories = null } = useNavigator(); + const { setIsVisible = null } = useCatalog(); + const { promoteInformation, isExtended, setIsExtended } = useRoomPromote(); + + useEffect(() => + { + if(isExtended) + { + setRoomId(promoteInformation.data.flatId); + setEventName(promoteInformation.data.eventName); + setEventDesc(promoteInformation.data.eventDescription); + setCategoryId(promoteInformation.data.categoryId); + setExtended(isExtended); // This is for sending to packet + setIsExtended(false); // This is from hook useRoomPromotte + } + + }, [ isExtended, eventName, eventDesc, categoryId ]); + + const resetData = () => + { + setRoomId(-1); + setEventName(''); + setEventDesc(''); + setCategoryId(1); + setIsExtended(false); + setIsVisible(false); + } const purchaseAd = () => { @@ -25,7 +51,8 @@ export const CatalogLayoutRoomAdsView: FC = props => const desc = eventDesc; const catId = categoryId; - SendMessageComposer(new PurchaseRoomAdMessageComposer(pageId, offerId, flatId, name, extended, desc, catId)) + SendMessageComposer(new PurchaseRoomAdMessageComposer(pageId, offerId, flatId, name, extended, desc, catId)); + resetData(); } useMessageEvent(RoomAdPurchaseInfoEvent, event => @@ -37,13 +64,6 @@ export const CatalogLayoutRoomAdsView: FC = props => setAvailableRooms(parser.rooms); }); - useMessageEvent(UserEventCatsEvent, event => - { - const parser = event.getParser(); - - setCategories(parser.categories); - }); - useEffect(() => { SendMessageComposer(new GetRoomAdPurchaseInfoComposer()); @@ -54,30 +74,31 @@ export const CatalogLayoutRoomAdsView: FC = props => return (<> { LocalizeText('roomad.catalog_header') } - { LocalizeText('roomad.catalog_text') } + { LocalizeText('roomad.catalog_text', [ 'duration' ], [ '120' ]) } - setCategoryId(parseInt(event.target.value)) } disabled={ extended }> + { categories && categories.map((cat, index) => ) } { LocalizeText('roomad.catalog_name') } - setEventName(event.target.value) } /> + setEventName(event.target.value) } readOnly={ extended } /> - < Text bold>{ LocalizeText('roomad.catalog_description') } - + + + + + + + ); +}; diff --git a/src/components/room/widgets/room-promotes/views/RoomPromoteMyOwnEventWidgetView.tsx b/src/components/room/widgets/room-promotes/views/RoomPromoteMyOwnEventWidgetView.tsx new file mode 100644 index 00000000..169cc9b2 --- /dev/null +++ b/src/components/room/widgets/room-promotes/views/RoomPromoteMyOwnEventWidgetView.tsx @@ -0,0 +1,35 @@ +import { FC } from 'react'; +import { CreateLinkEvent, LocalizeText } from '../../../../../api'; +import { Button, Flex, Grid, Text } from '../../../../../common'; +import { useRoomPromote } from '../../../../../hooks'; + +interface RoomPromoteMyOwnEventWidgetViewProps +{ + eventDescription: string; + setIsEditingPromote: (value: boolean) => void; +} + +export const RoomPromoteMyOwnEventWidgetView: FC = props => +{ + const { eventDescription = '', setIsEditingPromote = null } = props; + const { setIsExtended } = useRoomPromote(); + + const extendPromote = () => + { + setIsExtended(true); + CreateLinkEvent('catalog/open/room_event'); + } + + return ( + <> + + { eventDescription } + +

+ + + + + + ); +}; diff --git a/src/components/room/widgets/room-promotes/views/RoomPromoteOtherEventWidgetView.tsx b/src/components/room/widgets/room-promotes/views/RoomPromoteOtherEventWidgetView.tsx new file mode 100644 index 00000000..5adb5176 --- /dev/null +++ b/src/components/room/widgets/room-promotes/views/RoomPromoteOtherEventWidgetView.tsx @@ -0,0 +1,30 @@ +import { FC } from 'react'; +import { LocalizeText } from '../../../../../api'; +import { Base, Column, Flex, Text } from '../../../../../common'; + +interface RoomPromoteOtherEventWidgetViewProps +{ + eventDescription: string; +} + +export const RoomPromoteOtherEventWidgetView: FC = props => +{ + const { eventDescription = '' } = props; + + return ( + <> + + { eventDescription } + +

+ + + + { LocalizeText('navigator.eventinprogress') } + +   + + + + ); +}; diff --git a/src/components/room/widgets/room-promotes/views/index.ts b/src/components/room/widgets/room-promotes/views/index.ts new file mode 100644 index 00000000..da746917 --- /dev/null +++ b/src/components/room/widgets/room-promotes/views/index.ts @@ -0,0 +1,3 @@ +export * from './RoomPromoteEditWidgetView'; +export * from './RoomPromoteMyOwnEventWidgetView'; +export * from './RoomPromoteOtherEventWidgetView'; diff --git a/src/hooks/rooms/index.ts b/src/hooks/rooms/index.ts index 325d8804..e57ecfb1 100644 --- a/src/hooks/rooms/index.ts +++ b/src/hooks/rooms/index.ts @@ -1,3 +1,4 @@ export * from './engine'; +export * from './promotes'; export * from './useRoom'; export * from './widgets'; diff --git a/src/hooks/rooms/promotes/index.ts b/src/hooks/rooms/promotes/index.ts new file mode 100644 index 00000000..b1fd0d3d --- /dev/null +++ b/src/hooks/rooms/promotes/index.ts @@ -0,0 +1 @@ +export * from './useRoomPromote'; diff --git a/src/hooks/rooms/promotes/useRoomPromote.ts b/src/hooks/rooms/promotes/useRoomPromote.ts new file mode 100644 index 00000000..e534d18c --- /dev/null +++ b/src/hooks/rooms/promotes/useRoomPromote.ts @@ -0,0 +1,23 @@ +import { RoomEventEvent, RoomEventMessageParser } from '@nitrots/nitro-renderer'; +import { useState } from 'react'; +import { useBetween } from 'use-between'; +import { useMessageEvent } from '../../events'; + +const useRoomPromoteState = () => +{ + const [ promoteInformation, setPromoteInformation ] = useState(null); + const [ isExtended, setIsExtended ] = useState(false); + + useMessageEvent(RoomEventEvent, event => + { + const parser = event.getParser(); + + if (!parser) return; + + setPromoteInformation(parser); + }); + + return { promoteInformation, isExtended, setPromoteInformation, setIsExtended }; +} + +export const useRoomPromote = () => useBetween(useRoomPromoteState);