Skip to content

Commit

Permalink
💄 style: improve input file upload (lobehub#3314)
Browse files Browse the repository at this point in the history
* 💄 style: improve input height

* 💄 style: improve input height

* fix drag
  • Loading branch information
arvinxx authored Jul 26, 2024
1 parent 1b86e01 commit de85553
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 71 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,17 @@ import { memo, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Center, Flexbox } from 'react-layout-kit';

import DragUpload from '@/components/DragUpload';
import StopLoadingIcon from '@/components/StopLoading';
import SaveTopic from '@/features/ChatInput/Topic';
import { useSendMessage } from '@/features/ChatInput/useSend';
import { useAgentStore } from '@/store/agent';
import { agentSelectors } from '@/store/agent/slices/chat';
import { useChatStore } from '@/store/chat';
import { chatSelectors, topicSelectors } from '@/store/chat/selectors';
import { filesSelectors, useFileStore } from '@/store/file';
import { useUserStore } from '@/store/user';
import { modelProviderSelectors, preferenceSelectors } from '@/store/user/selectors';
import { preferenceSelectors } from '@/store/user/selectors';
import { isMacOS } from '@/utils/platform';

import { LocalFiles } from './LocalFiles';
import LocalFiles from '../LocalFiles';
import SendMore from './SendMore';

const useStyles = createStyles(({ css, prefixCls, token }) => {
Expand Down Expand Up @@ -51,10 +48,11 @@ const useStyles = createStyles(({ css, prefixCls, token }) => {
});

interface FooterProps {
expand: boolean;
setExpand?: (expand: boolean) => void;
}

const Footer = memo<FooterProps>(({ setExpand }) => {
const Footer = memo<FooterProps>(({ setExpand, expand }) => {
const { t } = useTranslation('chat');

const { theme, styles } = useStyles();
Expand All @@ -75,28 +73,7 @@ const Footer = memo<FooterProps>(({ setExpand }) => {

const isImageUploading = useFileStore(filesSelectors.isImageUploading);

const model = useAgentStore(agentSelectors.currentAgentModel);

const enabledFiles = useUserStore(modelProviderSelectors.isModelEnabledFiles(model));

const [useCmdEnterToSend, canUpload] = useUserStore((s) => [
preferenceSelectors.useCmdEnterToSend(s),
modelProviderSelectors.isModelEnabledUpload(model)(s),
]);

const uploadFile = useFileStore((s) => s.uploadFile);

const uploadImages = async (fileList: FileList | undefined) => {
if (!fileList || fileList.length === 0) return;

const pools = Array.from(fileList).map(async (file) => {
// skip none-file items
if (!file.type.startsWith('image') && !enabledFiles) return;
await uploadFile(file);
});

await Promise.all(pools);
};
const [useCmdEnterToSend] = useUserStore((s) => [preferenceSelectors.useCmdEnterToSend(s)]);

const sendMessage = useSendMessage();

Expand Down Expand Up @@ -142,12 +119,7 @@ const Footer = memo<FooterProps>(({ setExpand }) => {
padding={'0 24px'}
>
<Flexbox align={'center'} gap={8} horizontal style={{ overflow: 'hidden' }}>
{canUpload && (
<>
<DragUpload enabledFiles={enabledFiles} onUploadFiles={uploadImages} />
<LocalFiles />
</>
)}
{expand && <LocalFiles />}
</Flexbox>
<Flexbox align={'center'} flex={'none'} gap={8} horizontal>
<Flexbox
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { memo } from 'react';

import DragUpload from '@/components/DragUpload';
import { EditableFileList } from '@/features/FileList';
import { useAgentStore } from '@/store/agent';
import { agentSelectors } from '@/store/agent/slices/chat';
import { useFileStore } from '@/store/file';
import { useUserStore } from '@/store/user';
import { modelProviderSelectors } from '@/store/user/selectors';

interface LocalFilesProps {
padding?: number | string;
}

const LocalFiles = memo<LocalFilesProps>(({ padding }) => {
const model = useAgentStore(agentSelectors.currentAgentModel);

const enabledFiles = useUserStore(modelProviderSelectors.isModelEnabledFiles(model));
const canUpload = useUserStore(modelProviderSelectors.isModelEnabledUpload(model));

const inputFilesList = useFileStore((s) => s.inputFilesList);
const uploadFile = useFileStore((s) => s.uploadFile);

const uploadImages = async (fileList: FileList | undefined) => {
if (!fileList || fileList.length === 0) return;

const pools = Array.from(fileList).map(async (file) => {
// skip none-file items
if (!file.type.startsWith('image') && !enabledFiles) return;
await uploadFile(file);
});

await Promise.all(pools);
};

return (
canUpload && (
<>
<DragUpload enabledFiles={enabledFiles} onUploadFiles={uploadImages} />
<EditableFileList items={inputFilesList} padding={padding ?? 0} />
</>
)
);
});

export default LocalFiles;
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { systemStatusSelectors } from '@/store/global/selectors';

import Footer from './Footer';
import Head from './Header';
import LocalFiles from './LocalFiles';
import TextArea from './TextArea';

const DesktopChatInput = memo(() => {
Expand All @@ -25,33 +26,37 @@ const DesktopChatInput = memo(() => {
]);

return (
<DraggablePanel
fullscreen={expand}
headerHeight={HEADER_HEIGHT}
maxHeight={CHAT_TEXTAREA_MAX_HEIGHT}
minHeight={CHAT_TEXTAREA_HEIGHT}
onSizeChange={(_, size) => {
if (!size) return;

updatePreference({
inputHeight: typeof size.height === 'string' ? Number.parseInt(size.height) : size.height,
});
}}
placement="bottom"
size={{ height: inputHeight, width: '100%' }}
style={{ zIndex: 10 }}
>
<Flexbox
gap={8}
height={'100%'}
padding={'12px 0 16px'}
style={{ minHeight: CHAT_TEXTAREA_HEIGHT, position: 'relative' }}
<>
{!expand && <LocalFiles padding={'8px 16px'} />}
<DraggablePanel
fullscreen={expand}
headerHeight={HEADER_HEIGHT}
maxHeight={CHAT_TEXTAREA_MAX_HEIGHT}
minHeight={CHAT_TEXTAREA_HEIGHT}
onSizeChange={(_, size) => {
if (!size) return;

updatePreference({
inputHeight:
typeof size.height === 'string' ? Number.parseInt(size.height) : size.height,
});
}}
placement="bottom"
size={{ height: inputHeight, width: '100%' }}
style={{ zIndex: 10 }}
>
<Head expand={expand} setExpand={setExpand} />
<TextArea setExpand={setExpand} />
<Footer setExpand={setExpand} />
</Flexbox>
</DraggablePanel>
<Flexbox
gap={8}
height={'100%'}
padding={'12px 0 16px'}
style={{ minHeight: CHAT_TEXTAREA_HEIGHT, position: 'relative' }}
>
<Head expand={expand} setExpand={setExpand} />
<TextArea setExpand={setExpand} />
<Footer expand={expand} setExpand={setExpand} />
</Flexbox>
</DraggablePanel>
</>
);
});

Expand Down
2 changes: 1 addition & 1 deletion src/const/layoutTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const HEADER_HEIGHT = 64;
export const MOBILE_NABBAR_HEIGHT = 44;
export const MOBILE_TABBAR_HEIGHT = 48;
export const CHAT_TEXTAREA_MAX_HEIGHT = 800;
export const CHAT_TEXTAREA_HEIGHT = 230;
export const CHAT_TEXTAREA_HEIGHT = 160;
export const CHAT_TEXTAREA_HEIGHT_MOBILE = 108;
export const CHAT_SIDEBAR_WIDTH = 280;

Expand Down

0 comments on commit de85553

Please sign in to comment.