-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
648fccb
commit 709fdc6
Showing
87 changed files
with
2,269 additions
and
4,445 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,39 @@ | ||
import fetch from 'isomorphic-fetch'; | ||
import { getDocumentChildrenUrl } from '../conf/apiRoutes'; | ||
import makeErrorMessage from '../helpers/makeErrorMessage'; | ||
import { checkAndGetStatus } from './utils'; | ||
|
||
export const FETCH_DOCUMENT_CHILDREN = 'FETCH_DOCUMENT_CHILDREN'; | ||
export const FETCH_DOCUMENT_CHILDREN_SUCCESS = | ||
'FETCH_DOCUMENT_CHILDREN_SUCCESS'; | ||
export const FETCH_DOCUMENT_CHILDREN_FAILURE = | ||
'FETCH_DOCUMENT_CHILDREN_FAILURE'; | ||
|
||
export const fetchDocumentChildren = documentId => dispatch => { | ||
dispatch({ type: FETCH_DOCUMENT_CHILDREN }); | ||
return fetch(getDocumentChildrenUrl(documentId)) | ||
.then(response => { | ||
if (response.status >= 400) { | ||
throw new Error(response.status); | ||
} | ||
return response.json(); | ||
}) | ||
.then(data => | ||
dispatch({ type: FETCH_DOCUMENT_CHILDREN_SUCCESS, data: data.documents }) | ||
) | ||
.catch(error => | ||
dispatch({ | ||
type: FETCH_DOCUMENT_CHILDREN_FAILURE, | ||
error: makeErrorMessage( | ||
error.message, | ||
`Fetching children of document with id ${documentId}` | ||
) | ||
export const fetchDocumentChildren = | ||
(documentId, locale = 'en') => | ||
dispatch => { | ||
dispatch({ type: FETCH_DOCUMENT_CHILDREN }); | ||
return fetch(getDocumentChildrenUrl(documentId)) | ||
.then(checkAndGetStatus) | ||
.then(response => response.json()) | ||
.then(data => { | ||
data.documents.sort((a, b) => | ||
a.title | ||
.toLowerCase() | ||
.localeCompare(b.title.toLowerCase(), locale, { numeric: true }) | ||
); | ||
dispatch({ | ||
type: FETCH_DOCUMENT_CHILDREN_SUCCESS, | ||
data: data.documents | ||
}); | ||
}) | ||
); | ||
}; | ||
.catch(error => | ||
dispatch({ | ||
type: FETCH_DOCUMENT_CHILDREN_FAILURE, | ||
error: makeErrorMessage( | ||
error.message, | ||
`Fetching children of document with id ${documentId}` | ||
) | ||
}) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.