Skip to content

Commit

Permalink
🐛 fix: Fix image upload error
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 authored and arvinxx committed Dec 1, 2023
1 parent c68788d commit c7745c7
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { memo } from 'react';
import FileList from 'src/components/FileList';

import FileList from '@/app/chat/components/FileList';
import { useFileStore } from '@/store/file';

export const LocalFiles = memo(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/chat/(mobile)/features/ChatInput/Files.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { memo } from 'react';
import { Flexbox } from 'react-layout-kit';
import FileList from 'src/components/FileList';

import FileList from '@/app/chat/components/FileList';
import { useFileStore } from '@/store/file';

const Files = memo(() => {
Expand Down
63 changes: 0 additions & 63 deletions src/app/chat/components/FileList/index.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ReactNode, memo } from 'react';
import { Flexbox } from 'react-layout-kit';
import FileList from 'src/components/FileList';

import FileList from '@/app/chat/components/FileList';
import { LOADING_FLAT } from '@/const/message';
import { ChatMessage } from '@/types/chatMessage';

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import { Image } from 'antd';
import { PropsWithChildren, memo } from 'react';

import { filesSelectors, useFileStore } from '@/store/file';

const { PreviewGroup } = Image;

interface LightBoxProps extends PropsWithChildren {
items: string[];
}

const LightBox = memo<LightBoxProps>(({ items, children }) => {
const list = useFileStore(filesSelectors.getImageUrlByList(items));

if (list.length === 1) return children;
if (items.length === 1) return children;

return (
<PreviewGroup
items={list}
preview={{
styles: { mask: { backdropFilter: 'blur(2px)' } },
}}
Expand Down
28 changes: 28 additions & 0 deletions src/components/FileList/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { memo } from 'react';

import LightBox from '@/components/FileList/Lightbox';

import FileItem from './FileItem';
import { useStyles } from './style';

interface FileListProps {
alwaysShowClose?: boolean;
editable?: boolean;
items: string[];
}

const FileList = memo<FileListProps>(({ items, editable = true, alwaysShowClose }) => {
const { styles } = useStyles();

return (
<div className={styles.container}>
<LightBox items={items}>
{items.map((i) => (
<FileItem alwaysShowClose={alwaysShowClose} editable={editable} id={i} key={i} />
))}
</LightBox>
</div>
);
});

export default FileList;
37 changes: 37 additions & 0 deletions src/components/FileList/style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { createStyles } from 'antd-style';

import { MIN_IMAGE_SIZE } from './FileItem.style';

export const MAX_SIZE = 640;
export const GAP = 8;

export const useStyles = createStyles(({ css }) => ({
container: css`
display: grid;
grid-gap: ${GAP}px;
grid-template-columns: repeat(6, 1fr);
width: 100%;
max-width: ${MAX_SIZE}px;
& > div {
grid-column: span 2;
width: 100%;
min-width: ${MIN_IMAGE_SIZE}px;
min-height: ${MIN_IMAGE_SIZE}px;
max-height: ${(MAX_SIZE - GAP) / 2}px;
}
& > div:nth-child(1):nth-last-child(2),
& > div:nth-child(2):nth-last-child(1) {
grid-column: span 3;
max-height: ${(MAX_SIZE - 2 * GAP) / 3}px;
}
& > :nth-child(1):nth-last-child(1) {
grid-column: span 6;
max-height: ${MAX_SIZE}px;
}
`,
}));

0 comments on commit c7745c7

Please sign in to comment.