Skip to content

Commit 4102702

Browse files
committed
Open single graphml file (alongwith save)
1 parent 02bdeca commit 4102702

1 file changed

Lines changed: 50 additions & 2 deletions

File tree

src/component/fileBrowser.jsx

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,25 @@ const LocalFileBrowser = ({ superState, dispatcher }) => {
8585
setFileState(state);
8686
};
8787

88+
const newFeatureFile = async () => {
89+
const pickerOpts = {
90+
types: [
91+
{
92+
description: 'Graphml',
93+
accept: {
94+
'text/graphml': ['.graphml'],
95+
},
96+
},
97+
],
98+
excludeAcceptAllOption: true,
99+
multiple: false,
100+
};
101+
102+
const [fileHandle] = await window.showOpenFilePicker(pickerOpts);
103+
const fileObj = await fileHandle.getFile();
104+
readFile(superState, dispatcher, fileObj, fileHandle);
105+
};
106+
88107
return (
89108
<div>
90109
{!dirButton && (
@@ -96,7 +115,6 @@ const LocalFileBrowser = ({ superState, dispatcher }) => {
96115
<input
97116
type="file"
98117
accept=".py, .m, .c, .cpp, .v, .sh"
99-
ref={fileRef}
100118
id="fileButton"
101119
style={{ display: 'none' }}
102120
onClick={(e) => { e.target.value = null; }}
@@ -126,11 +144,41 @@ const LocalFileBrowser = ({ superState, dispatcher }) => {
126144
className="inputButton"
127145
disabled={!dirButton}
128146
onClick={newFeature}
129-
ref={fileRef}
130147
>
131148
Upload Directory
132149
</button>
133150
)}
151+
{!dirButton
152+
&& (
153+
<input
154+
type="file"
155+
ref={fileRef}
156+
onClick={(e) => { e.target.value = null; }}
157+
style={{ display: 'none' }}
158+
accept=".graphml"
159+
onChange={(e) => readFile(superState, dispatcher, e.target.files[0])}
160+
/>
161+
)}
162+
{dirButton
163+
&& (
164+
<button
165+
type="button"
166+
ref={fileRef}
167+
className="inputButton"
168+
disabled={!dirButton}
169+
style={{ display: 'none' }}
170+
onClick={newFeatureFile}
171+
label="File Upload"
172+
/>
173+
// <input
174+
// type="file"
175+
// ref={fileRef}
176+
// onClick={(e) => { e.target.value = null; }}
177+
// style={{ display: 'none' }}
178+
// accept=".graphml"
179+
// onChange={(e) => readFile(superState, dispatcher, e.target.files[0])}
180+
// />
181+
)}
134182
<h4>
135183
Folder Name :
136184
{' '}

0 commit comments

Comments
 (0)