mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-23 14:40:50 +01:00
Add subscription to purse
This commit is contained in:
parent
7780eb6592
commit
5ca61ece5e
@ -1,4 +1,4 @@
|
||||
import { UserCreditsEvent, UserCurrencyEvent, UserCurrencyUpdateEvent } from 'nitro-renderer';
|
||||
import { UserCreditsEvent, UserCurrencyEvent, UserCurrencyUpdateEvent, UserSubscriptionEvent } from 'nitro-renderer';
|
||||
import { FC, useCallback } from 'react';
|
||||
import { CreateMessageHook } from '../../hooks/messages/message-event';
|
||||
import { Currency } from './common/Currency';
|
||||
@ -48,9 +48,27 @@ export const PurseMessageHandler: FC<PurseMessageHandlerProps> = props =>
|
||||
});
|
||||
}, [ dispatchPurseState ]);
|
||||
|
||||
const onUserSubscriptionEvent = useCallback((event: UserSubscriptionEvent) =>
|
||||
{
|
||||
const parser = event.getParser();
|
||||
|
||||
switch(parser.name)
|
||||
{
|
||||
case 'habbo_club':
|
||||
dispatchPurseState({
|
||||
type: PurseActions.SET_CLUB_SUBSCRIPTION,
|
||||
payload: {
|
||||
clubSubscription: parser
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
}, [ dispatchPurseState ]);
|
||||
|
||||
CreateMessageHook(UserCreditsEvent, onUserCreditsEvent);
|
||||
CreateMessageHook(UserCurrencyEvent, onUserCurrencyEvent);
|
||||
CreateMessageHook(UserCurrencyUpdateEvent, onUserCurrencyUpdateEvent);
|
||||
CreateMessageHook(UserSubscriptionEvent, onUserSubscriptionEvent);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
import { UserSubscriptionParser } from 'nitro-renderer';
|
||||
import { Reducer } from 'react';
|
||||
import { Currency } from '../common/Currency';
|
||||
|
||||
export interface IPurseState
|
||||
{
|
||||
currencies: Currency[];
|
||||
clubSubscription: UserSubscriptionParser;
|
||||
}
|
||||
|
||||
export interface IPurseAction
|
||||
@ -12,6 +14,7 @@ export interface IPurseAction
|
||||
payload: {
|
||||
currency?: Currency;
|
||||
currencies?: Currency[];
|
||||
clubSubscription?: UserSubscriptionParser;
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,10 +22,12 @@ export class PurseActions
|
||||
{
|
||||
public static SET_CURRENCY: string = 'PA_SET_CURRENCY';
|
||||
public static SET_CURRENCIES: string = 'PA_SET_CURRENCIES';
|
||||
public static SET_CLUB_SUBSCRIPTION: string = 'PA_SET_CLUB_SUBSCRIPTION';
|
||||
}
|
||||
|
||||
export const initialPurse: IPurseState = {
|
||||
currencies: []
|
||||
currencies: [],
|
||||
clubSubscription: null
|
||||
}
|
||||
|
||||
export const PurseReducer: Reducer<IPurseState, IPurseAction> = (state, action) =>
|
||||
@ -34,7 +39,7 @@ export const PurseReducer: Reducer<IPurseState, IPurseAction> = (state, action)
|
||||
|
||||
let didSet = false;
|
||||
|
||||
const currencies = state.currencies.map((existing, index) =>
|
||||
const currencies = state.currencies.map(existing =>
|
||||
{
|
||||
if(existing.type !== updated.type) return existing;
|
||||
|
||||
@ -50,7 +55,7 @@ export const PurseReducer: Reducer<IPurseState, IPurseAction> = (state, action)
|
||||
case PurseActions.SET_CURRENCIES: {
|
||||
const updated = action.payload.currencies;
|
||||
|
||||
const currencies = state.currencies.filter((existing, index) =>
|
||||
const currencies = state.currencies.filter(existing =>
|
||||
{
|
||||
if(existing.type !== -1) return null;
|
||||
|
||||
@ -61,6 +66,11 @@ export const PurseReducer: Reducer<IPurseState, IPurseAction> = (state, action)
|
||||
|
||||
return { ...state, currencies };
|
||||
}
|
||||
case PurseActions.SET_CLUB_SUBSCRIPTION: {
|
||||
const clubSubscription = action.payload.clubSubscription;
|
||||
|
||||
return { ...state, clubSubscription };
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user