Skip to content

Commit

Permalink
Fix upload issues with doubled number of log files
Browse files Browse the repository at this point in the history
  • Loading branch information
karniv00l committed Nov 6, 2022
1 parent 8ed9c21 commit 9b76f04
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/pages/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ const UploadPage = () => {
const [logFiles, setLogFiles] = useState<File[]>([]);
const [toothLogFiles, setToothLogFiles] = useState<File[]>([]);

const [logsTouched, setLogsTouched] = useState(false);
const [toothLogsTouched, setToothLogsTouched] = useState(false);
const [customIniRequired, setCustomIniRequired] = useState(false);

const shareSupported = 'share' in navigator;
Expand Down Expand Up @@ -245,7 +243,7 @@ const UploadPage = () => {
fuel,
ignition,
year,
].filter((field) => field !== null && `${field}`.length > 1)
].filter((field) => field !== null && `${field}`.length > 1 && field !== 'null')
.join(' ')
.replace(/[^\w.\-\d ]/g, ''),
};
Expand All @@ -264,15 +262,12 @@ const UploadPage = () => {
}
});


if (existingTune) {
if (logsTouched || toothLogsTouched) {
// clear old multi files first since there is no other way to handle this
const tempFormData = new FormData();
tempFormData.append('logFiles', '');
tempFormData.append('toothLogFiles', '');
await updateTune(existingTune.id, tempFormData as unknown as TunesRecord);
}
// always clear old multi files first since there is no other way to handle this
const tempFormData = new FormData();
tempFormData.append('logFiles', '');
tempFormData.append('toothLogFiles', '');
await updateTune(existingTune.id, tempFormData as unknown as TunesRecord);

// another update with new files
await updateTune(existingTune.id, formData as unknown as TunesRecord);
Expand Down Expand Up @@ -357,7 +352,6 @@ const UploadPage = () => {
const uploadLogs = async (options: UploadRequestOption) => {
upload(options, async (file) => {
setLogFiles((prev) => [...prev, file]);
setLogsTouched(true);
}, async (file) => {
const { result, message } = await validateSize(file);
if (!result) {
Expand Down Expand Up @@ -391,7 +385,6 @@ const UploadPage = () => {
const uploadToothLogs = async (options: UploadRequestOption) => {
upload(options, async (file) => {
setToothLogFiles((prev) => [...prev, file]);
setToothLogsTouched(true);
}, async (file) => {
const { result, message } = await validateSize(file);
if (!result) {
Expand Down Expand Up @@ -439,12 +432,10 @@ const UploadPage = () => {

const removeLogFile = async (file: UploadFile) => {
setLogFiles((prev) => prev.filter((f) => removeFilenameSuffix(f.name) !== file.name));
setLogsTouched(true);
};

const removeToothLogFile = async (file: UploadFile) => {
setToothLogFiles((prev) => prev.filter((f) => removeFilenameSuffix(f.name) !== file.name));
setToothLogsTouched(true);
};

const removeCustomIniFile = async (file: UploadFile) => {
Expand Down

0 comments on commit 9b76f04

Please sign in to comment.