Authored by 于良

下拉刷新和上拉加载优化 review by 阿瑟

@@ -100,7 +100,7 @@ class HomeContainer extends React.Component { @@ -100,7 +100,7 @@ class HomeContainer extends React.Component {
100 100
101 componentDidMount() { 101 componentDidMount() {
102 InteractionManager.runAfterInteractions(() => { 102 InteractionManager.runAfterInteractions(() => {
103 - this.props.actions.bannerNoticeSection(); 103 + this.props.actions.bannerNoticeSectionOnlyDispathSuccess();
104 this.props.actions.getUserInfo(false); 104 this.props.actions.getUserInfo(false);
105 }); 105 });
106 106
@@ -86,7 +86,7 @@ class SectionContainer extends React.Component { @@ -86,7 +86,7 @@ class SectionContainer extends React.Component {
86 } 86 }
87 87
88 InteractionManager.runAfterInteractions(() => { 88 InteractionManager.runAfterInteractions(() => {
89 - this.props.actions.header(); 89 + this.props.actions.headerOnlyDispatchSuccess();
90 }); 90 });
91 } 91 }
92 92
@@ -67,6 +67,25 @@ export function bannerNoticeSection() { @@ -67,6 +67,25 @@ export function bannerNoticeSection() {
67 }; 67 };
68 } 68 }
69 69
  70 +export function bannerNoticeSectionOnlyDispathSuccess() {
  71 + return (dispatch, getState) => {
  72 +
  73 + let {app, home} = getState();
  74 + if (home.isFetching) {
  75 + return;
  76 + }
  77 + // dispatch(bnsRequest());
  78 + return new HomeService().bannerNoticeSection(app.container)
  79 + .then(json => {
  80 + let payload = parseBNS(json);
  81 + dispatch(bnsSuccess(payload));
  82 + })
  83 + .catch(error => {
  84 + // dispatch(bnsFailure(error));
  85 + });
  86 + };
  87 +}
  88 +
70 export function recommendationRequest(ptr) { 89 export function recommendationRequest(ptr) {
71 return { 90 return {
72 type: HOME_RECOMMENDATION_REQUEST, 91 type: HOME_RECOMMENDATION_REQUEST,
@@ -91,7 +110,7 @@ export function recommendationFailure(error) { @@ -91,7 +110,7 @@ export function recommendationFailure(error) {
91 export function recommendation(ptr = false) { 110 export function recommendation(ptr = false) {
92 return (dispatch, getState) => { 111 return (dispatch, getState) => {
93 let {home, user} = getState(); 112 let {home, user} = getState();
94 - if (home.recommendation.isFetching || (!ptr && home.recommendation.endReached)) { 113 + if (home.recommendation.isFetching || (!ptr && home.recommendation.endReached) || home.recommendation.error !== null) {
95 return; 114 return;
96 } 115 }
97 116
@@ -24,7 +24,7 @@ let InitialState = Record({ @@ -24,7 +24,7 @@ let InitialState = Record({
24 })), 24 })),
25 notice: new (Record({ 25 notice: new (Record({
26 duration: 3, 26 duration: 3,
27 - open: 'Y', 27 + open: 'N',
28 list: List(), 28 list: List(),
29 })), 29 })),
30 section: List(), 30 section: List(),
@@ -106,10 +106,28 @@ export function header() { @@ -106,10 +106,28 @@ export function header() {
106 }; 106 };
107 } 107 }
108 108
  109 +export function headerOnlyDispatchSuccess() {
  110 + return (dispatch, getState) => {
  111 + let {section} = getState();
  112 + if (section.isFetching) {
  113 + return;
  114 + }
  115 + // dispatch(headerRequest());
  116 + return new SectionService().header(section.id)
  117 + .then(json => {
  118 + let payload = parseHeader(json);
  119 + dispatch(headerSuccess(payload));
  120 + })
  121 + .catch(error => {
  122 + // dispatch(headerFailure());
  123 + });
  124 + };
  125 +}
  126 +
109 export function newPost(ptr = false) { 127 export function newPost(ptr = false) {
110 return (dispatch, getState) => { 128 return (dispatch, getState) => {
111 let {section, user} = getState(); 129 let {section, user} = getState();
112 - if (section.new.isFetching || (!ptr && section.new.endReached)) { 130 + if (section.new.isFetching || (!ptr && section.new.endReached) || section.new.error !== null) {
113 return; 131 return;
114 } 132 }
115 dispatch(newPostRequest(ptr)); 133 dispatch(newPostRequest(ptr));
@@ -139,7 +157,7 @@ export function newPost(ptr = false) { @@ -139,7 +157,7 @@ export function newPost(ptr = false) {
139 export function hotPost(ptr = false) { 157 export function hotPost(ptr = false) {
140 return (dispatch, getState) => { 158 return (dispatch, getState) => {
141 let {section, user} = getState(); 159 let {section, user} = getState();
142 - if (section.hot.isFetching || (!ptr && section.hot.endReached)) { 160 + if (section.hot.isFetching || (!ptr && section.hot.endReached) || section.hot.error !== null) {
143 return; 161 return;
144 } 162 }
145 dispatch(hotPostRequest(ptr)); 163 dispatch(hotPostRequest(ptr));
@@ -23,7 +23,7 @@ let InitialState = Record({ @@ -23,7 +23,7 @@ let InitialState = Record({
23 ptr: false, 23 ptr: false,
24 notice: new (Record({ 24 notice: new (Record({
25 duration: 3, 25 duration: 3,
26 - open: 'Y', 26 + open: 'N',
27 list: List(), 27 list: List(),
28 })), 28 })),
29 header: new (Record({ 29 header: new (Record({