WbwFactorsEditor.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { useState } from "react";
  2. import { LoadingOutlined, WarningOutlined } from "@ant-design/icons";
  3. import WbwFactors from "./WbwFactors";
  4. import type { IWbw, TWbwDisplayMode } from "./WbwWord";
  5. import type { IPreferenceResponse } from "../../../api/Dict";
  6. import { Space } from "antd";
  7. interface IWidget {
  8. initValue: IWbw;
  9. display?: TWbwDisplayMode;
  10. onChange?: (key: string) => Promise<IPreferenceResponse>;
  11. }
  12. const WbwFactorsEditor = ({ initValue, display, onChange }: IWidget) => {
  13. const [loading, setLoading] = useState(false);
  14. const [error, setError] = useState(false);
  15. return (
  16. <Space>
  17. {loading ? <LoadingOutlined /> : error ? <WarningOutlined /> : <></>}
  18. <WbwFactors
  19. key="factors"
  20. data={initValue}
  21. display={display}
  22. onChange={async (e: string) => {
  23. console.log("factor change", e);
  24. if (onChange) {
  25. setLoading(true);
  26. setError(false);
  27. const response = await onChange(e);
  28. setLoading(false);
  29. if (!response.ok) {
  30. setError(true);
  31. }
  32. }
  33. }}
  34. />
  35. </Space>
  36. );
  37. };
  38. export default WbwFactorsEditor;