From 5815da5eaecd675af9e24d022e97b00f967ccb18 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Fri, 15 Aug 2025 18:25:41 +0200 Subject: [PATCH] Public Posts Results: Add loading state (#6121) --- .../left/search/PublicPostsResults.tsx | 13 +++-- .../PublicPostsSearchLauncher.module.scss | 1 + .../left/search/PublicPostsSearchLauncher.tsx | 48 ++++++++++++++++--- 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/components/left/search/PublicPostsResults.tsx b/src/components/left/search/PublicPostsResults.tsx index e6202cb52..e8a9ab751 100644 --- a/src/components/left/search/PublicPostsResults.tsx +++ b/src/components/left/search/PublicPostsResults.tsx @@ -31,6 +31,7 @@ type StateProps = { searchFlood?: ApiSearchPostsFlood; shouldShowSearchLauncher?: boolean; isNothingFound?: boolean; + isLoading?: boolean; }; const runThrottled = throttle((cb) => cb(), 500, true); @@ -42,6 +43,7 @@ const PublicPostsResults = ({ searchFlood, shouldShowSearchLauncher, isNothingFound, + isLoading, }: OwnProps & StateProps) => { const { searchMessagesGlobal } = getActions(); @@ -103,13 +105,14 @@ const PublicPostsResults = ({ return ( - {shouldShowSearchLauncher ? ( + {shouldShowSearchLauncher || isLoading ? ( ) : (
@@ -145,11 +148,12 @@ const PublicPostsResults = ({ export default memo(withGlobal( (global): StateProps => { const { messages: { byChatId: globalMessagesByChatId } } = global; - const { resultsByType, searchFlood } = selectTabState(global).globalSearch; + const { resultsByType, searchFlood, fetchingStatus } = selectTabState(global).globalSearch; const publicPostsResult = resultsByType?.publicPosts; const { foundIds } = publicPostsResult || {}; - const shouldShowSearchLauncher = !publicPostsResult; + const isLoading = Boolean(fetchingStatus?.publicPosts && !publicPostsResult); + const shouldShowSearchLauncher = !publicPostsResult && !isLoading; const isNothingFound = publicPostsResult && !foundIds?.length; return { @@ -158,6 +162,7 @@ export default memo(withGlobal( searchFlood, shouldShowSearchLauncher, isNothingFound, + isLoading, }; }, )(PublicPostsResults)); diff --git a/src/components/left/search/PublicPostsSearchLauncher.module.scss b/src/components/left/search/PublicPostsSearchLauncher.module.scss index 54db58b01..d2d784ec7 100644 --- a/src/components/left/search/PublicPostsSearchLauncher.module.scss +++ b/src/components/left/search/PublicPostsSearchLauncher.module.scss @@ -18,6 +18,7 @@ text-align: center; } +.loadingScreen, .searchButtonContent { display: flex; align-items: center; diff --git a/src/components/left/search/PublicPostsSearchLauncher.tsx b/src/components/left/search/PublicPostsSearchLauncher.tsx index 5da01b803..09489c97d 100644 --- a/src/components/left/search/PublicPostsSearchLauncher.tsx +++ b/src/components/left/search/PublicPostsSearchLauncher.tsx @@ -8,6 +8,7 @@ import { PUBLIC_POSTS_SEARCH_DEFAULT_TOTAL_DAILY, } from '../../../config'; import { selectIsCurrentUserPremium } from '../../../global/selectors'; +import buildClassName from '../../../util/buildClassName'; import { formatStarsAsIcon } from '../../../util/localization/format'; import { getServerTime } from '../../../util/serverTime'; import { LOCAL_TGS_PREVIEW_URLS, LOCAL_TGS_URLS } from '../../common/helpers/animatedAssets'; @@ -19,6 +20,7 @@ import useLastCallback from '../../../hooks/useLastCallback'; import AnimatedIconWithPreview from '../../common/AnimatedIconWithPreview'; import Icon from '../../common/icons/Icon'; import Button from '../../ui/Button'; +import Loading from '../../ui/Loading'; import TextTimer from '../../ui/TextTimer'; import Transition from '../../ui/Transition'; @@ -28,6 +30,7 @@ type OwnProps = { searchQuery?: string; searchFlood?: ApiSearchPostsFlood; onSearch: () => void; + isLoading?: boolean; }; type StateProps = { @@ -41,6 +44,7 @@ const PublicPostsSearchLauncher = ({ searchQuery, searchFlood, onSearch, + isLoading, isCurrentUserPremium, starsBalance, }: OwnProps & StateProps) => { @@ -213,20 +217,52 @@ const PublicPostsSearchLauncher = ({ ); }; - if (!isCurrentUserPremium) { - return renderPremiumRequired(); - } - const serverTime = getServerTime(); const shouldRenderPaidScreen = searchFlood?.remains === 0 || (searchFlood?.waitTill && searchFlood.waitTill > serverTime); + const renderLoading = () => { + return ( +
+
+ +
+
+ ); + }; + + const getActiveKey = () => { + if (!isCurrentUserPremium) { + return 3; + } + if (isLoading) { + return 2; + } + if (shouldRenderPaidScreen) { + return 0; + } + return 1; + }; + + const renderContent = () => { + if (!isCurrentUserPremium) { + return renderPremiumRequired(); + } + if (isLoading) { + return renderLoading(); + } + if (shouldRenderPaidScreen) { + return renderLimitReached(); + } + return renderSearchButton(); + }; + return ( - {shouldRenderPaidScreen ? renderLimitReached() : renderSearchButton()} + {renderContent()} ); };