From a374d4d40fa8deb9ea5690b8a9df74374101cbe7 Mon Sep 17 00:00:00 2001 From: jialin Date: Thu, 9 Jan 2025 10:47:36 +0800 Subject: [PATCH] fix: body scrolls to top after opening a modal --- src/components/tags-wrapper/index.tsx | 2 +- src/global.less | 1 + src/pages/llmodels/catalog.tsx | 63 ++------------ .../llmodels/components/catalog-list.tsx | 87 +++++++++++++++++++ .../playground/components/ground-images.tsx | 2 +- .../playground/components/image-edit.tsx | 2 +- src/pages/playground/config/params-config.ts | 5 +- 7 files changed, 102 insertions(+), 60 deletions(-) create mode 100644 src/pages/llmodels/components/catalog-list.tsx diff --git a/src/components/tags-wrapper/index.tsx b/src/components/tags-wrapper/index.tsx index 6c31eb7b..7fdd93de 100644 --- a/src/components/tags-wrapper/index.tsx +++ b/src/components/tags-wrapper/index.tsx @@ -53,7 +53,7 @@ const TagsWrapper: React.FC = (props) => { const nodeWidth = sizeList[i]; if (totalWidth + moreButtonWidth.current >= wrapperWidth) { - end = i - 1; + end = i - 1 < 0 ? 0 : i - 1; break; } totalWidth += nodeWidth; diff --git a/src/global.less b/src/global.less index 4d20d6a8..7710942c 100644 --- a/src/global.less +++ b/src/global.less @@ -184,6 +184,7 @@ body { font-family: 'noto sans', sans-serif; -moz-osx-font-smoothing: grayscale; -webkit-font-smoothing: antialiased; + overflow-y: initial !important; &::-webkit-scrollbar { width: 0; diff --git a/src/pages/llmodels/catalog.tsx b/src/pages/llmodels/catalog.tsx index 3cbaf4e1..8ea2462c 100644 --- a/src/pages/llmodels/catalog.tsx +++ b/src/pages/llmodels/catalog.tsx @@ -4,23 +4,11 @@ import breakpoints from '@/config/breakpoints'; import { SyncOutlined } from '@ant-design/icons'; import { PageContainer } from '@ant-design/pro-components'; import { useIntl, useNavigate } from '@umijs/max'; -import { - Button, - Col, - Input, - Pagination, - Row, - Select, - Space, - Spin, - message -} from 'antd'; +import { Button, Input, Pagination, Select, Space, message } from 'antd'; import _ from 'lodash'; -import ResizeObserver from 'rc-resize-observer'; import React, { useCallback, useEffect, useState } from 'react'; import { createModel, queryCatalogList } from './apis'; -import CatalogItem from './components/catalog-item'; -import CatalogSkelton from './components/catalog-skelton'; +import CatalogList from './components/catalog-list'; import DelopyBuiltInModal from './components/deploy-builtin-modal'; import { modelCategories, modelSourceMap } from './config'; import { CatalogItem as CatalogItemType, FormData } from './config/types'; @@ -266,46 +254,13 @@ const Catalog: React.FC = () => { } > -
- - - {dataSource.dataList.map((item: CatalogItemType, index) => { - return ( - - - - ); - })} - - {dataSource.loading && ( -
- - {isFirst && } - -
- )} -
-
+
void; +} + +const CatalogList: React.FC = (props) => { + const { dataList, loading, activeId, isFirst, onDeploy } = props; + const [span, setSpan] = React.useState(8); + + const handleResize = useCallback( + _.throttle((size: { width: number; height: number }) => { + const { width } = size; + if (width < breakpoints.xs) { + setSpan(24); + } else if (width < breakpoints.sm) { + setSpan(24); + } else if (width < breakpoints.md) { + setSpan(12); + } else if (width < breakpoints.lg) { + setSpan(12); + } else { + setSpan(8); + } + }, 100), + [] + ); + + return ( +
+ +
+ + {dataList.map((item: CatalogItemType, index) => { + return ( + + + + ); + })} + + {loading && ( +
+ + {isFirst && } + +
+ )} +
+
+
+ ); +}; + +export default React.memo(CatalogList); diff --git a/src/pages/playground/components/ground-images.tsx b/src/pages/playground/components/ground-images.tsx index 03fef606..c73fab78 100644 --- a/src/pages/playground/components/ground-images.tsx +++ b/src/pages/playground/components/ground-images.tsx @@ -67,7 +67,7 @@ const advancedFieldsDefaultValus = { guidance: 3.5, sampling_steps: 10, negative_prompt: null, - schedule_method: 'default', + schedule_method: 'discrete', preview: null }; diff --git a/src/pages/playground/components/image-edit.tsx b/src/pages/playground/components/image-edit.tsx index 6ae911cc..3c3e2bbc 100644 --- a/src/pages/playground/components/image-edit.tsx +++ b/src/pages/playground/components/image-edit.tsx @@ -71,7 +71,7 @@ const advancedFieldsDefaultValus = { sampling_steps: 10, negative_prompt: null, preview: null, - schedule_method: 'default' + schedule_method: 'discrete' }; const openaiCompatibleFieldsDefaultValus = { diff --git a/src/pages/playground/config/params-config.ts b/src/pages/playground/config/params-config.ts index 1505157a..0df7b77c 100644 --- a/src/pages/playground/config/params-config.ts +++ b/src/pages/playground/config/params-config.ts @@ -15,8 +15,8 @@ export const imageSizeOptions: { height: 0 }, { label: '512x512', value: '512x512', width: 512, height: 512 }, - { label: '768x1024', value: '768x1024', width: 768, height: 1024 }, - { label: '1024x768', value: '1024x768', width: 1024, height: 768 }, + { label: '768x1024(3:4)', value: '768x1024', width: 768, height: 1024 }, + { label: '1024x768(4:3)', value: '1024x768', width: 1024, height: 768 }, { label: '1024x1024', value: '1024x1024', width: 1024, height: 1024 } ]; @@ -278,7 +278,6 @@ export const ImageAdvancedParamsConfig: ParamsSchema[] = [ type: 'Select', name: 'schedule_method', options: [ - { label: 'default', value: 'default' }, { label: 'discrete', value: 'discrete' }, { label: 'karras', value: 'karras' }, { label: 'exponential', value: 'exponential' },