mirror of
https://github.com/gethomepage/homepage.git
synced 2026-01-12 20:12:09 +08:00
Chore: change hoarder widget to karakeep (#5143)
Some checks failed
Crowdin Action / Crowdin Sync (push) Has been cancelled
Docker CI / Linting Checks (push) Has been cancelled
Docker CI / Docker Build & Push (push) Has been cancelled
Repository Maintenance / Stale (push) Has been cancelled
Repository Maintenance / Lock Old Threads (push) Has been cancelled
Repository Maintenance / Close Answered Discussions (push) Has been cancelled
Repository Maintenance / Close Outdated Discussions (push) Has been cancelled
Repository Maintenance / Close Unsupported Feature Requests (push) Has been cancelled
Some checks failed
Crowdin Action / Crowdin Sync (push) Has been cancelled
Docker CI / Linting Checks (push) Has been cancelled
Docker CI / Docker Build & Push (push) Has been cancelled
Repository Maintenance / Stale (push) Has been cancelled
Repository Maintenance / Lock Old Threads (push) Has been cancelled
Repository Maintenance / Close Answered Discussions (push) Has been cancelled
Repository Maintenance / Close Outdated Discussions (push) Has been cancelled
Repository Maintenance / Close Unsupported Feature Requests (push) Has been cancelled
This commit is contained in:
49
src/widgets/karakeep/component.jsx
Normal file
49
src/widgets/karakeep/component.jsx
Normal file
@@ -0,0 +1,49 @@
|
||||
import Block from "components/services/widget/block";
|
||||
import Container from "components/services/widget/container";
|
||||
import { useTranslation } from "next-i18next";
|
||||
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
export const karakeepDefaultFields = ["bookmarks", "favorites", "archived", "highlights"];
|
||||
const MAX_ALLOWED_FIELDS = 4;
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
const { widget } = service;
|
||||
|
||||
const { data: statsData, error: statsError } = useWidgetAPI(widget, "stats");
|
||||
|
||||
if (statsError) {
|
||||
return <Container service={service} error={statsError} />;
|
||||
}
|
||||
|
||||
if (!widget.fields || widget.fields.length === 0) {
|
||||
widget.fields = karakeepDefaultFields;
|
||||
} else if (widget.fields?.length > MAX_ALLOWED_FIELDS) {
|
||||
widget.fields = widget.fields.slice(0, MAX_ALLOWED_FIELDS);
|
||||
}
|
||||
|
||||
if (!statsData) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="karakeep.bookmarks" />
|
||||
<Block label="karakeep.favorites" />
|
||||
<Block label="karakeep.archived" />
|
||||
<Block label="karakeep.highlights" />
|
||||
<Block label="karakeep.lists" />
|
||||
<Block label="karakeep.tags" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="karakeep.bookmarks" value={t("common.number", { value: statsData.numBookmarks })} />
|
||||
<Block label="karakeep.favorites" value={t("common.number", { value: statsData.numFavorites })} />
|
||||
<Block label="karakeep.archived" value={t("common.number", { value: statsData.numArchived })} />
|
||||
<Block label="karakeep.highlights" value={t("common.number", { value: statsData.numHighlights })} />
|
||||
<Block label="karakeep.lists" value={t("common.number", { value: statsData.numLists })} />
|
||||
<Block label="karakeep.tags" value={t("common.number", { value: statsData.numTags })} />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
14
src/widgets/karakeep/widget.js
Normal file
14
src/widgets/karakeep/widget.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
||||
|
||||
const widget = {
|
||||
api: `{url}/api/v1/{endpoint}`,
|
||||
proxyHandler: credentialedProxyHandler,
|
||||
|
||||
mappings: {
|
||||
stats: {
|
||||
endpoint: "users/me/stats",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default widget;
|
||||
Reference in New Issue
Block a user