forked from Remchi/bookworm-react
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
11 changed files
with
104 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { normalize } from "normalizr"; | ||
import { BOOKS_FETCHED, BOOK_CREATED } from "../types"; | ||
import api from "../api"; | ||
import { bookSchema } from "../schemas"; | ||
|
||
// data.entities.books | ||
const booksFetched = data => ({ | ||
type: BOOKS_FETCHED, | ||
data | ||
}); | ||
|
||
const bookCreated = data => ({ | ||
type: BOOK_CREATED, | ||
data | ||
}); | ||
|
||
export const fetchBooks = () => dispatch => | ||
api.books | ||
.fetchAll() | ||
.then(books => dispatch(booksFetched(normalize(books, [bookSchema])))); | ||
|
||
export const createBook = data => dispatch => | ||
api.books | ||
.create(data) | ||
.then(book => dispatch(bookCreated(normalize(book, bookSchema)))); |
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
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { schema } from "normalizr"; | ||
|
||
export const bookSchema = new schema.Entity( | ||
"books", | ||
{}, | ||
{ idAttribute: "_id" } | ||
); |
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,2 +1,4 @@ | ||
export const USER_LOGGED_IN = "USER_LOGGED_IN"; | ||
export const USER_LOGGED_OUT = "USER_LOGGED_OUT"; | ||
export const BOOKS_FETCHED = "BOOKS_FETCHED"; | ||
export const BOOK_CREATED = "BOOK_CREATED"; |
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