mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-19 19:19:50 +00:00
widget refactoring and cleanup
This commit is contained in:
parent
808e79e2ac
commit
47bc073fb4
39 changed files with 92 additions and 1410 deletions
36
src/widgets/mastodon/component.jsx
Normal file
36
src/widgets/mastodon/component.jsx
Normal file
|
@ -0,0 +1,36 @@
|
|||
import useSWR from "swr";
|
||||
import { useTranslation } from "next-i18next";
|
||||
|
||||
import Widget from "components/services/widgets/widget";
|
||||
import Block from "components/services/widgets/block";
|
||||
import { formatProxyUrl } from "utils/api-helpers";
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const config = service.widget;
|
||||
|
||||
const { data: statsData, error: statsError } = useSWR(formatProxyUrl(config, `instance`));
|
||||
|
||||
if (statsError) {
|
||||
return <Widget error={t("widget.api_error")} />;
|
||||
}
|
||||
|
||||
if (!statsData) {
|
||||
return (
|
||||
<Widget>
|
||||
<Block label={t("mastodon.user_count")} />
|
||||
<Block label={t("mastodon.status_count")} />
|
||||
<Block label={t("mastodon.domain_count")} />
|
||||
</Widget>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Widget>
|
||||
<Block label={t("mastodon.user_count")} value={t("common.number", { value: statsData.stats.user_count })} />
|
||||
<Block label={t("mastodon.status_count")} value={t("common.number", { value: statsData.stats.status_count })} />
|
||||
<Block label={t("mastodon.domain_count")} value={t("common.number", { value: statsData.stats.domain_count })} />
|
||||
</Widget>
|
||||
);
|
||||
}
|
14
src/widgets/mastodon/widget.js
Normal file
14
src/widgets/mastodon/widget.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
import genericProxyHandler from "utils/proxies/generic";
|
||||
|
||||
const widget = {
|
||||
api: "{url}/api/v1/{endpoint}",
|
||||
proxyHandler: genericProxyHandler,
|
||||
|
||||
mappings: {
|
||||
instance: {
|
||||
endpoint: "instance",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default widget;
|
Loading…
Add table
Add a link
Reference in a new issue