Skip to content

Commit

Permalink
fix: handle duplicate and long file name
Browse files Browse the repository at this point in the history
  • Loading branch information
pasyukevich committed Oct 24, 2024
1 parent cfceae4 commit fc154dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/components/AttachmentPicker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {FileObject} from '@components/AttachmentModal';
import type CONST from '@src/CONST';

type PickerOptions = {
/** A callback that will be called with the selected attachment. */
/** A callback that will be called with the selected attachments. */
onPicked: (files: FileObject[]) => void;
/** A callback that will be called without a selected attachment. */
onCanceled?: () => void;
Expand Down
22 changes: 11 additions & 11 deletions src/components/UploadFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,9 @@ function UploadFile({
}
}

if (fileLimit) {
if (files.length > 0) {
if (files.length > fileLimit) {
setError(translate('attachmentPicker.tooManyFiles', {fileLimit}));
return;
}
}
if (fileLimit && files.length > 0 && files.length > fileLimit) {
setError(translate('attachmentPicker.tooManyFiles', {fileLimit}));
return;
}

if (acceptedFileTypes.length > 0) {
Expand All @@ -96,8 +92,12 @@ function UploadFile({
}
}

onInputChange(files);
onUpload(files);
const uploadedFilesNames = uploadedFiles.map((uploadedFile) => uploadedFile.name);

const newFilesToUpload = files.filter((file) => !uploadedFilesNames.includes(file.name));

onInputChange(newFilesToUpload);
onUpload(newFilesToUpload);
};

return (
Expand All @@ -122,15 +122,15 @@ function UploadFile({
</AttachmentPicker>
{uploadedFiles.map((file) => (
<View
style={[styles.flexRow, styles.alignItemsCenter, styles.justifyContentCenter, styles.border, styles.p5, styles.mt3]}
style={[styles.flexRow, styles.alignItemsCenter, styles.justifyContentCenter, styles.border, styles.p5, styles.mt3, styles.wrpap]}

Check failure on line 125 in src/components/UploadFile.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Property 'wrpap' does not exist on type '{ editedLabelStyles: TextStyle; emojiDefaultStyles: TextStyle; autoCompleteSuggestionsContainer: { backgroundColor: string; borderRadius: number; borderWidth: number; ... 4 more ...; paddingVertical: 8; }; ... 1088 more ...; minHeight65: { ...; }; }'.
key={file.uri}
>
<Icon
src={Expensicons.Paperclip}
fill={theme.icon}
medium
/>
<Text style={[styles.ml2, styles.mr2, styles.textBold]}>{file.name}</Text>
<Text style={[styles.ml2, styles.mr2, styles.textBold, styles.breakWord]}>{file.name}</Text>
<PressableWithFeedback
onPress={() => onRemove(file?.uri ?? '')}
role={CONST.ROLE.BUTTON}
Expand Down

0 comments on commit fc154dc

Please sign in to comment.