sd-new.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import homeStyles from "@/app/components/home.module.scss";
  2. import { IconButton } from "@/app/components/button";
  3. import GithubIcon from "@/app/icons/github.svg";
  4. import ReturnIcon from "@/app/icons/return.svg";
  5. import Locale from "@/app/locales";
  6. import HistoryIcon from "@/app/icons/history.svg";
  7. import { Path, REPO_URL } from "@/app/constant";
  8. import { useNavigate } from "react-router-dom";
  9. import dynamic from "next/dynamic";
  10. import {
  11. SideBarContainer,
  12. SideBarBody,
  13. SideBarTail,
  14. useDragSideBar,
  15. useHotKey,
  16. } from "@/app/components/sidebar";
  17. import { getParams, getModelParamBasicData } from "./sd-panel";
  18. import { useSdStore } from "@/app/store/sd";
  19. import { showToast } from "@/app/components/ui-lib";
  20. const SdPanel = dynamic(
  21. async () => (await import("@/app/components/sd")).SdPanel,
  22. {
  23. loading: () => null,
  24. },
  25. );
  26. export function SdNew() {
  27. useHotKey();
  28. const { onDragStart, shouldNarrow } = useDragSideBar();
  29. const navigate = useNavigate();
  30. const sdStore = useSdStore();
  31. const currentModel = sdStore.currentModel;
  32. const params = sdStore.currentParams;
  33. const setParams = sdStore.setCurrentParams;
  34. const handleSubmit = () => {
  35. const columns = getParams?.(currentModel, params);
  36. const reqParams: any = {};
  37. for (let i = 0; i < columns.length; i++) {
  38. const item = columns[i];
  39. reqParams[item.value] = params[item.value] ?? null;
  40. if (item.required) {
  41. if (!reqParams[item.value]) {
  42. showToast(Locale.SdPanel.ParamIsRequired(item.name));
  43. return;
  44. }
  45. }
  46. }
  47. let data: any = {
  48. model: currentModel.value,
  49. model_name: currentModel.name,
  50. status: "wait",
  51. params: reqParams,
  52. created_at: new Date().toLocaleString(),
  53. img_data: "",
  54. };
  55. sdStore.sendTask(data, () => {
  56. setParams(getModelParamBasicData(columns, params, true));
  57. navigate(Path.Sd);
  58. });
  59. };
  60. return (
  61. <SideBarContainer
  62. onDragStart={onDragStart}
  63. shouldNarrow={shouldNarrow}
  64. className={homeStyles["sidebar-show"]}
  65. >
  66. <div
  67. className="window-header"
  68. data-tauri-drag-region
  69. style={{
  70. paddingLeft: 0,
  71. paddingRight: 0,
  72. }}
  73. >
  74. {
  75. <div className="window-actions">
  76. <div className="window-action-button">
  77. <IconButton
  78. icon={<ReturnIcon />}
  79. bordered
  80. title={Locale.Sd.Actions.ReturnHome}
  81. onClick={() => navigate(Path.Home)}
  82. />
  83. </div>
  84. </div>
  85. }
  86. <div className={`window-header-title`}>
  87. <div className={`window-header-main-title`}>Stability</div>
  88. </div>
  89. <div className="window-actions">
  90. <div className="window-action-button">
  91. <IconButton
  92. icon={<HistoryIcon />}
  93. bordered
  94. title={Locale.Sd.Actions.History}
  95. onClick={() => navigate(Path.Sd)}
  96. />
  97. </div>
  98. </div>
  99. </div>
  100. <SideBarBody>
  101. <SdPanel />
  102. </SideBarBody>
  103. <SideBarTail
  104. primaryAction={
  105. <a href={REPO_URL} target="_blank" rel="noopener noreferrer">
  106. <IconButton icon={<GithubIcon />} shadow />
  107. </a>
  108. }
  109. secondaryAction={
  110. <IconButton
  111. text={Locale.SdPanel.Submit}
  112. type="primary"
  113. shadow
  114. onClick={handleSubmit}
  115. ></IconButton>
  116. }
  117. />
  118. </SideBarContainer>
  119. );
  120. }