fetch repo after modifying it

This commit is contained in:
Maren Süwer
2018-11-05 13:52:46 +01:00
parent c4d57b1ce8
commit bb92041e09
3 changed files with 86 additions and 15 deletions

View File

@@ -99,13 +99,20 @@ export function fetchReposFailure(err: Error): Action {
}
// fetch repo
export function fetchRepoByLink(repo: Repository) {
return fetchRepo(repo._links.self.href, repo.namespace, repo.name);
}
export function fetchRepo(link: string, namespace: string, name: string) {
export function fetchRepoByName(link: string, namespace: string, name: string) {
const repoUrl = link.endsWith("/") ? link : link + "/";
return fetchRepo(`${repoUrl}${namespace}/${name}`, namespace, name);
}
function fetchRepo(link: string, namespace: string, name: string) {
return function(dispatch: any) {
dispatch(fetchRepoPending(namespace, name));
return apiClient
.get(`${repoUrl}${namespace}/${name}`)
.get(link)
.then(response => response.json())
.then(repository => {
dispatch(fetchRepoSuccess(repository));
@@ -213,6 +220,9 @@ export function modifyRepo(repository: Repository, callback?: () => void) {
callback();
}
})
.then(() => {
dispatch(fetchRepoByLink(repository));
})
.catch(cause => {
const error = new Error(`failed to modify repo: ${cause.message}`);
dispatch(modifyRepoFailure(repository, error));
@@ -347,8 +357,6 @@ export default function reducer(
switch (action.type) {
case FETCH_REPOS_SUCCESS:
return normalizeByNamespaceAndName(action.payload);
case MODIFY_REPO_SUCCESS:
return reducerByNames(state, action.payload);
case FETCH_REPO_SUCCESS:
return reducerByNames(state, action.payload);
default: