Skip to content

Commit 3b1dc24

Browse files
authored
Merge pull request #222 from saksham-gera/prompt_issue
Prompt issue fixed
2 parents b69af74 + 0898a3d commit 3b1dc24

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
@@ -1,6 +1,7 @@
11
import React, { useState, useEffect } from 'react';
22
import Editor from '@monaco-editor/react';
33
import { saveAs } from 'file-saver';
4+
import ReactModal from 'react-modal';
45
import Modal from './ParentModal';
56
import { toast } from 'react-toastify';
67
import './file-edit.css';
@@ -11,6 +12,8 @@ const FileEditModal = ({ superState, dispatcher }) => {
1112
const [fileName, setFileName] = useState('');
1213
const [dirButton, setDirButton] = useState(false);
1314
const [language, setLanguage] = useState('plaintext');
15+
const [newFileName, setNewFileName] = useState('');
16+
const [showFilenameModal, setShowFilenameModal] = useState(false);
1417

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

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

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

0 commit comments

Comments
 (0)