fastapi-rtk
Version:
A React component library for FastAPI in combination with FastAPI React Toolkit backend, built with Mantine, JsonForms, and Zustand.
38 lines (37 loc) • 1.63 kB
JavaScript
import { jsx, Fragment } from "react/jsx-runtime";
import { DEBOUNCE_LOADING_DELAY } from "fastapi-rtk/constants";
import { useActionIcon } from "fastapi-rtk/hooks";
import { Tooltip, ActionIcon } from "@mantine/core";
import { useDebouncedState } from "@mantine/hooks";
import { memo } from "react";
import { useApi } from "../../hooks/api/useApi.mjs";
import { useForms } from "../../hooks/api/useForms.mjs";
import "../../Wrappers/Provider/Contexts/LangContext.mjs";
import { useTranslation } from "../../../../.external/esm/react-i18next@15.7.3_i18next@25.5.2_react-dom@18.3.1_react@18.3.1_typescript@5.9.2/react-i18next/dist/es/useTranslation.mjs";
import IconEye from "../../../../.external/esm/@tabler_icons-react@3.18.0_react@18.3.1/@tabler/icons-react/dist/esm/icons/IconEye.mjs";
const View = memo(({ id, ...props }) => {
const { getEntry } = useApi();
const { t } = useTranslation();
const { setOpened, setItem } = useForms("view");
const [loading, setLoading] = useDebouncedState(false, DEBOUNCE_LOADING_DELAY);
const actionIconProps = useActionIcon({
onClick: () => {
setLoading(true);
getEntry(id).then((entry) => {
if (entry) {
setItem(entry);
setOpened(true);
}
}).catch(() => {
}).finally(() => setLoading(false));
},
size: "sm",
loading,
...props
});
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(Tooltip, { label: t("View"), children: /* @__PURE__ */ jsx(ActionIcon, { ...actionIconProps, children: /* @__PURE__ */ jsx(IconEye, {}) }) }) });
});
View.displayName = "View";
export {
View
};