diff --git a/src/components/camera/views/CameraWidgetCheckoutView.tsx b/src/components/camera/views/CameraWidgetCheckoutView.tsx index cba04320..6ee92f5a 100644 --- a/src/components/camera/views/CameraWidgetCheckoutView.tsx +++ b/src/components/camera/views/CameraWidgetCheckoutView.tsx @@ -1,5 +1,5 @@ import { CameraPublishStatusMessageEvent, CameraPurchaseOKMessageEvent, CameraStorageUrlMessageEvent, PublishPhotoMessageComposer, PurchasePhotoMessageComposer } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useMemo, useState } from 'react'; +import { FC, useEffect, useMemo, useState } from 'react'; import { CreateLinkEvent, GetConfiguration, GetRoomEngine, LocalizeText, SendMessageComposer } from '../../../api'; import { Button, Column, Flex, LayoutCurrencyIcon, LayoutImage, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../common'; import { useMessageEvent } from '../../../hooks'; @@ -24,15 +24,13 @@ export const CameraWidgetCheckoutView: FC = props const publishDisabled = useMemo(() => GetConfiguration('camera.publish.disabled', false), []); - const onCameraPurchaseOKMessageEvent = useCallback((event: CameraPurchaseOKMessageEvent) => + useMessageEvent(CameraPurchaseOKMessageEvent, event => { setPicturesBought(value => (value + 1)); setIsWaiting(false); - }, []); + }); - useMessageEvent(CameraPurchaseOKMessageEvent, onCameraPurchaseOKMessageEvent); - - const onCameraPublishStatusMessageEvent = useCallback((event: CameraPublishStatusMessageEvent) => + useMessageEvent(CameraPublishStatusMessageEvent, event => { const parser = event.getParser(); @@ -40,18 +38,14 @@ export const CameraWidgetCheckoutView: FC = props setPublishCooldown(parser.secondsToWait); setWasPicturePublished(parser.ok); setIsWaiting(false); - }, []); + }); - useMessageEvent(CameraPublishStatusMessageEvent, onCameraPublishStatusMessageEvent); - - const onCameraStorageUrlMessageEvent = useCallback((event: CameraStorageUrlMessageEvent) => + useMessageEvent(CameraStorageUrlMessageEvent, event => { const parser = event.getParser(); setPictureUrl(GetConfiguration('camera.url') + '/' + parser.url); - }, []); - - useMessageEvent(CameraStorageUrlMessageEvent, onCameraStorageUrlMessageEvent); + }); const processAction = (type: string, value: string | number = null) => { diff --git a/src/components/campaign/CampaignView.tsx b/src/components/campaign/CampaignView.tsx index 6b3a9db8..dec8aea4 100644 --- a/src/components/campaign/CampaignView.tsx +++ b/src/components/campaign/CampaignView.tsx @@ -10,18 +10,16 @@ export const CampaignView: FC<{}> = props => const [ lastOpenAttempt, setLastOpenAttempt ] = useState(-1); const [ receivedProducts, setReceivedProducts ] = useState>(new Map()); const [ isCalendarOpen, setCalendarOpen ] = useState(false); - - const onCampaignCalendarDataMessageEvent = useCallback((event: CampaignCalendarDataMessageEvent) => + + useMessageEvent(CampaignCalendarDataMessageEvent, event => { const parser = event.getParser(); if(!parser) return; setCalendarData(parser.calendarData); - }, []); + }); - useMessageEvent(CampaignCalendarDataMessageEvent, onCampaignCalendarDataMessageEvent); - - const onCampaignCalendarDoorOpenedMessageEvent = useCallback((event: CampaignCalendarDoorOpenedMessageEvent) => + useMessageEvent(CampaignCalendarDoorOpenedMessageEvent, event => { const parser = event.getParser(); @@ -49,9 +47,7 @@ export const CampaignView: FC<{}> = props => } setLastOpenAttempt(-1); - }, [ lastOpenAttempt ]); - - useMessageEvent(CampaignCalendarDoorOpenedMessageEvent, onCampaignCalendarDoorOpenedMessageEvent); + }); const openPackage = useCallback((id: number, asStaff = false) => { diff --git a/src/components/catalog/views/gift/CatalogGiftView.tsx b/src/components/catalog/views/gift/CatalogGiftView.tsx index cf293529..a169a55c 100644 --- a/src/components/catalog/views/gift/CatalogGiftView.tsx +++ b/src/components/catalog/views/gift/CatalogGiftView.tsx @@ -113,12 +113,7 @@ export const CatalogGiftView: FC<{}> = props => } }, [ extraData, maxBoxIndex, maxRibbonIndex, message, offerId, pageId, receiverName, selectedBoxIndex, selectedColorId, selectedRibbonIndex, showMyFace ]); - const onGiftReceiverNotFoundEvent = useCallback(() => - { - setReceiverNotFound(true); - }, []); - - useMessageEvent(GiftReceiverNotFoundEvent, onGiftReceiverNotFoundEvent); + useMessageEvent(GiftReceiverNotFoundEvent, event => setReceiverNotFound(true)); useEffect(() => { diff --git a/src/components/catalog/views/page/common/CatalogRedeemVoucherView.tsx b/src/components/catalog/views/page/common/CatalogRedeemVoucherView.tsx index 23fb9088..f0f8a521 100644 --- a/src/components/catalog/views/page/common/CatalogRedeemVoucherView.tsx +++ b/src/components/catalog/views/page/common/CatalogRedeemVoucherView.tsx @@ -1,6 +1,6 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { RedeemVoucherMessageComposer, VoucherRedeemErrorMessageEvent, VoucherRedeemOkMessageEvent } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useState } from 'react'; +import { FC, useState } from 'react'; import { LocalizeText, SendMessageComposer } from '../../../../../api'; import { Button, Flex } from '../../../../../common'; import { useMessageEvent, useNotification } from '../../../../../hooks'; @@ -26,7 +26,7 @@ export const CatalogRedeemVoucherView: FC = props setIsWaiting(true); } - const onVoucherRedeemOkMessageEvent = useCallback((event: VoucherRedeemOkMessageEvent) => + useMessageEvent(VoucherRedeemOkMessageEvent, event => { const parser = event.getParser(); @@ -38,20 +38,16 @@ export const CatalogRedeemVoucherView: FC = props setIsWaiting(false); setVoucher(''); - }, [ simpleAlert ]); + }); - useMessageEvent(VoucherRedeemOkMessageEvent, onVoucherRedeemOkMessageEvent); - - const onVoucherRedeemErrorMessageEvent = useCallback((event: VoucherRedeemErrorMessageEvent) => + useMessageEvent(VoucherRedeemErrorMessageEvent, event => { const parser = event.getParser(); simpleAlert(LocalizeText(`catalog.alert.voucherredeem.error.description.${ parser.errorCode }`), null, null, null, LocalizeText('catalog.alert.voucherredeem.error.title')); setIsWaiting(false); - }, [ simpleAlert ]); - - useMessageEvent(VoucherRedeemErrorMessageEvent, onVoucherRedeemErrorMessageEvent); + }); return ( diff --git a/src/components/catalog/views/page/layout/CatalogLayoutRoomAdsView.tsx b/src/components/catalog/views/page/layout/CatalogLayoutRoomAdsView.tsx index ee2b056b..67724c81 100644 --- a/src/components/catalog/views/page/layout/CatalogLayoutRoomAdsView.tsx +++ b/src/components/catalog/views/page/layout/CatalogLayoutRoomAdsView.tsx @@ -16,16 +16,14 @@ export const CatalogLayoutRoomAdsView: FC = props => const [ categoryId, setCategoryId ] = useState(1); const [ categories, setCategories ] = useState(null); - const onRoomAdPurchaseInfoEvent = (event: RoomAdPurchaseInfoEvent) => + useMessageEvent(RoomAdPurchaseInfoEvent, event => { const parser = event.getParser(); if(!parser) return; setAvailableRooms(parser.rooms); - } - - useMessageEvent(RoomAdPurchaseInfoEvent, onRoomAdPurchaseInfoEvent); + }); const purchaseAd = useCallback(() => { @@ -39,15 +37,12 @@ export const CatalogLayoutRoomAdsView: FC = props => SendMessageComposer(new PurchaseRoomAdMessageComposer(pageId, offerId, flatId, name, extended, desc, catId)) }, [ categoryId, eventDesc, eventName, extended, page.offers, page.pageId, roomId ]); - - const onUserEventCatsEvent = (event: UserEventCatsEvent) => + useMessageEvent(UserEventCatsEvent, event => { const parser = event.getParser(); setCategories(parser.categories); - } - - useMessageEvent(UserEventCatsEvent, onUserEventCatsEvent); + }); useEffect(() => { diff --git a/src/components/catalog/views/page/layout/marketplace/CatalogLayoutMarketplaceOwnItemsView.tsx b/src/components/catalog/views/page/layout/marketplace/CatalogLayoutMarketplaceOwnItemsView.tsx index b2314ede..5a18378d 100644 --- a/src/components/catalog/views/page/layout/marketplace/CatalogLayoutMarketplaceOwnItemsView.tsx +++ b/src/components/catalog/views/page/layout/marketplace/CatalogLayoutMarketplaceOwnItemsView.tsx @@ -14,7 +14,7 @@ export const CatalogLayoutMarketplaceOwnItemsView: FC = prop const [ offers, setOffers ] = useState([]); const { simpleAlert = null } = useNotification(); - const onMarketPlaceOwnOffersEvent = useCallback((event: MarketplaceOwnOffersEvent) => + useMessageEvent(MarketplaceOwnOffersEvent, event => { const parser = event.getParser(); @@ -30,12 +30,10 @@ export const CatalogLayoutMarketplaceOwnItemsView: FC = prop }); setCreditsWaiting(parser.creditsWaiting); - setOffers(offers); - }, []); + setOffers(offers); + }); - useMessageEvent(MarketplaceOwnOffersEvent, onMarketPlaceOwnOffersEvent); - - const onMarketplaceCancelOfferResultEvent = useCallback((event:MarketplaceCancelOfferResultEvent) => + useMessageEvent(MarketplaceCancelOfferResultEvent, event => { const parser = event.getParser(); @@ -49,9 +47,7 @@ export const CatalogLayoutMarketplaceOwnItemsView: FC = prop } setOffers(prevValue => prevValue.filter(value => (value.offerId !== parser.offerId))); - }, [ simpleAlert ]); - - useMessageEvent(MarketplaceCancelOfferResultEvent, onMarketplaceCancelOfferResultEvent); + }); const soldOffers = useMemo(() => { diff --git a/src/components/catalog/views/page/layout/marketplace/CatalogLayoutMarketplacePublicItemsView.tsx b/src/components/catalog/views/page/layout/marketplace/CatalogLayoutMarketplacePublicItemsView.tsx index 9f6b6560..172e3001 100644 --- a/src/components/catalog/views/page/layout/marketplace/CatalogLayoutMarketplacePublicItemsView.tsx +++ b/src/components/catalog/views/page/layout/marketplace/CatalogLayoutMarketplacePublicItemsView.tsx @@ -64,7 +64,7 @@ export const CatalogLayoutMarketplacePublicItemsView: FC + useMessageEvent(MarketPlaceOffersEvent, event => { const parser = event.getParser(); @@ -80,9 +80,9 @@ export const CatalogLayoutMarketplacePublicItemsView: FC + useMessageEvent(MarketplaceBuyOfferResultEvent, event => { const parser = event.getParser(); @@ -133,10 +133,7 @@ export const CatalogLayoutMarketplacePublicItemsView: FC diff --git a/src/components/catalog/views/page/layout/pets/CatalogLayoutPetView.tsx b/src/components/catalog/views/page/layout/pets/CatalogLayoutPetView.tsx index 50cf1f7d..e8511b79 100644 --- a/src/components/catalog/views/page/layout/pets/CatalogLayoutPetView.tsx +++ b/src/components/catalog/views/page/layout/pets/CatalogLayoutPetView.tsx @@ -104,7 +104,7 @@ export const CatalogLayoutPetView: FC = props => } }, [ page, currentOffer, petName, petPurchaseString, approvalResult ]); - const onApproveNameMessageEvent = useCallback((event: ApproveNameMessageEvent) => + useMessageEvent(ApproveNameMessageEvent, event => { const parser = event.getParser(); @@ -112,9 +112,7 @@ export const CatalogLayoutPetView: FC = props => if(parser.result === 0) purchasePet(); else DispatchUiEvent(new CatalogPurchaseFailureEvent(-1)); - }, [ purchasePet ]); - - useMessageEvent(ApproveNameMessageEvent, onApproveNameMessageEvent); + }); useEffect(() => { diff --git a/src/components/floorplan-editor/FloorplanEditorView.tsx b/src/components/floorplan-editor/FloorplanEditorView.tsx index 318d6f7e..995e8f73 100644 --- a/src/components/floorplan-editor/FloorplanEditorView.tsx +++ b/src/components/floorplan-editor/FloorplanEditorView.tsx @@ -1,5 +1,5 @@ import { FloorHeightMapEvent, ILinkEventTracker, NitroPoint, RoomEngineEvent, RoomVisualizationSettingsEvent, UpdateFloorPropertiesMessageComposer } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useState } from 'react'; +import { FC, useEffect, useState } from 'react'; import { AddEventLinkTracker, LocalizeText, RemoveLinkEventTracker, SendMessageComposer } from '../../api'; import { Button, ButtonGroup, Flex, NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../common'; import { useMessageEvent, useRoomEngineEvent } from '../../hooks'; @@ -54,14 +54,9 @@ export const FloorplanEditorView: FC<{}> = props => FloorplanEditor.instance.renderTiles(); } - const onRoomEngineEvent = useCallback((event: RoomEngineEvent) => - { - setIsVisible(false); - }, []); + useRoomEngineEvent(RoomEngineEvent.DISPOSED, event => setIsVisible(false)); - useRoomEngineEvent(RoomEngineEvent.DISPOSED, onRoomEngineEvent); - - const onFloorHeightMapEvent = useCallback((event: FloorHeightMapEvent) => + useMessageEvent(FloorHeightMapEvent, event => { const parser = event.getParser(); @@ -83,11 +78,9 @@ export const FloorplanEditorView: FC<{}> = props => return newValue; }); - }, []); + }); - useMessageEvent(FloorHeightMapEvent, onFloorHeightMapEvent); - - const onRoomVisualizationSettingsEvent = useCallback((event: RoomVisualizationSettingsEvent) => + useMessageEvent(RoomVisualizationSettingsEvent, event => { const parser = event.getParser(); @@ -110,9 +103,7 @@ export const FloorplanEditorView: FC<{}> = props => return newValue; }); - }, []); - - useMessageEvent(RoomVisualizationSettingsEvent, onRoomVisualizationSettingsEvent); + }); useEffect(() => { diff --git a/src/components/floorplan-editor/views/FloorplanCanvasView.tsx b/src/components/floorplan-editor/views/FloorplanCanvasView.tsx index e33c4820..83417749 100644 --- a/src/components/floorplan-editor/views/FloorplanCanvasView.tsx +++ b/src/components/floorplan-editor/views/FloorplanCanvasView.tsx @@ -1,6 +1,6 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { GetOccupiedTilesMessageComposer, GetRoomEntryTileMessageComposer, NitroPoint, RoomEntryTileMessageEvent, RoomOccupiedTilesMessageEvent } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useRef, useState } from 'react'; +import { FC, useEffect, useRef, useState } from 'react'; import { SendMessageComposer } from '../../../api'; import { Base, Button, Column, ColumnProps, Flex, Grid } from '../../../common'; import { useMessageEvent } from '../../../hooks'; @@ -15,7 +15,7 @@ export const FloorplanCanvasView: FC = props => const { originalFloorplanSettings = null, setOriginalFloorplanSettings = null, setVisualizationSettings = null } = useFloorplanEditorContext(); const elementRef = useRef(null); - const onRoomOccupiedTilesMessageEvent = useCallback((event: RoomOccupiedTilesMessageEvent) => + useMessageEvent(RoomOccupiedTilesMessageEvent, event => { const parser = event.getParser(); @@ -33,11 +33,9 @@ export const FloorplanCanvasView: FC = props => setOccupiedTilesReceived(true); elementRef.current.scrollTo((FloorplanEditor.instance.view.width / 3), 0); - }, [ setOriginalFloorplanSettings ]); + }); - useMessageEvent(RoomOccupiedTilesMessageEvent, onRoomOccupiedTilesMessageEvent); - - const onRoomEntryTileMessageEvent = useCallback((event: RoomEntryTileMessageEvent) => + useMessageEvent(RoomEntryTileMessageEvent, event => { const parser = event.getParser(); @@ -63,9 +61,7 @@ export const FloorplanCanvasView: FC = props => FloorplanEditor.instance.doorLocation = new NitroPoint(parser.x, parser.y); setEntryTileReceived(true); - }, [ setOriginalFloorplanSettings, setVisualizationSettings ]); - - useMessageEvent(RoomEntryTileMessageEvent, onRoomEntryTileMessageEvent); + }); const onClickArrowButton = (scrollDirection: string) => { diff --git a/src/components/friends/views/friends-list/FriendsListSearchView.tsx b/src/components/friends/views/friends-list/FriendsListSearchView.tsx index f1132a78..69073a22 100644 --- a/src/components/friends/views/friends-list/FriendsListSearchView.tsx +++ b/src/components/friends/views/friends-list/FriendsListSearchView.tsx @@ -1,5 +1,5 @@ import { HabboSearchComposer, HabboSearchResultData, HabboSearchResultEvent } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useState } from 'react'; +import { FC, useEffect, useState } from 'react'; import { LocalizeText, OpenMessengerChat, SendMessageComposer } from '../../../../api'; import { Base, Column, Flex, NitroCardAccordionItemView, NitroCardAccordionSetView, NitroCardAccordionSetViewProps, Text, UserProfileIconView } from '../../../../common'; import { useFriends, useMessageEvent } from '../../../../hooks'; @@ -17,15 +17,13 @@ export const FriendsSearchView: FC = props => const [ otherResults, setOtherResults ] = useState(null); const { canRequestFriend = null, requestFriend = null } = useFriends(); - const onHabboSearchResultEvent = useCallback((event: HabboSearchResultEvent) => + useMessageEvent(HabboSearchResultEvent, event => { const parser = event.getParser(); setFriendResults(parser.friends); setOtherResults(parser.others); - }, []); - - useMessageEvent(HabboSearchResultEvent, onHabboSearchResultEvent); + }); useEffect(() => { diff --git a/src/components/groups/views/GroupCreatorView.tsx b/src/components/groups/views/GroupCreatorView.tsx index a283c762..cd64ef3a 100644 --- a/src/components/groups/views/GroupCreatorView.tsx +++ b/src/components/groups/views/GroupCreatorView.tsx @@ -1,5 +1,5 @@ import { GroupBuyComposer, GroupBuyDataComposer, GroupBuyDataEvent } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useState } from 'react'; +import { FC, useEffect, useState } from 'react'; import { HasHabboClub, IGroupData, LocalizeText, SendMessageComposer } from '../../../api'; import { Base, Button, Column, Flex, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../common'; import { useMessageEvent } from '../../../hooks'; @@ -85,7 +85,7 @@ export const GroupCreatorView: FC = props => setCurrentTab(value => (value === 4 ? value : value + 1)); } - const onGroupBuyDataEvent = useCallback((event: GroupBuyDataEvent) => + useMessageEvent(GroupBuyDataEvent, event => { const parser = event.getParser(); @@ -95,9 +95,7 @@ export const GroupCreatorView: FC = props => setAvailableRooms(rooms); setPurchaseCost(parser.groupCost); - }, []); - - useMessageEvent(GroupBuyDataEvent, onGroupBuyDataEvent); + }); useEffect(() => { diff --git a/src/components/groups/views/GroupInformationStandaloneView.tsx b/src/components/groups/views/GroupInformationStandaloneView.tsx index 9ec1e5dc..d4206d7f 100644 --- a/src/components/groups/views/GroupInformationStandaloneView.tsx +++ b/src/components/groups/views/GroupInformationStandaloneView.tsx @@ -1,5 +1,5 @@ import { GroupInformationEvent, GroupInformationParser } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useState } from 'react'; +import { FC, useState } from 'react'; import { LocalizeText } from '../../../api'; import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../../common'; import { useMessageEvent } from '../../../hooks'; @@ -9,14 +9,12 @@ export const GroupInformationStandaloneView: FC<{}> = props => { const [ groupInformation, setGroupInformation ] = useState(null); - const onGroupInformationEvent = useCallback((event: GroupInformationEvent) => + useMessageEvent(GroupInformationEvent, event => { const parser = event.getParser(); if((groupInformation && (groupInformation.id === parser.id)) || parser.flag) setGroupInformation(parser); - }, [ groupInformation ]); - - useMessageEvent(GroupInformationEvent, onGroupInformationEvent); + }); if(!groupInformation) return null; diff --git a/src/components/groups/views/GroupMembersView.tsx b/src/components/groups/views/GroupMembersView.tsx index 91a8bf96..a7e97abc 100644 --- a/src/components/groups/views/GroupMembersView.tsx +++ b/src/components/groups/views/GroupMembersView.tsx @@ -73,18 +73,16 @@ export const GroupMembersView: FC<{}> = props => SendMessageComposer(new GroupConfirmRemoveMemberComposer(membersData.groupId, member.id)); } - const onGroupMembersEvent = useCallback((event: GroupMembersEvent) => + useMessageEvent(GroupMembersEvent, event => { const parser = event.getParser(); setMembersData(parser); setLevelId(parser.level); setTotalPages(Math.ceil(parser.totalMembersCount / parser.pageSize)); - }, []); + }); - useMessageEvent(GroupMembersEvent, onGroupMembersEvent); - - const onGroupConfirmMemberRemoveEvent = useCallback((event: GroupConfirmMemberRemoveEvent) => + useMessageEvent(GroupConfirmMemberRemoveEvent, event => { const parser = event.getParser(); @@ -96,9 +94,7 @@ export const GroupMembersView: FC<{}> = props => }, null); setRemovingMemberName(null); - }, [ membersData, removingMemberName, refreshMembers, showConfirm ]); - - useMessageEvent(GroupConfirmMemberRemoveEvent, onGroupConfirmMemberRemoveEvent); + }); useEffect(() => { diff --git a/src/components/groups/views/GroupRoomInformationView.tsx b/src/components/groups/views/GroupRoomInformationView.tsx index 5f7e4433..4c6ae9a4 100644 --- a/src/components/groups/views/GroupRoomInformationView.tsx +++ b/src/components/groups/views/GroupRoomInformationView.tsx @@ -1,6 +1,6 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { DesktopViewEvent, GetGuestRoomResultEvent, GroupInformationComposer, GroupInformationEvent, GroupInformationParser, GroupRemoveMemberComposer, HabboGroupDeactivatedMessageEvent, RoomEntryInfoMessageEvent } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useState } from 'react'; +import { FC, useState } from 'react'; import { GetGroupInformation, GetGroupManager, GetSessionDataManager, GroupMembershipType, GroupType, LocalizeText, SendMessageComposer, TryJoinGroup } from '../../../api'; import { Base, Button, Column, Flex, LayoutBadgeImageView, Text } from '../../../common'; import { useMessageEvent, useNotification } from '../../../hooks'; @@ -12,23 +12,19 @@ export const GroupRoomInformationView: FC<{}> = props => const [ isOpen, setIsOpen ] = useState(true); const { showConfirm = null } = useNotification(); - const onDesktopViewEvent = useCallback((event: DesktopViewEvent) => + useMessageEvent(DesktopViewEvent, event => { setExpectedGroupId(0); setGroupInformation(null); - }, []); + }); - useMessageEvent(DesktopViewEvent, onDesktopViewEvent); - - const onRoomEntryInfoMessageEvent = useCallback((event: RoomEntryInfoMessageEvent) => + useMessageEvent(RoomEntryInfoMessageEvent, event => { setExpectedGroupId(0); setGroupInformation(null); - }, []); + }); - useMessageEvent(RoomEntryInfoMessageEvent, onRoomEntryInfoMessageEvent); - - const onGetGuestRoomResultEvent = useCallback((event: GetGuestRoomResultEvent) => + useMessageEvent(GetGuestRoomResultEvent, event => { const parser = event.getParser(); @@ -44,11 +40,9 @@ export const GroupRoomInformationView: FC<{}> = props => setExpectedGroupId(0); setGroupInformation(null); } - }, []); + }); - useMessageEvent(GetGuestRoomResultEvent, onGetGuestRoomResultEvent); - - const onHabboGroupDeactivatedMessageEvent = useCallback((event: HabboGroupDeactivatedMessageEvent) => + useMessageEvent(HabboGroupDeactivatedMessageEvent, event => { const parser = event.getParser(); @@ -56,20 +50,16 @@ export const GroupRoomInformationView: FC<{}> = props => setExpectedGroupId(0); setGroupInformation(null); - }, [ expectedGroupId, groupInformation ]); + }); - useMessageEvent(HabboGroupDeactivatedMessageEvent, onHabboGroupDeactivatedMessageEvent); - - const onGroupInformationEvent = useCallback((event: GroupInformationEvent) => + useMessageEvent(GroupInformationEvent, event => { const parser = event.getParser(); if(parser.id !== expectedGroupId) return; setGroupInformation(parser); - }, [ expectedGroupId ]); - - useMessageEvent(GroupInformationEvent, onGroupInformationEvent); + }); const leaveGroup = () => { diff --git a/src/components/guide-tool/GuideToolView.tsx b/src/components/guide-tool/GuideToolView.tsx index 589a5485..cec4f5f7 100644 --- a/src/components/guide-tool/GuideToolView.tsx +++ b/src/components/guide-tool/GuideToolView.tsx @@ -107,7 +107,7 @@ export const GuideToolView: FC<{}> = props => useUiEvent(GuideToolEvent.TOGGLE_GUIDE_TOOL, onGuideToolEvent); useUiEvent(GuideToolEvent.CREATE_HELP_REQUEST, onGuideToolEvent); - const onPerkAllowancesMessageEvent = useCallback((event: PerkAllowancesMessageEvent) => + useMessageEvent(PerkAllowancesMessageEvent, event => { const parser = event.getParser(); @@ -116,11 +116,9 @@ export const GuideToolView: FC<{}> = props => setIsOnDuty(false); SendMessageComposer(new GuideSessionOnDutyUpdateMessageComposer(false, false, false, false)); } - }, [ isOnDuty, setIsOnDuty ]); + }); - useMessageEvent(PerkAllowancesMessageEvent, onPerkAllowancesMessageEvent); - - const onGuideOnDutyStatusMessageEvent = useCallback((event: GuideOnDutyStatusMessageEvent) => + useMessageEvent(GuideOnDutyStatusMessageEvent, event => { const parser = event.getParser(); @@ -128,11 +126,9 @@ export const GuideToolView: FC<{}> = props => setGuidesOnDuty(parser.guidesOnDuty); setHelpersOnDuty(parser.helpersOnDuty); setGuardiansOnDuty(parser.guardiansOnDuty); - }, [ setIsOnDuty, setHelpersOnDuty, setGuidesOnDuty, setGuardiansOnDuty ]); + }); - useMessageEvent(GuideOnDutyStatusMessageEvent, onGuideOnDutyStatusMessageEvent); - - const onGuideSessionAttachedMessageEvent = useCallback((event: GuideSessionAttachedMessageEvent) => + useMessageEvent(GuideSessionAttachedMessageEvent, event => { const parser = event.getParser(); @@ -142,12 +138,9 @@ export const GuideToolView: FC<{}> = props => if(parser.asGuide && isOnDuty) updateSessionState(GuideSessionState.GUIDE_ACCEPT); if(!parser.asGuide) updateSessionState(GuideSessionState.USER_PENDING); - - }, [ isOnDuty, updateSessionState ]); + }); - useMessageEvent(GuideSessionAttachedMessageEvent, onGuideSessionAttachedMessageEvent); - - const onGuideSessionStartedMessageEvent = useCallback((event: GuideSessionStartedMessageEvent) => + useMessageEvent(GuideSessionStartedMessageEvent, event => { const parser = event.getParser(); @@ -165,20 +158,16 @@ export const GuideToolView: FC<{}> = props => setOngoingFigure(parser.guideFigure); updateSessionState(GuideSessionState.USER_ONGOING, parser.guideName); } - }, [ isOnDuty, updateSessionState ]); + }); - useMessageEvent(GuideSessionStartedMessageEvent, onGuideSessionStartedMessageEvent); - - const onGuideSessionPartnerIsTypingMessageEvent = useCallback((event: GuideSessionPartnerIsTypingMessageEvent) => + useMessageEvent(GuideSessionPartnerIsTypingMessageEvent, event => { const parser = event.getParser(); setOngoingIsTyping(parser.isTyping); - }, []); + }); - useMessageEvent(GuideSessionPartnerIsTypingMessageEvent, onGuideSessionPartnerIsTypingMessageEvent); - - const onGuideSessionMessageMessageEvent = useCallback((event: GuideSessionMessageMessageEvent) => + useMessageEvent(GuideSessionMessageMessageEvent, event => { const parser = event.getParser(); @@ -194,11 +183,9 @@ export const GuideToolView: FC<{}> = props => lastGroup.addChat(new GuideToolMessage(parser.chatMessage)); setOngoingMessageGroups(messageGroups); - }, [ ongoingMessageGroups ]); + }); - useMessageEvent(GuideSessionMessageMessageEvent, onGuideSessionMessageMessageEvent); - - const onGuideSessionInvitedToGuideRoomMessageEvent = useCallback((event: GuideSessionInvitedToGuideRoomMessageEvent) => + useMessageEvent(GuideSessionInvitedToGuideRoomMessageEvent, event => { const parser = event.getParser(); @@ -216,11 +203,9 @@ export const GuideToolView: FC<{}> = props => lastGroup.addChat(new GuideToolMessage(parser.roomName, parser.roomId)); setOngoingMessageGroups(messageGroups); - }, [ isOnDuty, ongoingMessageGroups, ongoingUserId ]); + }); - useMessageEvent(GuideSessionInvitedToGuideRoomMessageEvent, onGuideSessionInvitedToGuideRoomMessageEvent); - - const onGuideSessionEndedMessageEvent = useCallback((event: GuideSessionEndedMessageEvent) => + useMessageEvent(GuideSessionEndedMessageEvent, event => { if(isOnDuty) { @@ -235,11 +220,9 @@ export const GuideToolView: FC<{}> = props => { updateSessionState(GuideSessionState.USER_FEEDBACK); } - }, [ isOnDuty, updateSessionState ]); + }); - useMessageEvent(GuideSessionEndedMessageEvent, onGuideSessionEndedMessageEvent); - - const onGuideSessionDetachedMessageEvent = useCallback((event: GuideSessionDetachedMessageEvent) => + useMessageEvent(GuideSessionDetachedMessageEvent, event => { setOngoingUserId(0); setOngoingUsername(null); @@ -256,9 +239,7 @@ export const GuideToolView: FC<{}> = props => { updateSessionState(GuideSessionState.USER_THANKS); } - }, [ isOnDuty, updateSessionState ]); - - useMessageEvent(GuideSessionDetachedMessageEvent, onGuideSessionDetachedMessageEvent); + }); useEffect(() => { diff --git a/src/components/guide-tool/views/GuideToolOngoingView.tsx b/src/components/guide-tool/views/GuideToolOngoingView.tsx index 08ed8119..7dd01850 100644 --- a/src/components/guide-tool/views/GuideToolOngoingView.tsx +++ b/src/components/guide-tool/views/GuideToolOngoingView.tsx @@ -35,14 +35,12 @@ export const GuideToolOngoingView: FC = props => SendMessageComposer(new GuideSessionResolvedMessageComposer()); }, []); - const onGuideSessionRequesterRoomMessageEvent = useCallback((event: GuideSessionRequesterRoomMessageEvent) => + useMessageEvent(GuideSessionRequesterRoomMessageEvent, event => { const parser = event.getParser(); TryVisitRoom(parser.requesterRoomId); - }, []); - - useMessageEvent(GuideSessionRequesterRoomMessageEvent, onGuideSessionRequesterRoomMessageEvent); + }); const sendMessage = useCallback(() => { diff --git a/src/components/hc-center/HcCenterView.tsx b/src/components/hc-center/HcCenterView.tsx index eb553075..2c94d395 100644 --- a/src/components/hc-center/HcCenterView.tsx +++ b/src/components/hc-center/HcCenterView.tsx @@ -1,5 +1,5 @@ import { ClubGiftInfoEvent, FriendlyTime, GetClubGiftInfo, ILinkEventTracker, ScrGetKickbackInfoMessageComposer, ScrKickbackData, ScrSendKickbackInfoMessageEvent } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useState } from 'react'; +import { FC, useEffect, useState } from 'react'; import { OverlayTrigger, Popover } from 'react-bootstrap'; import { AddEventLinkTracker, ClubStatus, CreateLinkEvent, GetClubBadge, GetConfiguration, LocalizeText, RemoveLinkEventTracker, SendMessageComposer } from '../../api'; import { Base, Button, Column, Flex, LayoutAvatarImageView, LayoutBadgeImageView, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../common'; @@ -44,23 +44,19 @@ export const HcCenterView: FC<{}> = props => const getHcPaydayTime = () => (kickbackData.timeUntilPayday < 60) ? LocalizeText('hccenter.special.time.soon') : FriendlyTime.shortFormat(kickbackData.timeUntilPayday * 60); const getHcPaydayAmount = () => LocalizeText('hccenter.special.sum', [ 'credits' ], [ (kickbackData.creditRewardForStreakBonus + kickbackData.creditRewardForMonthlySpent).toString() ]); - const onClubGiftInfoEvent = useCallback((event: ClubGiftInfoEvent) => + useMessageEvent(ClubGiftInfoEvent, event => { const parser = event.getParser(); setUnclaimedGifts(parser.giftsAvailable); - }, []); + }); - useMessageEvent(ClubGiftInfoEvent, onClubGiftInfoEvent); - - const onScrSendKickbackInfo = useCallback((event: ScrSendKickbackInfoMessageEvent) => + useMessageEvent(ScrSendKickbackInfoMessageEvent, event => { const parser = event.getParser(); setKickbackData(parser.data); - }, []); - - useMessageEvent(ScrSendKickbackInfoMessageEvent, onScrSendKickbackInfo); + }); useEffect(() => { diff --git a/src/components/help/views/name-change/NameChangeConfirmationView.tsx b/src/components/help/views/name-change/NameChangeConfirmationView.tsx index 0061a381..8aef9c26 100644 --- a/src/components/help/views/name-change/NameChangeConfirmationView.tsx +++ b/src/components/help/views/name-change/NameChangeConfirmationView.tsx @@ -7,10 +7,9 @@ import { NameChangeLayoutViewProps } from './NameChangeView.types'; export const NameChangeConfirmationView:FC = props => { const { username = '', onAction = null } = props; - const [ isConfirming, setIsConfirming ] = useState(false); - - const onUserNameChangeMessageEvent = useCallback((event: UserNameChangeMessageEvent) => + + useMessageEvent(UserNameChangeMessageEvent, event => { const parser = event.getParser(); @@ -19,9 +18,7 @@ export const NameChangeConfirmationView:FC = props => if(parser.webId !== GetSessionDataManager().userId) return; onAction('close'); - }, [ onAction ]); - - useMessageEvent(UserNameChangeMessageEvent, onUserNameChangeMessageEvent); + }); const confirm = useCallback(() => { diff --git a/src/components/help/views/name-change/NameChangeInputView.tsx b/src/components/help/views/name-change/NameChangeInputView.tsx index 7554b9b2..cfcb540a 100644 --- a/src/components/help/views/name-change/NameChangeInputView.tsx +++ b/src/components/help/views/name-change/NameChangeInputView.tsx @@ -20,8 +20,8 @@ export const NameChangeInputView:FC = props => const [ isChecking, setIsChecking ] = useState(false); const [ errorCode, setErrorCode ] = useState(null); const [ suggestions, setSuggestions ] = useState([]); - - const onCheckUserNameResultMessageEvent = useCallback((event: CheckUserNameResultMessageEvent) => + + useMessageEvent(CheckUserNameResultMessageEvent, event => { setIsChecking(false); @@ -50,9 +50,7 @@ export const NameChangeInputView:FC = props => case DISABLED: setErrorCode('change_not_allowed'); } - }, []); - - useMessageEvent(CheckUserNameResultMessageEvent, onCheckUserNameResultMessageEvent); + }); const check = useCallback(() => { diff --git a/src/components/hotel-view/views/widgets/bonus-rare/BonusRareWidgetView.tsx b/src/components/hotel-view/views/widgets/bonus-rare/BonusRareWidgetView.tsx index fa6c4b0b..ee32c54f 100644 --- a/src/components/hotel-view/views/widgets/bonus-rare/BonusRareWidgetView.tsx +++ b/src/components/hotel-view/views/widgets/bonus-rare/BonusRareWidgetView.tsx @@ -1,5 +1,5 @@ import { BonusRareInfoMessageEvent, GetBonusRareInfoMessageComposer } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useState } from 'react'; +import { FC, useEffect, useState } from 'react'; import { SendMessageComposer } from '../../../../../api'; import { useMessageEvent } from '../../../../../hooks'; @@ -13,7 +13,7 @@ export const BonusRareWidgetView: FC = props => const [ totalCoinsForBonus, setTotalCoinsForBonus ] = useState(null); const [ coinsStillRequiredToBuy, setCoinsStillRequiredToBuy ] = useState(null); - const onBonusRareInfoMessageEvent = useCallback((event: BonusRareInfoMessageEvent) => + useMessageEvent(BonusRareInfoMessageEvent, event => { const parser = event.getParser(); @@ -21,9 +21,7 @@ export const BonusRareWidgetView: FC = props => setProductClassId(parser.productClassId); setTotalCoinsForBonus(parser.totalCoinsForBonus); setCoinsStillRequiredToBuy(parser.coinsStillRequiredToBuy); - }, []); - - useMessageEvent(BonusRareInfoMessageEvent, onBonusRareInfoMessageEvent); + }); useEffect(() => { diff --git a/src/components/hotel-view/views/widgets/hall-of-fame/HallOfFameWidgetView.tsx b/src/components/hotel-view/views/widgets/hall-of-fame/HallOfFameWidgetView.tsx index 4beddebf..582ce041 100644 --- a/src/components/hotel-view/views/widgets/hall-of-fame/HallOfFameWidgetView.tsx +++ b/src/components/hotel-view/views/widgets/hall-of-fame/HallOfFameWidgetView.tsx @@ -1,5 +1,5 @@ import { CommunityGoalHallOfFameData, CommunityGoalHallOfFameMessageEvent, GetCommunityGoalHallOfFameMessageComposer } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useState } from 'react'; +import { FC, useEffect, useState } from 'react'; import { SendMessageComposer } from '../../../../../api'; import { useMessageEvent } from '../../../../../hooks'; import { HallOfFameItemView } from '../hall-of-fame-item/HallOfFameItemView'; @@ -10,14 +10,12 @@ export const HallOfFameWidgetView: FC = props => const { slot = -1, conf = null } = props; const [ data, setData ] = useState(null); - const onCommunityGoalHallOfFameMessageEvent = useCallback((event: CommunityGoalHallOfFameMessageEvent) => + useMessageEvent(CommunityGoalHallOfFameMessageEvent, event => { const parser = event.getParser(); setData(parser.data); - }, []); - - useMessageEvent(CommunityGoalHallOfFameMessageEvent, onCommunityGoalHallOfFameMessageEvent); + }); useEffect(() => { diff --git a/src/components/hotel-view/views/widgets/promo-article/PromoArticleWidgetView.tsx b/src/components/hotel-view/views/widgets/promo-article/PromoArticleWidgetView.tsx index e434ed25..65393247 100644 --- a/src/components/hotel-view/views/widgets/promo-article/PromoArticleWidgetView.tsx +++ b/src/components/hotel-view/views/widgets/promo-article/PromoArticleWidgetView.tsx @@ -1,5 +1,5 @@ import { GetPromoArticlesComposer, PromoArticleData, PromoArticlesMessageEvent } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useState } from 'react'; +import { FC, useEffect, useState } from 'react'; import { LocalizeText, OpenUrl, SendMessageComposer } from '../../../../../api'; import { useMessageEvent } from '../../../../../hooks'; @@ -8,13 +8,11 @@ export const PromoArticleWidgetView: FC<{}> = props => const [ articles, setArticles ] = useState(null); const [ index, setIndex ] = useState(0); - const onPromoArticlesMessageEvent = useCallback((event: PromoArticlesMessageEvent) => + useMessageEvent(PromoArticlesMessageEvent, event => { const parser = event.getParser(); setArticles(parser.articles); - }, []); - - useMessageEvent(PromoArticlesMessageEvent, onPromoArticlesMessageEvent); + }); useEffect(() => { diff --git a/src/components/inventory/InventoryView.tsx b/src/components/inventory/InventoryView.tsx index 544a236b..8a3410a8 100644 --- a/src/components/inventory/InventoryView.tsx +++ b/src/components/inventory/InventoryView.tsx @@ -1,5 +1,5 @@ import { BadgePointLimitsEvent, ILinkEventTracker, IRoomSession, RoomEngineObjectEvent, RoomEngineObjectPlacedEvent, RoomPreviewer, RoomSessionEvent } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useState } from 'react'; +import { FC, useEffect, useState } from 'react'; import { AddEventLinkTracker, GetLocalization, GetRoomEngine, isObjectMoverRequested, LocalizeText, RemoveLinkEventTracker, setObjectMoverRequested, UnseenItemCategory } from '../../api'; import { NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView } from '../../common'; import { useInventoryTrade, useInventoryUnseenTracker, useMessageEvent, useRoomEngineEvent, useRoomSessionManagerEvent } from '../../hooks'; @@ -32,18 +32,19 @@ export const InventoryView: FC<{}> = props => setIsVisible(false); } - const onRoomEngineObjectPlacedEvent = useCallback((event: RoomEngineObjectPlacedEvent) => + useRoomEngineEvent(RoomEngineObjectEvent.PLACED, event => { if(!isObjectMoverRequested()) return; setObjectMoverRequested(false); if(!event.placedInRoom) setIsVisible(true); - }, []); + }); - useRoomEngineEvent(RoomEngineObjectEvent.PLACED, onRoomEngineObjectPlacedEvent); - - const onRoomSessionEvent = useCallback((event: RoomSessionEvent) => + useRoomSessionManagerEvent([ + RoomSessionEvent.CREATED, + RoomSessionEvent.ENDED + ], event => { switch(event.type) { @@ -55,19 +56,14 @@ export const InventoryView: FC<{}> = props => setIsVisible(false); return; } - }, []); + }); - useRoomSessionManagerEvent(RoomSessionEvent.CREATED, onRoomSessionEvent); - useRoomSessionManagerEvent(RoomSessionEvent.ENDED, onRoomSessionEvent); - - const onBadgePointLimitsEvent = useCallback((event: BadgePointLimitsEvent) => + useMessageEvent(BadgePointLimitsEvent, event => { const parser = event.getParser(); for(const data of parser.data) GetLocalization().setBadgePointLimit(data.badgeId, data.limit); - }, []); - - useMessageEvent(BadgePointLimitsEvent, onBadgePointLimitsEvent); + }); useEffect(() => { diff --git a/src/components/navigator/views/room-settings/NavigatorRoomSettingsModTabView.tsx b/src/components/navigator/views/room-settings/NavigatorRoomSettingsModTabView.tsx index 1b5f3f67..2bf48c2a 100644 --- a/src/components/navigator/views/room-settings/NavigatorRoomSettingsModTabView.tsx +++ b/src/components/navigator/views/room-settings/NavigatorRoomSettingsModTabView.tsx @@ -16,16 +16,14 @@ export const NavigatorRoomSettingsModTabView: FC(-1); const [ bannedUsers, setBannedUsers ] = useState([]); - const onBannedUsersFromRoomEvent = useCallback((event: BannedUsersFromRoomEvent) => + useMessageEvent(BannedUsersFromRoomEvent, event => { const parser = event.getParser(); if(!roomData || (roomData.roomId !== parser.roomId)) return; setBannedUsers(parser.bannedUsers); - }, [ roomData ]); - - useMessageEvent(BannedUsersFromRoomEvent, onBannedUsersFromRoomEvent); + }); const unBanUser = useCallback((userId: number) => { diff --git a/src/components/navigator/views/room-settings/NavigatorRoomSettingsRightsTabView.tsx b/src/components/navigator/views/room-settings/NavigatorRoomSettingsRightsTabView.tsx index a7ea65fc..ac17d13f 100644 --- a/src/components/navigator/views/room-settings/NavigatorRoomSettingsRightsTabView.tsx +++ b/src/components/navigator/views/room-settings/NavigatorRoomSettingsRightsTabView.tsx @@ -1,5 +1,5 @@ import { FlatControllerAddedEvent, FlatControllerRemovedEvent, FlatControllersEvent, RemoveAllRightsMessageComposer, RoomTakeRightsComposer, RoomUsersWithRightsComposer } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useState } from 'react'; +import { FC, useEffect, useState } from 'react'; import { IRoomData, LocalizeText, SendMessageComposer } from '../../../../api'; import { Button, Column, Flex, Grid, Text, UserProfileIconView } from '../../../../common'; import { useMessageEvent } from '../../../../hooks'; @@ -15,18 +15,16 @@ export const NavigatorRoomSettingsRightsTabView: FC>(new Map()); - const onFlatControllersEvent = useCallback((event: FlatControllersEvent) => + useMessageEvent(FlatControllersEvent, event => { const parser = event.getParser(); if(!roomData || (roomData.roomId !== parser.roomId)) return; setUsersWithRights(parser.users); - }, [ roomData ]); + }); - useMessageEvent(FlatControllersEvent, onFlatControllersEvent); - - const onFlatControllerAddedEvent = useCallback((event: FlatControllerAddedEvent) => + useMessageEvent(FlatControllerAddedEvent, event => { const parser = event.getParser(); @@ -40,11 +38,9 @@ export const NavigatorRoomSettingsRightsTabView: FC + useMessageEvent(FlatControllerRemovedEvent, event => { const parser = event.getParser(); @@ -57,10 +53,8 @@ export const NavigatorRoomSettingsRightsTabView: FC { diff --git a/src/components/navigator/views/room-settings/NavigatorRoomSettingsView.tsx b/src/components/navigator/views/room-settings/NavigatorRoomSettingsView.tsx index 5eae5a05..ed03de13 100644 --- a/src/components/navigator/views/room-settings/NavigatorRoomSettingsView.tsx +++ b/src/components/navigator/views/room-settings/NavigatorRoomSettingsView.tsx @@ -1,5 +1,5 @@ import { RoomBannedUsersComposer, RoomDataParser, RoomSettingsDataEvent, SaveRoomSettingsComposer } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useState } from 'react'; +import { FC, useState } from 'react'; import { IRoomData, LocalizeText, SendMessageComposer } from '../../../../api'; import { NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView } from '../../../../common'; import { useMessageEvent } from '../../../../hooks'; @@ -22,7 +22,7 @@ export const NavigatorRoomSettingsView: FC<{}> = props => const [ roomData, setRoomData ] = useState(null); const [ currentTab, setCurrentTab ] = useState(TABS[0]); - const onRoomSettingsEvent = useCallback((event: RoomSettingsDataEvent) => + useMessageEvent(RoomSettingsDataEvent, event => { const parser = event.getParser(); @@ -61,9 +61,7 @@ export const NavigatorRoomSettingsView: FC<{}> = props => }); SendMessageComposer(new RoomBannedUsersComposer(data.roomId)); - }, []); - - useMessageEvent(RoomSettingsDataEvent, onRoomSettingsEvent); + }); const onClose = () => { diff --git a/src/components/toolbar/ToolbarView.tsx b/src/components/toolbar/ToolbarView.tsx index 5f8b2c53..4a67374b 100644 --- a/src/components/toolbar/ToolbarView.tsx +++ b/src/components/toolbar/ToolbarView.tsx @@ -17,15 +17,13 @@ export const ToolbarView: FC<{ isInRoom: boolean }> = props => const { requests = [] } = useFriends(); const { iconState = MessengerIconState.HIDDEN } = useMessenger(); const isMod = GetSessionDataManager().isModerator; - - const onPerkAllowancesMessageEvent = useCallback((event: PerkAllowancesMessageEvent) => + + useMessageEvent(PerkAllowancesMessageEvent, event => { const parser = event.getParser(); setUseGuideTool(parser.isAllowed(PerkEnum.USE_GUIDE_TOOL)); - }, [ setUseGuideTool ]); - - useMessageEvent(PerkAllowancesMessageEvent, onPerkAllowancesMessageEvent); + }); const animationIconToToolbar = useCallback((iconName: string, image: HTMLImageElement, x: number, y: number) => { @@ -61,12 +59,10 @@ export const ToolbarView: FC<{ isInRoom: boolean }> = props => Motions.runMotion(motion); }, []); - const onNitroToolbarAnimateIconEvent = useCallback((event: NitroToolbarAnimateIconEvent) => + useRoomEngineEvent(NitroToolbarAnimateIconEvent.ANIMATE_ICON, event => { animationIconToToolbar('icon-inventory', event.image, event.x, event.y); - }, [ animationIconToToolbar ]); - - useRoomEngineEvent(NitroToolbarAnimateIconEvent.ANIMATE_ICON, onNitroToolbarAnimateIconEvent); + }); return ( <> diff --git a/src/components/user-profile/UserProfileView.tsx b/src/components/user-profile/UserProfileView.tsx index 72f21a2e..59f426da 100644 --- a/src/components/user-profile/UserProfileView.tsx +++ b/src/components/user-profile/UserProfileView.tsx @@ -27,30 +27,26 @@ export const UserProfileView: FC<{}> = props => GetUserProfile(userProfile.id); }, [ userProfile ]); - - const onUserCurrentBadgesEvent = useCallback((event: UserCurrentBadgesEvent) => + + useMessageEvent(UserCurrentBadgesEvent, event => { const parser = event.getParser(); if(!userProfile || (parser.userId !== userProfile.id)) return; setUserBadges(parser.badges); - }, [ userProfile ]); + }); - useMessageEvent(UserCurrentBadgesEvent, onUserCurrentBadgesEvent); - - const onUserRelationshipsEvent = useCallback((event: RelationshipStatusInfoEvent) => + useMessageEvent(RelationshipStatusInfoEvent, event => { const parser = event.getParser(); if(!userProfile || (parser.userId !== userProfile.id)) return; setUserRelationships(parser); - }, [ userProfile ]); + }); - useMessageEvent(RelationshipStatusInfoEvent, onUserRelationshipsEvent); - - const onUserProfileEvent = useCallback((event: UserProfileEvent) => + useMessageEvent(UserProfileEvent, event => { const parser = event.getParser(); @@ -71,11 +67,9 @@ export const UserProfileView: FC<{}> = props => SendMessageComposer(new UserCurrentBadgesComposer(parser.id)); SendMessageComposer(new UserRelationshipsComposer(parser.id)); - }, []); + }); - useMessageEvent(UserProfileEvent, onUserProfileEvent); - - const onRoomEngineObjectEvent = useCallback((event: RoomEngineObjectEvent) => + useRoomEngineEvent(RoomEngineObjectEvent.SELECTED, event => { if(!userProfile) return; @@ -86,9 +80,7 @@ export const UserProfileView: FC<{}> = props => if(userData.type !== RoomObjectType.USER) return; GetUserProfile(userData.webID); - }, [ userProfile ]); - - useRoomEngineEvent(RoomEngineObjectEvent.SELECTED, onRoomEngineObjectEvent); + }); if(!userProfile) return null; diff --git a/src/components/user-profile/views/GroupsContainerView.tsx b/src/components/user-profile/views/GroupsContainerView.tsx index 94012593..bd598ee1 100644 --- a/src/components/user-profile/views/GroupsContainerView.tsx +++ b/src/components/user-profile/views/GroupsContainerView.tsx @@ -1,5 +1,5 @@ import { GroupInformationComposer, GroupInformationEvent, GroupInformationParser, HabboGroupEntryData } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useState } from 'react'; +import { FC, useEffect, useState } from 'react'; import { SendMessageComposer, ToggleFavoriteGroup } from '../../../api'; import { AutoGrid, Base, Column, Flex, Grid, GridProps, LayoutBadgeImageView, LayoutGridItem } from '../../../common'; import { useMessageEvent } from '../../../hooks'; @@ -18,16 +18,14 @@ export const GroupsContainerView: FC = props => const [ selectedGroupId, setSelectedGroupId ] = useState(null); const [ groupInformation, setGroupInformation ] = useState(null); - const onGroupInformationEvent = useCallback((event: GroupInformationEvent) => + useMessageEvent(GroupInformationEvent, event => { const parser = event.getParser(); if(!selectedGroupId || (selectedGroupId !== parser.id) || parser.flag) return; setGroupInformation(parser); - }, [ selectedGroupId ]); - - useMessageEvent(GroupInformationEvent, onGroupInformationEvent); + }); useEffect(() => { diff --git a/src/hooks/catalog/useCatalog.ts b/src/hooks/catalog/useCatalog.ts index 49e549c1..25d0d26d 100644 --- a/src/hooks/catalog/useCatalog.ts +++ b/src/hooks/catalog/useCatalog.ts @@ -416,7 +416,7 @@ const useCatalogState = () => }, []); - const onCatalogPagesListEvent = useCallback((event: CatalogPagesListEvent) => + useMessageEvent(CatalogPagesListEvent, event => { const parser = event.getParser(); const offers: Map = new Map(); @@ -440,11 +440,9 @@ const useCatalogState = () => setRootNode(getCatalogNode(parser.root, 0, null)); setOffersToNodes(offers); - }, [ setRootNode, setOffersToNodes ]); + }); - useMessageEvent(CatalogPagesListEvent, onCatalogPagesListEvent); - - const onCatalogPageMessageEvent = useCallback((event: CatalogPageMessageEvent) => + useMessageEvent(CatalogPageMessageEvent, event => { const parser = event.getParser(); @@ -479,47 +477,37 @@ const useCatalogState = () => { showCatalogPage(parser.pageId, parser.layoutCode, new PageLocalization(parser.localization.images.concat(), parser.localization.texts.concat()), purchasableOffers, parser.offerId, parser.acceptSeasonCurrencyAsCredits); } - }, [ currentType, pageId, setFrontPageItems, setIsBusy, showCatalogPage ]); + }); - useMessageEvent(CatalogPageMessageEvent, onCatalogPageMessageEvent); - - const onPurchaseOKMessageEvent = useCallback((event: PurchaseOKMessageEvent) => + useMessageEvent(PurchaseOKMessageEvent, event => { const parser = event.getParser(); DispatchUiEvent(new CatalogPurchasedEvent(parser.offer)); - }, []); + }); - useMessageEvent(PurchaseOKMessageEvent, onPurchaseOKMessageEvent); - - const onPurchaseErrorMessageEvent = useCallback((event: PurchaseErrorMessageEvent) => + useMessageEvent(PurchaseErrorMessageEvent, event => { const parser = event.getParser(); DispatchUiEvent(new CatalogPurchaseFailureEvent(parser.code)); - }, []); + }); - useMessageEvent(PurchaseErrorMessageEvent, onPurchaseErrorMessageEvent); - - const onPurchaseNotAllowedMessageEvent = useCallback((event: PurchaseNotAllowedMessageEvent) => + useMessageEvent(PurchaseNotAllowedMessageEvent, event => { const parser = event.getParser(); DispatchUiEvent(new CatalogPurchaseNotAllowedEvent(parser.code)); - }, []); + }); - useMessageEvent(PurchaseNotAllowedMessageEvent, onPurchaseNotAllowedMessageEvent); - - const onLimitedEditionSoldOutEvent = useCallback((event: LimitedEditionSoldOutEvent) => + useMessageEvent(LimitedEditionSoldOutEvent, event => { const parser = event.getParser(); DispatchUiEvent(new CatalogPurchaseSoldOutEvent()); - }, []); + }); - useMessageEvent(LimitedEditionSoldOutEvent, onLimitedEditionSoldOutEvent); - - const onProductOfferEvent = useCallback((event: ProductOfferEvent) => + useMessageEvent(ProductOfferEvent, event => { const parser = event.getParser(); const offerData = parser.offer; @@ -564,11 +552,9 @@ const useCatalogState = () => } // (this._isObjectMoverRequested) && (this._purchasableOffer) - }, [ currentType, currentPage, setCurrentOffer, setPurchaseOptions ]); + }); - useMessageEvent(ProductOfferEvent, onProductOfferEvent); - - const onSellablePetPalettesMessageEvent = useCallback((event: SellablePetPalettesMessageEvent) => + useMessageEvent(SellablePetPalettesMessageEvent, event => { const parser = event.getParser(); const petPalette = new CatalogPetPalette(parser.productCode, parser.palettes.slice()); @@ -595,11 +581,9 @@ const useCatalogState = () => return { ...prevValue, petPalettes }; }); - }, [ setCatalogOptions ]); + }); - useMessageEvent(SellablePetPalettesMessageEvent, onSellablePetPalettesMessageEvent); - - const onHabboClubOffersMessageEvent = useCallback((event: HabboClubOffersMessageEvent) => + useMessageEvent(HabboClubOffersMessageEvent, event => { const parser = event.getParser(); @@ -609,11 +593,9 @@ const useCatalogState = () => return { ...prevValue, clubOffers }; }); - }, [ setCatalogOptions ]); + }); - useMessageEvent(HabboClubOffersMessageEvent, onHabboClubOffersMessageEvent); - - const onGuildMembershipsMessageEvent = useCallback((event: GuildMembershipsMessageEvent) => + useMessageEvent(GuildMembershipsMessageEvent, event => { const parser = event.getParser(); @@ -623,11 +605,9 @@ const useCatalogState = () => return { ...prevValue, groups }; }); - }, [ setCatalogOptions ]); + }); - useMessageEvent(GuildMembershipsMessageEvent, onGuildMembershipsMessageEvent); - - const onGiftWrappingConfigurationEvent = useCallback((event: GiftWrappingConfigurationEvent) => + useMessageEvent(GiftWrappingConfigurationEvent, event => { const parser = event.getParser(); @@ -637,11 +617,9 @@ const useCatalogState = () => return { ...prevValue, giftConfiguration }; }); - }, [ setCatalogOptions ]); + }); - useMessageEvent(GiftWrappingConfigurationEvent, onGiftWrappingConfigurationEvent); - - const onMarketplaceMakeOfferResult = useCallback((event: MarketplaceMakeOfferResult) => + useMessageEvent(MarketplaceMakeOfferResult, event => { const parser = event.getParser(); @@ -660,11 +638,9 @@ const useCatalogState = () => const message = LocalizeText(`inventory.marketplace.result.${ parser.result }`); simpleAlert(message, NotificationAlertType.DEFAULT, null, null, title); - }, [ simpleAlert ]); + }); - useMessageEvent(MarketplaceMakeOfferResult, onMarketplaceMakeOfferResult); - - const onClubGiftInfoEvent = useCallback((event: ClubGiftInfoEvent) => + useMessageEvent(ClubGiftInfoEvent, event => { const parser = event.getParser(); @@ -674,33 +650,27 @@ const useCatalogState = () => return { ...prevValue, clubGifts }; }); - }, [ setCatalogOptions ]); + }); - useMessageEvent(ClubGiftInfoEvent, onClubGiftInfoEvent); - - const onCatalogPublishedMessageEvent = useCallback((event: CatalogPublishedMessageEvent) => + useMessageEvent(CatalogPublishedMessageEvent, event => { const wasVisible = isVisible; resetState(); if(wasVisible) simpleAlert(LocalizeText('catalog.alert.published.description'), NotificationAlertType.ALERT, null, null, LocalizeText('catalog.alert.published.title')); - }, [ isVisible, resetState, simpleAlert ]); + }); - useMessageEvent(CatalogPublishedMessageEvent, onCatalogPublishedMessageEvent); - - const onBuildersClubFurniCountMessageEvent = useCallback((event: BuildersClubFurniCountMessageEvent) => + useMessageEvent(BuildersClubFurniCountMessageEvent, event => { const parser = event.getParser(); setFurniCount(parser.furniCount); refreshBuilderStatus(); - }, [ refreshBuilderStatus ]); + }); - useMessageEvent(BuildersClubFurniCountMessageEvent, onBuildersClubFurniCountMessageEvent); - - const onBuildersClubSubscriptionStatusMessageEvent = useCallback((event: BuildersClubSubscriptionStatusMessageEvent) => + useMessageEvent(BuildersClubSubscriptionStatusMessageEvent, event => { const parser = event.getParser(); @@ -711,18 +681,11 @@ const useCatalogState = () => setSecondsLeftWithGrace(parser._Str_24379); refreshBuilderStatus(); - }, [ refreshBuilderStatus ]); + }); - useMessageEvent(BuildersClubSubscriptionStatusMessageEvent, onBuildersClubSubscriptionStatusMessageEvent); + useUiEvent(CatalogPurchasedEvent.PURCHASE_SUCCESS, event => PlaySound(SoundNames.CREDITS)); - const onCatalogPurchasedEvent = useCallback((event: CatalogPurchasedEvent) => - { - PlaySound(SoundNames.CREDITS); - }, []); - - useUiEvent(CatalogPurchasedEvent.PURCHASE_SUCCESS, onCatalogPurchasedEvent); - - const onRoomEngineObjectPlacedEvent = useCallback((event: RoomEngineObjectPlacedEvent) => + useRoomEngineEvent(RoomEngineObjectPlacedEvent.PLACED, event => { if(!objectMoverRequested || (event.type !== RoomEngineObjectPlacedEvent.PLACED)) return; @@ -830,11 +793,9 @@ const useCatalogState = () => break; } } - }, [ objectMoverRequested, purchasableOffer, catalogPlaceMultipleObjects, catalogSkipPurchaseConfirmation, currentType, pageId, resetPlacedOfferData, resetObjectMover, resetRoomPaint, requestOfferToMover ]); + }); - useRoomEngineEvent(RoomEngineObjectPlacedEvent.PLACED, onRoomEngineObjectPlacedEvent); - - const onInventoryFurniAddedEvent = useCallback((event: InventoryFurniAddedEvent) => + useUiEvent(InventoryFurniAddedEvent.FURNI_ADDED, event => { const roomEngine = GetRoomEngine(); @@ -865,9 +826,7 @@ const useCatalogState = () => } if(!catalogPlaceMultipleObjects) resetPlacedOfferData(); - }, [ placedObjectPurchaseData, catalogPlaceMultipleObjects, resetPlacedOfferData ]); - - useUiEvent(InventoryFurniAddedEvent.FURNI_ADDED, onInventoryFurniAddedEvent); + }); useEffect(() => {