Skip to content

Commit ff13207

Browse files
committed
Improvements to uploader modal
1 parent 2a1de96 commit ff13207

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/components/uploader.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ export default class FileUploader extends React.Component {
133133
{this.state.pane === 'library' &&
134134
<LibraryPane
135135
fileListEndpoint={this.context.fileListEndpoint}
136+
endpointArgs={{
137+
field_name: this.context.fieldName,
138+
model_name: this.context.modelName,
139+
coordinates: JSON.stringify(this.props.name.split('-').slice(1)),
140+
uid: this.context.uid
141+
}}
136142
onFileSelect={this.handleFileSelect}
137143
/>
138144
}
@@ -204,9 +210,17 @@ class LibraryPane extends React.Component {
204210
return;
205211
}
206212

207-
fetch(endpoint + '?page=' + (this.state.page + 1), {method: 'GET'})
213+
let url = endpoint + '?' + new URLSearchParams({
214+
...this.props.endpointArgs,
215+
page: this.state.page + 1
216+
});
217+
218+
fetch(url, {method: 'GET'})
208219
.then((response) => response.json())
209220
.then((result) => {
221+
if (!Array.isArray(result.file_list))
222+
result.file_list = [];
223+
210224
this.setState((state) => ({
211225
loading: false,
212226
files: [...state.files, ...result.file_list],
@@ -216,7 +230,7 @@ class LibraryPane extends React.Component {
216230
);
217231
})
218232
.catch((error) => {
219-
alert('Something went wrong while uploading file');
233+
alert('Something went wrong while retrieving media files');
220234
console.error('Error:', error);
221235
this.setState({loading: false});
222236
});
@@ -267,11 +281,13 @@ function MediaTile(props) {
267281
<div className="rjf-upload-modal__media-tile">
268282
<div className="rjf-upload-modal__media-tile-inner" tabIndex="0" onClick={() => props.onClick(props.value)}>
269283
<img src={props.thumbnail ? props.thumbnail : DEFAULT_THUBNAIL} />
270-
<div className="rjf-upload-modal__media-tile-metadata">
271-
{Object.getOwnPropertyNames(metadata).map((key) => {
272-
return <span>{metadata[key]}</span>;
273-
})}
274-
</div>
284+
{props.metadata &&
285+
<div className="rjf-upload-modal__media-tile-metadata">
286+
{Object.getOwnPropertyNames(metadata).map((key) => {
287+
return <span>{metadata[key]}</span>;
288+
})}
289+
</div>
290+
}
275291
</div>
276292
</div>
277293
);

0 commit comments

Comments
 (0)