Add clubgifts requirements & correct sorting (#119)

This commit is contained in:
Live 2023-01-14 06:45:37 +01:00 committed by GitHub
parent 340aeff64d
commit 9381b37e8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -1,5 +1,5 @@
import { SelectClubGiftComposer } from '@nitrots/nitro-renderer'; import { SelectClubGiftComposer } from '@nitrots/nitro-renderer';
import { FC, useCallback } from 'react'; import { FC, useCallback, useMemo } from 'react';
import { LocalizeText, SendMessageComposer } from '../../../../../../api'; import { LocalizeText, SendMessageComposer } from '../../../../../../api';
import { AutoGrid, Text } from '../../../../../../common'; import { AutoGrid, Text } from '../../../../../../common';
import { useCatalog, useNotification, usePurse } from '../../../../../../hooks'; import { useCatalog, useNotification, usePurse } from '../../../../../../hooks';
@ -41,11 +41,21 @@ export const CatalogLayoutVipGiftsView: FC<CatalogLayoutProps> = props =>
}, null); }, null);
}, [ setCatalogOptions, showConfirm ]); }, [ setCatalogOptions, showConfirm ]);
const sortGifts = useMemo(() =>
{
let gifts = clubGifts.offers.sort((a,b) =>
{
return clubGifts.getOfferExtraData(a.offerId).daysRequired - clubGifts.getOfferExtraData(b.offerId).daysRequired;
})
return gifts;
},[ clubGifts ]);
return ( return (
<> <>
<Text truncate shrink fontWeight="bold">{ giftsAvailable() }</Text> <Text truncate shrink fontWeight="bold">{ giftsAvailable() }</Text>
<AutoGrid columnCount={ 1 } className="nitro-catalog-layout-vip-gifts-grid"> <AutoGrid columnCount={ 1 } className="nitro-catalog-layout-vip-gifts-grid">
{ (clubGifts.offers.length > 0) && clubGifts.offers.map(offer => <VipGiftItem key={ offer.offerId } offer={ offer } isAvailable={ (clubGifts.getOfferExtraData(offer.offerId).isSelectable && (clubGifts.giftsAvailable > 0)) } onSelect={ selectGift }/>) } { (clubGifts.offers.length > 0) && sortGifts.map(offer => <VipGiftItem key={ offer.offerId } offer={ offer } isAvailable={ (clubGifts.getOfferExtraData(offer.offerId).isSelectable && (clubGifts.giftsAvailable > 0)) } onSelect={ selectGift } daysRequired={ clubGifts.getOfferExtraData(offer.offerId).daysRequired }/>) }
</AutoGrid> </AutoGrid>
</> </>
) )

View File

@ -7,12 +7,13 @@ export interface VipGiftItemViewProps
{ {
offer: CatalogPageMessageOfferData; offer: CatalogPageMessageOfferData;
isAvailable: boolean; isAvailable: boolean;
daysRequired: number;
onSelect(localizationId: string): void; onSelect(localizationId: string): void;
} }
export const VipGiftItem : FC<VipGiftItemViewProps> = props => export const VipGiftItem : FC<VipGiftItemViewProps> = props =>
{ {
const { offer = null, isAvailable = false, onSelect = null } = props; const { offer = null, isAvailable = false, daysRequired = 0, onSelect = null } = props;
const getImageUrlForOffer = useCallback( () => const getImageUrlForOffer = useCallback( () =>
{ {
@ -45,6 +46,11 @@ export const VipGiftItem : FC<VipGiftItemViewProps> = props =>
return LocalizeText(localizationKey); return LocalizeText(localizationKey);
}, [ offer ]); }, [ offer ]);
const getMonthsRequired = useCallback(() =>
{
return Math.floor(daysRequired / 31);
},[ daysRequired ]);
return ( return (
<LayoutGridItem center={ false } column={ false } alignItems="center" className="p-1"> <LayoutGridItem center={ false } column={ false } alignItems="center" className="p-1">
<LayoutImage imageUrl={ getImageUrlForOffer() } /> <LayoutImage imageUrl={ getImageUrlForOffer() } />