Skip to content

Commit

Permalink
Merge branch 'develop' into premium-subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-luger committed Nov 7, 2024
2 parents aa3cd72 + b9ea3f3 commit e24121b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion components/ItemFilter/ItemFilterPropertiesDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface Props {
isEditable?: boolean
}

const DATE_FORMAT_FILTER = ['EndBefore', 'EndAfter']
const DATE_FORMAT_FILTER = ['EndBefore', 'EndAfter', 'ItemCreatedBefore', 'ItemCreatedAfter']
const SELLER_FORMAT_FILTER = 'Seller'

function ItemFilterPropertiesDisplay(props: Props) {
Expand Down
25 changes: 17 additions & 8 deletions components/Premium/PremiumStatus/PremiumStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,48 @@ interface Props {

function PremiumStatus(props: Props) {
let [highestPriorityProduct, setHighestPriorityProduct] = useState<PremiumProduct>()
let [productsToShow, setProductsToShow] = useState<PremiumProduct[]>()
let [productsToShow, setProductsToShow] = useState<PremiumProductWithtimeDifference[]>()
let [showCancelSubscriptionDialogSubscription, setShowCancelSubscriptionDialogSubscription] = useState<PremiumSubscription>()

useEffect(() => {
let products = props.products
let products = props.products.map(product => {
return {
...product,
timeDifference: 0
};
}).sort((a, b) => getPremiumType(b)?.priority - getPremiumType(a)?.priority);

// Hide lower tier products that are most likely bought automatically together (<1min time difference)
if (products.length > 1) {
for (let i = 1; i < products.length; i++) {
if (Math.abs(products[i - 1].expires.getTime() - products[i].expires.getTime()) < 60000) {
const diff = Math.abs(products[i - 1].expires.getTime() - products[i].expires.getTime());
if (diff < 60000) {
if (getPremiumType(products[i - 1])?.priority > getPremiumType(products[i])?.priority) {
products.splice(i, 1)
} else {
products.splice(i - 1, 1)
}
i = 0
}
} else
products[i].timeDifference = diff
}
}
console.log(products)

products = products.filter(product => product.expires > new Date())
setProductsToShow(products)
setHighestPriorityProduct(getHighestPriorityPremiumProduct(props.products))
}, [props.products])

function getProductListEntry(product: PremiumProduct) {
function getProductListEntry(product: PremiumProductWithtimeDifference) {
return (
<>
<span>{getPremiumType(product)?.label}</span>
<Tooltip
type="hover"
content={<span> (ends {moment(product.expires).fromNow()})</span>}
tooltipContent={<span>{getLocalDateAndTime(product.expires)}</span>}
content={<span> (ends {moment(product.expires).fromNow()}{
product.timeDifference > 0 ? (<>, <span className={styles.timeDifference}>{moment.duration(product.timeDifference).humanize()}</span> after</>) : null})</span>}
tooltipContent={<span>At {getLocalDateAndTime(product.expires)}</span>}
/>
</>
)
Expand Down Expand Up @@ -116,7 +125,7 @@ function PremiumStatus(props: Props) {
<span className={styles.premiumStatusLabel} style={props.labelStyle}>
Premium Status:
</span>
{highestPriorityProduct ? getProductListEntry(highestPriorityProduct!) : 'No Premium'}
{highestPriorityProduct ? getProductListEntry({...highestPriorityProduct} as PremiumProductWithtimeDifference) : 'No Premium'}
</p>
)}
</div>
Expand Down
4 changes: 4 additions & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,10 @@ interface PremiumProduct {
productSlug: string
}

interface PremiumProductWithtimeDifference extends PremiumProduct {
timeDifference: number
}

interface PremiumTypeOption {
value: number
label: string
Expand Down

0 comments on commit e24121b

Please sign in to comment.