Remove trending communities card from home. (#2639)

* Remove trending communities card from home.

- This proved after time to be pointless. I thought about keeping the
  create and explore communities buttons, but these are already in the
  navbar, and so just take up more pointless space.
- Fixes #2027
- Fixes #2007

* Forgot to remove trending loading skeleton.
This commit is contained in:
Dessalines 2024-07-29 11:10:21 -04:00 committed by GitHub
parent a5a696e54f
commit 72a3a3dbb9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 7 additions and 159 deletions

View file

@ -58,40 +58,6 @@ class PostsLoadingSkeletonItem extends Component<any, any> {
} }
} }
export class TrendingCommunitiesLoadingSkeleton extends Component<
LoadingSkeletonProps,
any
> {
render() {
return (
<div className="mb-2">
{Array.from({ length: this.props.itemCount ?? 10 }, (_, index) => (
<TrendingCommunitiesLoadingSkeletonItem key={index} />
))}
</div>
);
}
}
class TrendingCommunitiesLoadingSkeletonItem extends Component<any, any> {
render() {
return (
<div className="col flex-grow-1 mt-2 ps-2 pe-4">
<div className="row">
<div className="col flex-grow-0 pe-0">
<div className="d-flex placeholder-glow img-icon">
<span className="placeholder placeholder-lg w-100 h-100 rounded-circle" />
</div>
</div>
<div className="col flex-grow-1 pe-0">
<LoadingSkeletonLine size={12} />
</div>
</div>
</div>
);
}
}
export class CommentsLoadingSkeleton extends Component<any, any> { export class CommentsLoadingSkeleton extends Component<any, any> {
render() { render() {
return Array.from({ length: this.props.itemCount ?? 10 }, (_, index) => ( return Array.from({ length: this.props.itemCount ?? 10 }, (_, index) => (

View file

@ -18,10 +18,8 @@ import {
getQueryString, getQueryString,
getRandomFromList, getRandomFromList,
resourcesSettled, resourcesSettled,
bareRoutePush,
} from "@utils/helpers"; } from "@utils/helpers";
import { scrollMixin } from "../mixins/scroll-mixin"; import { scrollMixin } from "../mixins/scroll-mixin";
import { canCreateCommunity } from "@utils/roles";
import type { QueryParams, StringBoolean } from "@utils/types"; import type { QueryParams, StringBoolean } from "@utils/types";
import { RouteDataResponse } from "@utils/types"; import { RouteDataResponse } from "@utils/types";
import { NoOptionI18nKeys } from "i18next"; import { NoOptionI18nKeys } from "i18next";
@ -56,8 +54,6 @@ import {
GetSiteResponse, GetSiteResponse,
HidePost, HidePost,
LemmyHttp, LemmyHttp,
ListCommunities,
ListCommunitiesResponse,
ListingType, ListingType,
LockPost, LockPost,
MarkCommentReplyAsRead, MarkCommentReplyAsRead,
@ -75,7 +71,7 @@ import {
SuccessResponse, SuccessResponse,
TransferCommunity, TransferCommunity,
} from "lemmy-js-client"; } from "lemmy-js-client";
import { fetchLimit, relTags, trendingFetchLimit } from "../../config"; import { fetchLimit, relTags } from "../../config";
import { import {
CommentViewType, CommentViewType,
DataType, DataType,
@ -106,7 +102,6 @@ import { getHttpBaseInternal } from "../../utils/env";
import { import {
CommentsLoadingSkeleton, CommentsLoadingSkeleton,
PostsLoadingSkeleton, PostsLoadingSkeleton,
TrendingCommunitiesLoadingSkeleton,
} from "../common/loading-skeleton"; } from "../common/loading-skeleton";
import { RouteComponentProps } from "inferno-router/dist/Route"; import { RouteComponentProps } from "inferno-router/dist/Route";
import { IRoutePropsWithFetch } from "../../routes"; import { IRoutePropsWithFetch } from "../../routes";
@ -116,9 +111,7 @@ import { isBrowser, snapToTop } from "@utils/browser";
interface HomeState { interface HomeState {
postsRes: RequestState<GetPostsResponse>; postsRes: RequestState<GetPostsResponse>;
commentsRes: RequestState<GetCommentsResponse>; commentsRes: RequestState<GetCommentsResponse>;
trendingCommunitiesRes: RequestState<ListCommunitiesResponse>;
showSubscribedMobile: boolean; showSubscribedMobile: boolean;
showTrendingMobile: boolean;
showSidebarMobile: boolean; showSidebarMobile: boolean;
subscribedCollapsed: boolean; subscribedCollapsed: boolean;
tagline?: string; tagline?: string;
@ -137,7 +130,6 @@ interface HomeProps {
type HomeData = RouteDataResponse<{ type HomeData = RouteDataResponse<{
postsRes: GetPostsResponse; postsRes: GetPostsResponse;
commentsRes: GetCommentsResponse; commentsRes: GetCommentsResponse;
trendingCommunitiesRes: ListCommunitiesResponse;
}>; }>;
function getRss(listingType: ListingType, sort: SortType) { function getRss(listingType: ListingType, sort: SortType) {
@ -238,18 +230,6 @@ const MobileButton = ({
</button> </button>
); );
const LinkButton = ({
path,
translationKey,
}: {
path: string;
translationKey: NoOptionI18nKeys;
}) => (
<Link className="btn btn-secondary d-block" to={path}>
{I18NextService.i18n.t(translationKey)}
</Link>
);
type HomePathProps = Record<string, never>; type HomePathProps = Record<string, never>;
type HomeRouteProps = RouteComponentProps<HomePathProps> & HomeProps; type HomeRouteProps = RouteComponentProps<HomePathProps> & HomeProps;
export type HomeFetchConfig = IRoutePropsWithFetch< export type HomeFetchConfig = IRoutePropsWithFetch<
@ -265,10 +245,8 @@ export class Home extends Component<HomeRouteProps, HomeState> {
state: HomeState = { state: HomeState = {
postsRes: EMPTY_REQUEST, postsRes: EMPTY_REQUEST,
commentsRes: EMPTY_REQUEST, commentsRes: EMPTY_REQUEST,
trendingCommunitiesRes: EMPTY_REQUEST,
siteRes: this.isoData.site_res, siteRes: this.isoData.site_res,
showSubscribedMobile: false, showSubscribedMobile: false,
showTrendingMobile: false,
showSidebarMobile: false, showSidebarMobile: false,
subscribedCollapsed: false, subscribedCollapsed: false,
isIsomorphic: false, isIsomorphic: false,
@ -276,7 +254,6 @@ export class Home extends Component<HomeRouteProps, HomeState> {
loadingSettled(): boolean { loadingSettled(): boolean {
return resourcesSettled([ return resourcesSettled([
this.state.trendingCommunitiesRes,
this.props.dataType === DataType.Post this.props.dataType === DataType.Post
? this.state.postsRes ? this.state.postsRes
: this.state.commentsRes, : this.state.commentsRes,
@ -324,12 +301,10 @@ export class Home extends Component<HomeRouteProps, HomeState> {
// Only fetch the data if coming from another route // Only fetch the data if coming from another route
if (FirstLoadService.isFirstLoad) { if (FirstLoadService.isFirstLoad) {
const { trendingCommunitiesRes, commentsRes, postsRes } = const { commentsRes, postsRes } = this.isoData.routeData;
this.isoData.routeData;
this.state = { this.state = {
...this.state, ...this.state,
trendingCommunitiesRes,
commentsRes, commentsRes,
postsRes, postsRes,
isIsomorphic: true, isIsomorphic: true,
@ -349,10 +324,7 @@ export class Home extends Component<HomeRouteProps, HomeState> {
)) && )) &&
isBrowser() isBrowser()
) { ) {
await Promise.all([ await this.fetchData(this.props);
this.fetchTrendingCommunities(),
this.fetchData(this.props),
]);
} }
} }
@ -360,10 +332,6 @@ export class Home extends Component<HomeRouteProps, HomeState> {
nextProps: HomeRouteProps & { children?: InfernoNode }, nextProps: HomeRouteProps & { children?: InfernoNode },
) { ) {
this.fetchData(nextProps); this.fetchData(nextProps);
if (bareRoutePush(this.props, nextProps)) {
this.fetchTrendingCommunities();
}
} }
static async fetchInitialData({ static async fetchInitialData({
@ -401,24 +369,12 @@ export class Home extends Component<HomeRouteProps, HomeState> {
commentsFetch = client.getComments(getCommentsForm); commentsFetch = client.getComments(getCommentsForm);
} }
const trendingCommunitiesForm: ListCommunities = { const [postsRes, commentsRes] = await Promise.all([
type_: "Local",
sort: "Hot",
limit: trendingFetchLimit,
};
const trendingCommunitiesFetch = client.listCommunities(
trendingCommunitiesForm,
);
const [postsRes, commentsRes, trendingCommunitiesRes] = await Promise.all([
postsFetch, postsFetch,
commentsFetch, commentsFetch,
trendingCommunitiesFetch,
]); ]);
return { return {
trendingCommunitiesRes,
commentsRes, commentsRes,
postsRes, postsRes,
}; };
@ -481,7 +437,6 @@ export class Home extends Component<HomeRouteProps, HomeState> {
admins, admins,
}, },
showSubscribedMobile, showSubscribedMobile,
showTrendingMobile,
showSidebarMobile, showSidebarMobile,
} = this.state; } = this.state;
@ -495,11 +450,6 @@ export class Home extends Component<HomeRouteProps, HomeState> {
onClick={linkEvent(this, this.handleShowSubscribedMobile)} onClick={linkEvent(this, this.handleShowSubscribedMobile)}
/> />
)} )}
<MobileButton
textKey="trending"
show={showTrendingMobile}
onClick={linkEvent(this, this.handleShowTrendingMobile)}
/>
<MobileButton <MobileButton
textKey="sidebar" textKey="sidebar"
show={showSidebarMobile} show={showSidebarMobile}
@ -514,11 +464,6 @@ export class Home extends Component<HomeRouteProps, HomeState> {
isMobile={true} isMobile={true}
/> />
)} )}
{showTrendingMobile && (
<div className="card border-secondary mb-3">
{this.trendingCommunities()}
</div>
)}
{showSubscribedMobile && ( {showSubscribedMobile && (
<div className="card border-secondary mb-3"> <div className="card border-secondary mb-3">
{this.subscribedCommunities(true)} {this.subscribedCommunities(true)}
@ -539,9 +484,6 @@ export class Home extends Component<HomeRouteProps, HomeState> {
return ( return (
<div id="sidebarContainer"> <div id="sidebarContainer">
<section id="sidebarMain" className="card border-secondary mb-3">
{this.trendingCommunities()}
</section>
<SiteSidebar <SiteSidebar
site={site} site={site}
admins={admins} admins={admins}
@ -562,51 +504,6 @@ export class Home extends Component<HomeRouteProps, HomeState> {
); );
} }
trendingCommunities() {
switch (this.state.trendingCommunitiesRes?.state) {
case "loading":
return <TrendingCommunitiesLoadingSkeleton itemCount={5} />;
case "success": {
const trending = this.state.trendingCommunitiesRes.data.communities;
return (
<>
<header className="card-header d-flex align-items-center">
<h5 className="mb-0">
<T i18nKey="trending_communities">
#
<Link className="text-body" to="/communities">
#
</Link>
</T>
</h5>
</header>
<div className="card-body">
{trending.length > 0 && (
<ul className="list-inline">
{trending.map(cv => (
<li key={cv.community.id} className="list-inline-item">
<CommunityLink community={cv.community} />
</li>
))}
</ul>
)}
{canCreateCommunity(this.state.siteRes) && (
<LinkButton
path="/create_community"
translationKey="create_a_community"
/>
)}
<LinkButton
path="/communities"
translationKey="explore_communities"
/>
</div>
</>
);
}
}
}
subscribedCommunities(isMobile = false) { subscribedCommunities(isMobile = false) {
const { subscribedCollapsed } = this.state; const { subscribedCollapsed } = this.state;
@ -842,17 +739,6 @@ export class Home extends Component<HomeRouteProps, HomeState> {
); );
} }
async fetchTrendingCommunities() {
this.setState({ trendingCommunitiesRes: LOADING_REQUEST });
this.setState({
trendingCommunitiesRes: await HttpService.client.listCommunities({
type_: "Local",
sort: "Hot",
limit: trendingFetchLimit,
}),
});
}
fetchDataToken?: symbol; fetchDataToken?: symbol;
async fetchData({ async fetchData({
dataType, dataType,
@ -893,10 +779,6 @@ export class Home extends Component<HomeRouteProps, HomeState> {
i.setState({ showSubscribedMobile: !i.state.showSubscribedMobile }); i.setState({ showSubscribedMobile: !i.state.showSubscribedMobile });
} }
handleShowTrendingMobile(i: Home) {
i.setState({ showTrendingMobile: !i.state.showTrendingMobile });
}
handleShowSidebarMobile(i: Home) { handleShowSidebarMobile(i: Home) {
i.setState({ showSidebarMobile: !i.state.showSidebarMobile }); i.setState({ showSidebarMobile: !i.state.showSidebarMobile });
} }

View file

@ -27,7 +27,7 @@ import {
ghostArchiveUrl, ghostArchiveUrl,
postMarkdownFieldCharacterLimit, postMarkdownFieldCharacterLimit,
relTags, relTags,
trendingFetchLimit, similarPostFetchLimit,
webArchiveUrl, webArchiveUrl,
} from "../../config"; } from "../../config";
import { PostFormParams } from "../../interfaces"; import { PostFormParams } from "../../interfaces";
@ -825,7 +825,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
listing_type: "All", listing_type: "All",
community_id: this.state.form.community_id, community_id: this.state.form.community_id,
page: 1, page: 1,
limit: trendingFetchLimit, limit: similarPostFetchLimit,
}), }),
}); });
} }

View file

@ -16,7 +16,6 @@ export const webArchiveUrl = "https://web.archive.org";
export const elementUrl = "https://element.io"; export const elementUrl = "https://element.io";
export const postRefetchSeconds: number = 60 * 1000; export const postRefetchSeconds: number = 60 * 1000;
export const trendingFetchLimit = 6;
export const mentionDropdownFetchLimit = 10; export const mentionDropdownFetchLimit = 10;
export const commentTreeMaxDepth = 8; export const commentTreeMaxDepth = 8;
export const postMarkdownFieldCharacterLimit = 50000; export const postMarkdownFieldCharacterLimit = 50000;
@ -25,6 +24,7 @@ export const maxUploadImages = 20;
export const concurrentImageUpload = 4; export const concurrentImageUpload = 4;
export const updateUnreadCountsInterval = 30000; export const updateUnreadCountsInterval = 30000;
export const fetchLimit = 20; export const fetchLimit = 20;
export const similarPostFetchLimit = 6;
export const relTags = "noopener nofollow"; export const relTags = "noopener nofollow";
export const emDash = "\u2014"; export const emDash = "\u2014";
export const authCookieName = "jwt"; export const authCookieName = "jwt";