Skip to content

Commit

Permalink
git gateway support for media library, branch config
Browse files Browse the repository at this point in the history
  • Loading branch information
erquhart committed Sep 19, 2017
1 parent 289c296 commit a7444e3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/actions/mediaLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function insertMedia(mediaPath) {
return { type: MEDIA_INSERT, payload: { mediaPath } };
}

export function loadMedia(delay = 0, query) {
export function loadMedia({ delay = 0, query }) {
return (dispatch, getState) => {
const state = getState();
const backend = currentBackend(state.config);
Expand Down Expand Up @@ -94,7 +94,7 @@ export function deleteMedia(file) {
return provider.delete(file.id)
.then(() => {
dispatch(mediaDeleted());
return dispatch(loadMedia(500));
return dispatch(loadMedia({ delay: 500 }));
})
.catch(error => {
console.error(error);
Expand All @@ -110,7 +110,7 @@ export function deleteMedia(file) {
return backend.deleteMedia(file.path)
.then(() => {
dispatch(mediaDeleted());
return dispatch(loadMedia(500));
return dispatch(loadMedia({ delay: 500 }));
})
.catch(error => {
console.error(error);
Expand Down
6 changes: 6 additions & 0 deletions src/backends/git-gateway/API.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import GithubAPI from "../github/API";
import { APIError } from "../../valueObjects/errors";

export default class API extends GithubAPI {
constructor(config) {
Expand Down Expand Up @@ -43,15 +44,20 @@ export default class API extends GithubAPI {

request(path, options = {}) {
const url = this.urlFor(path, options);
let responseStatus;
return this.getRequestHeaders(options.headers || {})
.then(headers => fetch(url, { ...options, headers }))
.then((response) => {
responseStatus = response.status;
const contentType = response.headers.get("Content-Type");
if (contentType && contentType.match(/json/)) {
return this.parseJsonResponse(response);
}

return response.text();
})
.catch(error => {
throw new APIError(error.message, responseStatus, 'Git Gateway');
});
}

Expand Down
6 changes: 3 additions & 3 deletions src/components/MediaLibrary/MediaLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MediaLibrary extends React.Component {

componentDidMount() {
const { dispatch, closeMediaLibrary } = this.props;
dispatch(loadMedia(0, this.state.query));
dispatch(loadMedia({ query: this.state.query }));
}

componentWillReceiveProps(nextProps) {
Expand Down Expand Up @@ -113,7 +113,7 @@ class MediaLibrary extends React.Component {
const files = [...fileList];
const file = files[0];
return dispatch(persistMedia(file, privateUpload))
.then(() => dispatch(0, loadMedia(this.state.query)));
.then(() => dispatch(loadMedia({ query: this.state.query })));
};

handleInsert = () => {
Expand All @@ -140,7 +140,7 @@ class MediaLibrary extends React.Component {

handleSearchKeyDown = (event, dynamicSearch) => {
if (event.key === 'Enter' && dynamicSearch) {
this.props.dispatch(loadMedia(0, this.state.query));
this.props.dispatch(loadMedia({ query: this.state.query }));
}
};

Expand Down

0 comments on commit a7444e3

Please sign in to comment.