Spaces:
Sleeping
Sleeping
Upload index.tsx
Browse files
aworld/cmd/web/webui/src/pages/components/Welcome/index.tsx
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { useState } from 'react';
|
| 2 |
+
import { Input, Button, Typography, Row, Col, Select, Flex } from 'antd';
|
| 3 |
+
import { ArrowUpOutlined, RightOutlined } from '@ant-design/icons';
|
| 4 |
+
import './index.less';
|
| 5 |
+
|
| 6 |
+
const { Title } = Typography;
|
| 7 |
+
|
| 8 |
+
interface WelcomeProps {
|
| 9 |
+
onSubmit: (value: string) => void;
|
| 10 |
+
models: Array<{ label: string; value: string }>;
|
| 11 |
+
selectedModel: string;
|
| 12 |
+
onModelChange: (value: string) => void;
|
| 13 |
+
modelsLoading: boolean;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
const Welcome: React.FC<WelcomeProps> = ({
|
| 17 |
+
onSubmit,
|
| 18 |
+
models,
|
| 19 |
+
selectedModel,
|
| 20 |
+
onModelChange,
|
| 21 |
+
modelsLoading,
|
| 22 |
+
}) => {
|
| 23 |
+
const [inputValue, setInputValue] = useState('');
|
| 24 |
+
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
| 25 |
+
if (e.key === 'Enter' && !e.shiftKey) {
|
| 26 |
+
e.preventDefault();
|
| 27 |
+
if (inputValue.trim()) onSubmit(inputValue);
|
| 28 |
+
}
|
| 29 |
+
};
|
| 30 |
+
|
| 31 |
+
return (
|
| 32 |
+
<div className="welcome-container">
|
| 33 |
+
<div className="content">
|
| 34 |
+
<Row justify="center">
|
| 35 |
+
<Col>
|
| 36 |
+
<Title level={1}>Hello Aworld</Title>
|
| 37 |
+
</Col>
|
| 38 |
+
</Row>
|
| 39 |
+
<div className="input-area">
|
| 40 |
+
<Input.TextArea
|
| 41 |
+
value={inputValue}
|
| 42 |
+
onChange={(e) => setInputValue(e.target.value)}
|
| 43 |
+
onKeyDown={handleKeyDown}
|
| 44 |
+
placeholder="Ask or input / use skills"
|
| 45 |
+
autoSize={{ minRows: 3, maxRows: 5 }}
|
| 46 |
+
className="text-input"
|
| 47 |
+
/>
|
| 48 |
+
<Button
|
| 49 |
+
type="primary"
|
| 50 |
+
shape="circle"
|
| 51 |
+
onClick={() => {
|
| 52 |
+
if (inputValue.trim()) onSubmit(inputValue);
|
| 53 |
+
}}
|
| 54 |
+
icon={<ArrowUpOutlined />}
|
| 55 |
+
className="submit-button"
|
| 56 |
+
disabled={inputValue.trim() === ''}
|
| 57 |
+
/>
|
| 58 |
+
</div>
|
| 59 |
+
<div className="controls-area">
|
| 60 |
+
<Select
|
| 61 |
+
value={selectedModel}
|
| 62 |
+
onChange={onModelChange}
|
| 63 |
+
options={models}
|
| 64 |
+
loading={modelsLoading}
|
| 65 |
+
placeholder="Select a model"
|
| 66 |
+
className="model-select"
|
| 67 |
+
showSearch
|
| 68 |
+
filterOption={(input, option) =>
|
| 69 |
+
(option?.label ?? '').toLowerCase().includes(input.toLowerCase())
|
| 70 |
+
}
|
| 71 |
+
optionRender={(option) => (
|
| 72 |
+
<div className="select-item">
|
| 73 |
+
<Flex justify="space-between">
|
| 74 |
+
<div>
|
| 75 |
+
<strong>{option.label}</strong>
|
| 76 |
+
<small>{option.value}</small>
|
| 77 |
+
</div>
|
| 78 |
+
<RightOutlined className="icon-right" />
|
| 79 |
+
</Flex>
|
| 80 |
+
</div>
|
| 81 |
+
)}
|
| 82 |
+
/>
|
| 83 |
+
</div>
|
| 84 |
+
</div>
|
| 85 |
+
</div>
|
| 86 |
+
);
|
| 87 |
+
};
|
| 88 |
+
|
| 89 |
+
export default Welcome;
|