mirror of
https://github.com/gethomepage/homepage.git
synced 2026-01-10 10:32:09 +08:00
Feature: Filebrowser service widget (#5546)
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
38
src/widgets/filebrowser/component.jsx
Normal file
38
src/widgets/filebrowser/component.jsx
Normal file
@@ -0,0 +1,38 @@
|
||||
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 default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { widget } = service;
|
||||
|
||||
const { data: usage, error: usageError } = useWidgetAPI(widget, "usage");
|
||||
|
||||
if (usageError) {
|
||||
return <Container service={service} error={usageError} />;
|
||||
}
|
||||
|
||||
if (!usage) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="filebrowser.available" />
|
||||
<Block label="filebrowser.used" />
|
||||
<Block label="filebrowser.total" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block
|
||||
label="filebrowser.available"
|
||||
value={t("common.bytes", { value: (usage?.total ?? 0) - (usage?.used ?? 0) })}
|
||||
/>
|
||||
<Block label="filebrowser.used" value={t("common.bytes", { value: usage?.used ?? 0 })} />
|
||||
<Block label="filebrowser.total" value={t("common.bytes", { value: usage?.total ?? 0 })} />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user