2023-06-21 22:28:24 +00:00
|
|
|
import { numToSI } from "@utils/helpers";
|
2023-06-16 22:31:47 +00:00
|
|
|
import { Link } from "inferno-router";
|
|
|
|
import {
|
|
|
|
CommunityAggregates,
|
2023-06-17 02:24:32 +00:00
|
|
|
CommunityId,
|
2023-06-16 22:31:47 +00:00
|
|
|
SiteAggregates,
|
|
|
|
} from "lemmy-js-client";
|
2023-06-22 00:54:35 +00:00
|
|
|
import { I18NextService } from "../../services";
|
2023-06-16 22:31:47 +00:00
|
|
|
|
|
|
|
interface BadgesProps {
|
|
|
|
counts: CommunityAggregates | SiteAggregates;
|
2023-06-17 02:24:32 +00:00
|
|
|
communityId?: CommunityId;
|
2023-06-16 22:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const isCommunityAggregates = (
|
|
|
|
counts: CommunityAggregates | SiteAggregates
|
|
|
|
): counts is CommunityAggregates => {
|
|
|
|
return "subscribers" in counts;
|
|
|
|
};
|
|
|
|
|
2023-06-17 00:56:01 +00:00
|
|
|
const isSiteAggregates = (
|
|
|
|
counts: CommunityAggregates | SiteAggregates
|
|
|
|
): counts is SiteAggregates => {
|
|
|
|
return "communities" in counts;
|
|
|
|
};
|
|
|
|
|
2023-06-17 02:24:32 +00:00
|
|
|
export const Badges = ({ counts, communityId }: BadgesProps) => {
|
2023-06-16 22:31:47 +00:00
|
|
|
return (
|
2023-06-20 18:46:16 +00:00
|
|
|
<ul className="badges my-1 list-inline">
|
2023-06-16 22:31:47 +00:00
|
|
|
<li
|
2023-06-20 12:01:29 +00:00
|
|
|
className="list-inline-item badge text-bg-secondary pointer"
|
2023-06-22 00:54:35 +00:00
|
|
|
data-tippy-content={I18NextService.i18n.t(
|
|
|
|
"active_users_in_the_last_day",
|
|
|
|
{
|
|
|
|
count: Number(counts.users_active_day),
|
|
|
|
formattedCount: numToSI(counts.users_active_day),
|
|
|
|
}
|
|
|
|
)}
|
2023-06-16 22:31:47 +00:00
|
|
|
>
|
2023-06-22 00:54:35 +00:00
|
|
|
{I18NextService.i18n.t("number_of_users", {
|
2023-06-16 22:31:47 +00:00
|
|
|
count: Number(counts.users_active_day),
|
|
|
|
formattedCount: numToSI(counts.users_active_day),
|
|
|
|
})}{" "}
|
2023-06-22 00:54:35 +00:00
|
|
|
/ {I18NextService.i18n.t("day")}
|
2023-06-16 22:31:47 +00:00
|
|
|
</li>
|
|
|
|
<li
|
2023-06-20 12:01:29 +00:00
|
|
|
className="list-inline-item badge text-bg-secondary pointer"
|
2023-06-22 00:54:35 +00:00
|
|
|
data-tippy-content={I18NextService.i18n.t(
|
|
|
|
"active_users_in_the_last_week",
|
|
|
|
{
|
|
|
|
count: Number(counts.users_active_week),
|
|
|
|
formattedCount: numToSI(counts.users_active_week),
|
|
|
|
}
|
|
|
|
)}
|
2023-06-16 22:31:47 +00:00
|
|
|
>
|
2023-06-22 00:54:35 +00:00
|
|
|
{I18NextService.i18n.t("number_of_users", {
|
2023-06-16 22:31:47 +00:00
|
|
|
count: Number(counts.users_active_week),
|
|
|
|
formattedCount: numToSI(counts.users_active_week),
|
|
|
|
})}{" "}
|
2023-06-22 00:54:35 +00:00
|
|
|
/ {I18NextService.i18n.t("week")}
|
2023-06-16 22:31:47 +00:00
|
|
|
</li>
|
|
|
|
<li
|
2023-06-20 12:01:29 +00:00
|
|
|
className="list-inline-item badge text-bg-secondary pointer"
|
2023-06-22 00:54:35 +00:00
|
|
|
data-tippy-content={I18NextService.i18n.t(
|
|
|
|
"active_users_in_the_last_month",
|
|
|
|
{
|
|
|
|
count: Number(counts.users_active_month),
|
|
|
|
formattedCount: numToSI(counts.users_active_month),
|
|
|
|
}
|
|
|
|
)}
|
2023-06-16 22:31:47 +00:00
|
|
|
>
|
2023-06-22 00:54:35 +00:00
|
|
|
{I18NextService.i18n.t("number_of_users", {
|
2023-06-16 22:31:47 +00:00
|
|
|
count: Number(counts.users_active_month),
|
|
|
|
formattedCount: numToSI(counts.users_active_month),
|
|
|
|
})}{" "}
|
2023-06-22 00:54:35 +00:00
|
|
|
/ {I18NextService.i18n.t("month")}
|
2023-06-16 22:31:47 +00:00
|
|
|
</li>
|
|
|
|
<li
|
2023-06-20 12:01:29 +00:00
|
|
|
className="list-inline-item badge text-bg-secondary pointer"
|
2023-06-22 00:54:35 +00:00
|
|
|
data-tippy-content={I18NextService.i18n.t(
|
|
|
|
"active_users_in_the_last_six_months",
|
|
|
|
{
|
|
|
|
count: Number(counts.users_active_half_year),
|
|
|
|
formattedCount: numToSI(counts.users_active_half_year),
|
|
|
|
}
|
|
|
|
)}
|
2023-06-16 22:31:47 +00:00
|
|
|
>
|
2023-06-22 00:54:35 +00:00
|
|
|
{I18NextService.i18n.t("number_of_users", {
|
2023-06-16 22:31:47 +00:00
|
|
|
count: Number(counts.users_active_half_year),
|
|
|
|
formattedCount: numToSI(counts.users_active_half_year),
|
|
|
|
})}{" "}
|
2023-06-22 00:54:35 +00:00
|
|
|
/{" "}
|
|
|
|
{I18NextService.i18n.t("number_of_months", {
|
|
|
|
count: 6,
|
|
|
|
formattedCount: 6,
|
|
|
|
})}
|
2023-06-16 22:31:47 +00:00
|
|
|
</li>
|
2023-06-17 01:44:45 +00:00
|
|
|
{isSiteAggregates(counts) && (
|
|
|
|
<>
|
2023-06-20 12:01:29 +00:00
|
|
|
<li className="list-inline-item badge text-bg-secondary">
|
2023-06-22 00:54:35 +00:00
|
|
|
{I18NextService.i18n.t("number_of_users", {
|
2023-06-17 01:44:45 +00:00
|
|
|
count: Number(counts.users),
|
|
|
|
formattedCount: numToSI(counts.users),
|
|
|
|
})}
|
|
|
|
</li>
|
2023-06-20 12:01:29 +00:00
|
|
|
<li className="list-inline-item badge text-bg-secondary">
|
2023-06-22 00:54:35 +00:00
|
|
|
{I18NextService.i18n.t("number_of_communities", {
|
2023-06-17 01:44:45 +00:00
|
|
|
count: Number(counts.communities),
|
|
|
|
formattedCount: numToSI(counts.communities),
|
|
|
|
})}
|
|
|
|
</li>
|
|
|
|
</>
|
|
|
|
)}
|
2023-06-16 22:31:47 +00:00
|
|
|
{isCommunityAggregates(counts) && (
|
2023-06-20 12:01:29 +00:00
|
|
|
<li className="list-inline-item badge text-bg-secondary">
|
2023-06-22 00:54:35 +00:00
|
|
|
{I18NextService.i18n.t("number_of_subscribers", {
|
2023-06-16 22:31:47 +00:00
|
|
|
count: Number(counts.subscribers),
|
|
|
|
formattedCount: numToSI(counts.subscribers),
|
|
|
|
})}
|
|
|
|
</li>
|
|
|
|
)}
|
2023-06-20 12:01:29 +00:00
|
|
|
<li className="list-inline-item badge text-bg-secondary">
|
2023-06-22 00:54:35 +00:00
|
|
|
{I18NextService.i18n.t("number_of_posts", {
|
2023-06-16 22:31:47 +00:00
|
|
|
count: Number(counts.posts),
|
|
|
|
formattedCount: numToSI(counts.posts),
|
|
|
|
})}
|
|
|
|
</li>
|
2023-06-20 12:01:29 +00:00
|
|
|
<li className="list-inline-item badge text-bg-secondary">
|
2023-06-22 00:54:35 +00:00
|
|
|
{I18NextService.i18n.t("number_of_comments", {
|
2023-06-16 22:31:47 +00:00
|
|
|
count: Number(counts.comments),
|
|
|
|
formattedCount: numToSI(counts.comments),
|
|
|
|
})}
|
|
|
|
</li>
|
|
|
|
<li className="list-inline-item">
|
|
|
|
<Link
|
2023-06-20 12:01:29 +00:00
|
|
|
className="badge text-bg-primary"
|
2023-06-17 02:24:32 +00:00
|
|
|
to={`/modlog${communityId ? `/${communityId}` : ""}`}
|
2023-06-16 22:31:47 +00:00
|
|
|
>
|
2023-06-22 00:54:35 +00:00
|
|
|
{I18NextService.i18n.t("modlog")}
|
2023-06-16 22:31:47 +00:00
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
);
|
|
|
|
};
|