mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +01:00
refactor, also add boilerplate edition store, actions and container
This commit is contained in:
parent
60d4ce8eaf
commit
9c21edf8c4
24
js/actions/edition_list_actions.js
Normal file
24
js/actions/edition_list_actions.js
Normal file
@ -0,0 +1,24 @@
|
||||
import alt from '../alt';
|
||||
|
||||
import EditionListFetcher from '../fetchers/edition_list_fetcher.js';
|
||||
|
||||
class EditionListActions {
|
||||
constructor() {
|
||||
this.generateActions(
|
||||
'updateEditionList'
|
||||
);
|
||||
}
|
||||
|
||||
fetchList() {
|
||||
EditionListFetcher
|
||||
.fetch()
|
||||
.then((res) => {
|
||||
this.actions.updateEditionList(res.pieces);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default alt.createActions(EditionListActions);
|
@ -1,4 +1,5 @@
|
||||
import alt from '../alt';
|
||||
|
||||
import PieceListFetcher from '../fetchers/piece_list_fetcher';
|
||||
|
||||
|
||||
@ -10,7 +11,8 @@ class PieceListActions {
|
||||
}
|
||||
|
||||
fetchList(page, pageSize, search, orderBy, orderAsc) {
|
||||
PieceListFetcher.fetch(page, pageSize, search, orderBy, orderAsc)
|
||||
PieceListFetcher
|
||||
.fetch(page, pageSize, search, orderBy, orderAsc)
|
||||
.then((res) => {
|
||||
this.actions.updatePieceList({
|
||||
'itemList': res.pieces,
|
||||
|
@ -16,6 +16,7 @@ let TableItem = React.createClass({
|
||||
},
|
||||
|
||||
render() {
|
||||
|
||||
/**
|
||||
* An element in the Table can have a certain display_type.
|
||||
* A display_type is just
|
||||
|
32
js/components/edition_list.js
Normal file
32
js/components/edition_list.js
Normal file
@ -0,0 +1,32 @@
|
||||
import React from 'react';
|
||||
import AltContainer from 'alt/AltContainer';
|
||||
|
||||
import EditionListStore from '../stores/edition_list_store';
|
||||
import EditionListActions from '../actions/edition_list_actions';
|
||||
|
||||
import Table from './ascribe_table/table';
|
||||
import TableItemText from './ascribe_table/table_item_text';
|
||||
|
||||
import TableColumnModel from '../models/table_column_model';
|
||||
|
||||
let EditionList = React.createClass({
|
||||
|
||||
getInitialState() {
|
||||
return EditionListStore.getState();
|
||||
},
|
||||
|
||||
componentDidMount() {
|
||||
EditionListActions.fetchList();
|
||||
},
|
||||
|
||||
render() {
|
||||
return (
|
||||
<AltContainer store={EditionListStore} actions={EditionListActions}>
|
||||
|
||||
</AltContainer>
|
||||
);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
export default EditionList;
|
@ -1,5 +1,4 @@
|
||||
import React from 'react';
|
||||
import Router from 'react-router';
|
||||
import AltContainer from 'alt/AltContainer';
|
||||
|
||||
import PieceListStore from '../stores/piece_list_store';
|
||||
@ -11,8 +10,6 @@ import TableItemText from './ascribe_table/table_item_text';
|
||||
|
||||
import TableColumnModel from '../models/table_column_model';
|
||||
|
||||
let Link = Router.Link;
|
||||
|
||||
|
||||
let PieceList = React.createClass({
|
||||
|
||||
|
20
js/fetchers/edition_list_fetcher.js
Normal file
20
js/fetchers/edition_list_fetcher.js
Normal file
@ -0,0 +1,20 @@
|
||||
import fetch from 'isomorphic-fetch';
|
||||
|
||||
import AppConstants from '../constants/application_constants';
|
||||
|
||||
|
||||
let EditionListFetcher = {
|
||||
/**
|
||||
* Fetches a list of editions from the API.
|
||||
*/
|
||||
fetch() {
|
||||
|
||||
return fetch(AppConstants.baseUrl + 'pieces/', {
|
||||
headers: {
|
||||
'Authorization': 'Basic ' + AppConstants.debugCredentialBase64
|
||||
}
|
||||
}).then((res) => res.json());
|
||||
}
|
||||
};
|
||||
|
||||
export default EditionListFetcher;
|
15
js/stores/edition_list_store.js
Normal file
15
js/stores/edition_list_store.js
Normal file
@ -0,0 +1,15 @@
|
||||
import alt from '../alt';
|
||||
import EditionsListActions from '../actions/edition_list_actions';
|
||||
|
||||
class EditionListStore {
|
||||
constructor() {
|
||||
this.itemList = [];
|
||||
this.bindActions(EditionsListActions);
|
||||
}
|
||||
|
||||
onUpdateEditionList(itemList) {
|
||||
this.itemList = itemList;
|
||||
}
|
||||
};
|
||||
|
||||
export default alt.createStore(EditionListStore);
|
Loading…
Reference in New Issue
Block a user