Skip to content

Commit 655aef0

Browse files
committed
Prompt Issue Fixed #218
1 parent a45405e commit 655aef0

3 files changed

Lines changed: 43 additions & 5 deletions

File tree

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"react-icons": "^4.2.0",
3131
"react-keyed-file-browser": "^1.14.0",
3232
"react-markdown": "^8.0.7",
33-
"react-modal": "^3.13.1",
33+
"react-modal": "^3.16.3",
3434
"react-scripts": "4.0.3",
3535
"react-simple-code-editor": "^0.13.0",
3636
"react-spinners": "^0.13.8",

src/component/modals/FileEdit.jsx

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react';
22
import Editor from '@monaco-editor/react';
33
import { saveAs } from 'file-saver';
44
import Modal from './ParentModal';
5+
import ReactModal from 'react-modal';
56
import './file-edit.css';
67
import { actionType as T } from '../../reducer';
78

@@ -10,6 +11,8 @@ const FileEditModal = ({ superState, dispatcher }) => {
1011
const [fileName, setFileName] = useState('');
1112
const [dirButton, setDirButton] = useState(false);
1213
const [language, setLanguage] = useState('plaintext');
14+
const [newFileName, setNewFileName] = useState('');
15+
const [showFilenameModal, setShowFilenameModal] = useState(false);
1316

1417
useEffect(() => {
1518
if (navigator.userAgent.indexOf('Edg') !== -1 || navigator.userAgent.indexOf('Chrome') !== -1) {
@@ -51,11 +54,19 @@ const FileEditModal = ({ superState, dispatcher }) => {
5154
dispatcher({ type: T.SET_FILE_STATE, payload: fS });
5255
}
5356

54-
async function saveSubmit() {
55-
const newFileName = prompt('Filename:');
57+
function handleSaveAsClick() {
58+
setShowFilenameModal(true);
59+
}
60+
61+
function confirmSaveAs() {
62+
if (newFileName.trim() === '') {
63+
toast.error('Filename cannot be empty!');
64+
return;
65+
}
5666
const bytes = new TextEncoder().encode(codeStuff);
5767
const blob = new Blob([bytes], { type: 'application/json;charset=utf-8' });
5868
saveAs(blob, newFileName);
69+
setShowFilenameModal(false);
5970
}
6071

6172
useEffect(() => {
@@ -120,10 +131,37 @@ const FileEditModal = ({ superState, dispatcher }) => {
120131
<button type="submit" className="btn btn-primary" onClick={saveAsSubmit}>Save As</button>
121132
)}
122133
{!dirButton && (
123-
<button type="submit" className="btn btn-primary" onClick={saveSubmit}>Save As</button>
134+
<button type="submit" className="btn btn-primary" onClick={handleSaveAsClick}>Save As</button>
124135
)}
125136
</div>
126137
</div>
138+
{/* Filename Input Modal */}
139+
<ReactModal
140+
isOpen={showFilenameModal}
141+
onRequestClose={() => setShowFilenameModal(false)}
142+
className="modal-content"
143+
overlayClassName="modal-overlay"
144+
ariaHideApp={false}
145+
>
146+
<h2>Enter Filename</h2>
147+
<input
148+
type="text"
149+
value={newFileName}
150+
onChange={(e) => setNewFileName(e.target.value)}
151+
className="modal-input"
152+
placeholder="Filename"
153+
/>
154+
<div className="modal-actions">
155+
<button type="button" onClick={confirmSaveAs} className="btn btn-primary">Save</button>
156+
<button
157+
type="button"
158+
onClick={() => setShowFilenameModal(false)}
159+
className="btn btn-secondary"
160+
>
161+
Cancel
162+
</button>
163+
</div>
164+
</ReactModal>
127165
</Modal>
128166
);
129167
};

0 commit comments

Comments
 (0)