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 { FC, useCallback } from 'react';
import { FC, useCallback, useMemo } from 'react';
import { LocalizeText, SendMessageComposer } from '../../../../../../api';
import { AutoGrid, Text } from '../../../../../../common';
import { useCatalog, useNotification, usePurse } from '../../../../../../hooks';
@ -41,11 +41,21 @@ export const CatalogLayoutVipGiftsView: FC<CatalogLayoutProps> = props =>
}, null);
}, [ 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 (
<>
<Text truncate shrink fontWeight="bold">{ giftsAvailable() }</Text>
<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>
</>
)

View File

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