Skip to content

Commit

Permalink
use last file name for editor save
Browse files Browse the repository at this point in the history
  • Loading branch information
alextusinean committed Jul 3, 2024
1 parent 51d55c9 commit 8d35932
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions components/cryptForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export default function CryptForm({ isEncryption, isLoading, setIsLoading, passw
const [data, setData] = useState(null);
const [editorData, setEditorData] = useState(null);
const [shouldGzip, setShouldGzip] = useState(false);
const [lastFileName, setLastFileName] = useState(null);
const [isEncryptionWarning, setIsEncryptionWarning] = useState(false);
const { isOpen, onOpen: _onOpen, onClose: _onClose } = useDisclosure();
const { isOpen: isEditorOpen, onOpen: onEditorOpen, onClose: onEditorClose } = useDisclosure();
Expand Down Expand Up @@ -125,7 +126,8 @@ export default function CryptForm({ isEncryption, isLoading, setIsLoading, passw
ref={saveFileRef}
disabled={isLoading}
onChange={changeEvent => {
if (!changeEvent.target.files.length) {
const files = changeEvent.target.files;
if (!files.length) {
setData(null);
return;
}
Expand All @@ -144,7 +146,9 @@ export default function CryptForm({ isEncryption, isLoading, setIsLoading, passw
});
};

fileReader.readAsArrayBuffer(changeEvent.target.files[0]);
const file = files[0];
setLastFileName(file.name);
fileReader.readAsArrayBuffer(file);
}}
/>
{isEncryption && (
Expand Down Expand Up @@ -362,7 +366,7 @@ export default function CryptForm({ isEncryption, isLoading, setIsLoading, passw
return false;
}

setDownloadData(cryptedData, 'SaveFile.encrypted.txt');
setDownloadData(cryptedData, lastFileName);
download();
return true;
}}
Expand Down

0 comments on commit 8d35932

Please sign in to comment.