From 86ddd5bf0b00eef47fd026a5c9d14734547edbc8 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Wed, 12 Jun 2024 18:11:18 +0200 Subject: [PATCH] Management: Fix layout in management boost list (#4645) --- .../common/PremiumProgress.module.scss | 10 +-- src/components/common/PremiumProgress.tsx | 50 ++++++++++++--- .../statistics/BoostStatistics.module.scss | 7 +- .../right/statistics/BoostStatistics.tsx | 64 +++++++++++-------- 4 files changed, 89 insertions(+), 42 deletions(-) diff --git a/src/components/common/PremiumProgress.module.scss b/src/components/common/PremiumProgress.module.scss index e7fd92e4b..dd7e0af50 100644 --- a/src/components/common/PremiumProgress.module.scss +++ b/src/components/common/PremiumProgress.module.scss @@ -12,17 +12,13 @@ } .badgeContainer { - --min-shift: calc(10% + var(--digits-count, 1) * 0.4ch); - --max-shift: calc(85% - var(--digits-count, 1) * 0.4ch); - --shift-x: calc(clamp(var(--min-shift), var(--percent), var(--max-shift)) - 50%); display: flex; justify-content: center; position: absolute; top: -1.5rem; left: 0; right: 0; - transform: translate(var(--shift-x), -20px); - + transform: translate(calc(var(--shift-x) * 100% - 50%), -20px); transition: transform 0.2s ease-in-out; animation: slide-in 0.5s ease-in-out; } @@ -33,7 +29,7 @@ } to { - transform: translate(var(--shift-x), -20px); + transform: translate(calc(var(--shift-x) * 100% - 50%), -20px); } } @@ -75,7 +71,7 @@ .floating-badge-triangle { display: inline-block; position: absolute; - bottom: -5px; + bottom: -4px; left: calc(var(--tail-position, 0.5) * 100%); transform: translateX(-50%); } diff --git a/src/components/common/PremiumProgress.tsx b/src/components/common/PremiumProgress.tsx index c1264dee5..02da139e9 100644 --- a/src/components/common/PremiumProgress.tsx +++ b/src/components/common/PremiumProgress.tsx @@ -1,5 +1,7 @@ import type { FC } from '../../lib/teact/teact'; -import React, { memo } from '../../lib/teact/teact'; +import React, { + memo, useEffect, useRef, useState, +} from '../../lib/teact/teact'; import type { IconName } from '../../types/icons'; @@ -7,6 +9,7 @@ import buildClassName from '../../util/buildClassName'; import buildStyle from '../../util/buildStyle'; import useLang from '../../hooks/useLang'; +import useResizeObserver from '../../hooks/useResizeObserver'; import Icon from './Icon'; @@ -21,8 +24,6 @@ type OwnProps = { className?: string; }; -const PROGRESS_LOCK = 0.1; - const LimitPreview: FC = ({ leftText, rightText, @@ -32,15 +33,48 @@ const LimitPreview: FC = ({ className, }) => { const lang = useLang(); + // eslint-disable-next-line no-null/no-null + const floatingBadgeRef = useRef(null); + // eslint-disable-next-line no-null/no-null + const parentContainerRef = useRef(null); + + const [shiftX, setShiftX] = useState(0); + const [tailPosition, setTailPosition] = useState(0); + + const updateBadgePosition = () => { + if (floatingBadgeRef.current && parentContainerRef.current && progress !== undefined) { + const badgeWidth = floatingBadgeRef.current.offsetWidth; + const parentWidth = parentContainerRef.current.offsetWidth; + const minShift = badgeWidth / 2; + const maxShift = parentWidth - badgeWidth / 2; + const currentShift = progress * parentWidth; + const safeShift = Math.max(minShift, Math.min(currentShift, maxShift)); + + setShiftX(safeShift / parentWidth); + + let newTailPosition; + if (currentShift < minShift) { + newTailPosition = (progress * parentWidth) / (minShift * 2); + } else if (currentShift > maxShift) { + const progressMapped = (progress - (maxShift / parentWidth)) / (1 - maxShift / parentWidth); + newTailPosition = 0.5 + (progressMapped * 0.4); + } else { + newTailPosition = 0.5; + } + setTailPosition(newTailPosition); + } + }; + + useEffect(updateBadgePosition, [progress]); + + useResizeObserver(parentContainerRef, updateBadgePosition); const hasFloatingBadge = Boolean(floatingBadgeIcon || floatingBadgeText); const isProgressFull = Boolean(progress) && progress > 0.99; - const digitsCount = floatingBadgeText?.length; - - const tailPosition = progress && (progress < PROGRESS_LOCK ? 0 : progress > 1 - PROGRESS_LOCK ? 1 : 0.5); return (
= ({ style={buildStyle( progress !== undefined && `--progress: ${progress}`, tailPosition !== undefined && `--tail-position: ${tailPosition}`, - digitsCount !== undefined && `--digits-count: ${digitsCount}`, + `--shift-x: ${shiftX}`, )} > {hasFloatingBadge && (
-
+
{floatingBadgeIcon && } {floatingBadgeText && (
diff --git a/src/components/right/statistics/BoostStatistics.module.scss b/src/components/right/statistics/BoostStatistics.module.scss index 1a9a451ff..5f6bfac0d 100644 --- a/src/components/right/statistics/BoostStatistics.module.scss +++ b/src/components/right/statistics/BoostStatistics.module.scss @@ -44,7 +44,7 @@ .status { display: flex; align-items: center; - gap: 1rem; + gap: 0.5rem; justify-content: space-between; width: 100%; } @@ -111,3 +111,8 @@ .giveawayButton { margin-bottom: 0.5rem; } + +.giveawayIcon { + width: 2.75rem; + height: 2.75rem; +} diff --git a/src/components/right/statistics/BoostStatistics.tsx b/src/components/right/statistics/BoostStatistics.tsx index 818266a9f..606504d75 100644 --- a/src/components/right/statistics/BoostStatistics.tsx +++ b/src/components/right/statistics/BoostStatistics.tsx @@ -177,7 +177,7 @@ const BoostStatistics = ({ >
{lang(boost.isFromGiveaway - ? 'lng_prizes_results_link' : 'BoostingGift')} + ? 'BoostingGiveaway' : 'BoostingGift')}
@@ -218,11 +218,13 @@ const BoostStatistics = ({ ); }); - const handleGiveawayClick = useLastCallback(() => { + const handleGiveawayClick = useLastCallback((e) => { + e.preventDefault(); openGiveawayModal({ chatId }); }); - const handleLoadMore = useLastCallback(() => { + const handleLoadMore = useLastCallback((e) => { + e.preventDefault(); loadMoreBoosters({ isGifts: tabType === 'giftedBoostList' }); }); @@ -243,7 +245,7 @@ const BoostStatistics = ({ } return ( -
+
{listToRender?.map((boost) => renderBoostList(boost))}
); @@ -278,7 +280,11 @@ const BoostStatistics = ({ >
- Giveaway + {lang('Giveaway')}

@@ -303,13 +309,12 @@ const BoostStatistics = ({

{lang('BoostingSelectPaidGiveaway')}

)} -
+
{shouldDisplayGiftList ? (
) : ( - <> +

{lang('BoostingBoostsCount', boostStatistics?.boosts?.count)}

@@ -331,28 +336,35 @@ const BoostStatistics = ({
)} {boostStatistics?.boosts?.list?.map((boost) => renderBoostList(boost))} - - )} - {Boolean(boostersToLoadCount) && ( - - {boostStatistics?.isLoadingBoosters ? ( - - ) : ( - - )} - {lang('ShowVotes', boostersToLoadCount, 'i')} - +
)} +
+ {Boolean(boostersToLoadCount) && ( + + {boostStatistics?.isLoadingBoosters ? ( + + ) : ( + + )} + {lang('ShowVotes', boostersToLoadCount, 'i')} + + )} +
{isGiveawayAvailable && (
- + {lang('BoostingGetBoostsViaGifts')}

{lang(