From: Jay Sitter Date: Sat, 17 Jun 2023 00:35:44 +0000 (-0400) Subject: Merge remote-tracking branch 'origin/main' into feat/add-badges-common-component X-Git-Url: http://these/git/?a=commitdiff_plain;h=8bbb6c9652bbbfda1ca9cc41592c413549f16c75;hp=1242d8d426cf258c1679efd7494811357a87232a;p=lemmy-ui.git Merge remote-tracking branch 'origin/main' into feat/add-badges-common-component * origin/main: handle login failures correctly wrap login call in try/catch for error handling Remove extra div in post sidebar Add a class to the more button on a comment node Switch navbar classes to ids Adding a few more 0.18.0 API changes. (#1324) Use aside semantic HTML tag for sidebars Use article semantic HTML tag for posts/comments Use footer semantic HTML tag Adding codeowners. Add lemmy-site class for easier detection Add ID's and classes to sidebars Add clases and ID's to post form/listing Add classes to post and comment repy textareas Rename markdown-textarea ID's Add nav and footer ID's --- diff --git a/src/shared/components/common/badges.tsx b/src/shared/components/common/badges.tsx new file mode 100644 index 0000000..4427895 --- /dev/null +++ b/src/shared/components/common/badges.tsx @@ -0,0 +1,106 @@ +import { Link } from "inferno-router"; +import { + CommunityAggregates, + CommunityView, + SiteAggregates, +} from "lemmy-js-client"; +import { i18n } from "../../i18next"; +import { numToSI } from "../../utils"; + +interface BadgesProps { + counts: CommunityAggregates | SiteAggregates; + community_view?: CommunityView; +} + +const isCommunityAggregates = ( + counts: CommunityAggregates | SiteAggregates +): counts is CommunityAggregates => { + return "subscribers" in counts; +}; + +export const Badges = ({ counts, community_view }: BadgesProps) => { + return ( + + ); +}; diff --git a/src/shared/components/community/sidebar.tsx b/src/shared/components/community/sidebar.tsx index f4c7452..711ab5e 100644 --- a/src/shared/components/community/sidebar.tsx +++ b/src/shared/components/community/sidebar.tsx @@ -24,8 +24,8 @@ import { hostname, mdToHtml, myAuthRequired, - numToSI, } from "../../utils"; +import { Badges } from "../common/badges"; import { BannerIconHeader } from "../common/banner-icon-header"; import { Icon, PurgeWarning, Spinner } from "../common/icon"; import { CommunityForm } from "../community/community-form"; @@ -158,7 +158,10 @@ export class Sidebar extends Component {
{this.description()} - {this.badges()} + {this.mods()}
@@ -233,93 +236,6 @@ export class Sidebar extends Component { ); } - badges() { - const community_view = this.props.community_view; - const counts = community_view.counts; - return ( -
    -
  • - {i18n.t("number_of_users", { - count: Number(counts.users_active_day), - formattedCount: numToSI(counts.users_active_day), - })}{" "} - / {i18n.t("day")} -
  • -
  • - {i18n.t("number_of_users", { - count: Number(counts.users_active_week), - formattedCount: numToSI(counts.users_active_week), - })}{" "} - / {i18n.t("week")} -
  • -
  • - {i18n.t("number_of_users", { - count: Number(counts.users_active_month), - formattedCount: numToSI(counts.users_active_month), - })}{" "} - / {i18n.t("month")} -
  • -
  • - {i18n.t("number_of_users", { - count: Number(counts.users_active_half_year), - formattedCount: numToSI(counts.users_active_half_year), - })}{" "} - / {i18n.t("number_of_months", { count: 6, formattedCount: 6 })} -
  • -
  • - {i18n.t("number_of_subscribers", { - count: Number(counts.subscribers), - formattedCount: numToSI(counts.subscribers), - })} -
  • -
  • - {i18n.t("number_of_posts", { - count: Number(counts.posts), - formattedCount: numToSI(counts.posts), - })} -
  • -
  • - {i18n.t("number_of_comments", { - count: Number(counts.comments), - formattedCount: numToSI(counts.comments), - })} -
  • -
  • - - {i18n.t("modlog")} - -
  • -
- ); - } - mods() { return (
    diff --git a/src/shared/components/home/site-sidebar.tsx b/src/shared/components/home/site-sidebar.tsx index 8603c36..66a48ca 100644 --- a/src/shared/components/home/site-sidebar.tsx +++ b/src/shared/components/home/site-sidebar.tsx @@ -1,8 +1,8 @@ import { Component, linkEvent } from "inferno"; -import { Link } from "inferno-router"; import { PersonView, Site, SiteAggregates } from "lemmy-js-client"; import { i18n } from "../../i18next"; -import { mdToHtml, numToSI } from "../../utils"; +import { mdToHtml } from "../../utils"; +import { Badges } from "../common/badges"; import { BannerIconHeader } from "../common/banner-icon-header"; import { Icon } from "../common/icon"; import { PersonListing } from "../person/person-listing"; @@ -71,7 +71,7 @@ export class SiteSidebar extends Component {
    {site.description &&
    {site.description}
    } {site.sidebar && this.siteSidebar(site.sidebar)} - {this.props.counts && this.badges(this.props.counts)} + {this.props.counts && } {this.props.admins && this.admins(this.props.admins)}
    ); @@ -96,95 +96,6 @@ export class SiteSidebar extends Component { ); } - badges(siteAggregates: SiteAggregates) { - const counts = siteAggregates; - return ( -
      -
    • - {i18n.t("number_of_users", { - count: Number(counts.users_active_day), - formattedCount: numToSI(counts.users_active_day), - })}{" "} - / {i18n.t("day")} -
    • -
    • - {i18n.t("number_of_users", { - count: Number(counts.users_active_week), - formattedCount: numToSI(counts.users_active_week), - })}{" "} - / {i18n.t("week")} -
    • -
    • - {i18n.t("number_of_users", { - count: Number(counts.users_active_month), - formattedCount: numToSI(counts.users_active_month), - })}{" "} - / {i18n.t("month")} -
    • -
    • - {i18n.t("number_of_users", { - count: Number(counts.users_active_half_year), - formattedCount: numToSI(counts.users_active_half_year), - })}{" "} - / {i18n.t("number_of_months", { count: 6, formattedCount: 6 })} -
    • -
    • - {i18n.t("number_of_users", { - count: Number(counts.users), - formattedCount: numToSI(counts.users), - })} -
    • -
    • - {i18n.t("number_of_communities", { - count: Number(counts.communities), - formattedCount: numToSI(counts.communities), - })} -
    • -
    • - {i18n.t("number_of_posts", { - count: Number(counts.posts), - formattedCount: numToSI(counts.posts), - })} -
    • -
    • - {i18n.t("number_of_comments", { - count: Number(counts.comments), - formattedCount: numToSI(counts.comments), - })} -
    • -
    • - - {i18n.t("modlog")} - -
    • -
    - ); - } - handleCollapseSidebar(i: SiteSidebar) { i.setState({ collapsed: !i.state.collapsed }); }