Authored by 盖剑秋

Fix bug YH-3192. reivewed by redding.

@@ -147,7 +147,7 @@ export function drillToEditPostPage() { @@ -147,7 +147,7 @@ export function drillToEditPostPage() {
147 147
148 export function titleEdited(title) { 148 export function titleEdited(title) {
149 return (dispatch, getState) => { 149 return (dispatch, getState) => {
150 - let canSubmit = canSubmitPost(getState(), title, null, null); 150 + let canSubmit = canSubmitPost(getState(), title, null, null, null);
151 dispatch({ 151 dispatch({
152 type: POSTING_TITLE_EDITED, 152 type: POSTING_TITLE_EDITED,
153 payload: {title, canSubmit}, 153 payload: {title, canSubmit},
@@ -157,7 +157,7 @@ export function titleEdited(title) { @@ -157,7 +157,7 @@ export function titleEdited(title) {
157 157
158 export function contentEdited(content) { 158 export function contentEdited(content) {
159 return (dispatch, getState) => { 159 return (dispatch, getState) => {
160 - let canSubmit = canSubmitPost(getState(), null, content, null); 160 + let canSubmit = canSubmitPost(getState(), null, content, null, null);
161 dispatch({ 161 dispatch({
162 type: POSTING_CONTENT_EDITED, 162 type: POSTING_CONTENT_EDITED,
163 payload: {content, canSubmit}, 163 payload: {content, canSubmit},
@@ -167,7 +167,7 @@ export function contentEdited(content) { @@ -167,7 +167,7 @@ export function contentEdited(content) {
167 167
168 export function boardSelected(sectionName, sectionId) { 168 export function boardSelected(sectionName, sectionId) {
169 return (dispatch, getState) => { 169 return (dispatch, getState) => {
170 - let canSubmit = canSubmitPost(getState(), null, null, sectionName); 170 + let canSubmit = canSubmitPost(getState(), null, null, sectionName, null);
171 dispatch({ 171 dispatch({
172 type: POSTING_BOARD_SELECTED, 172 type: POSTING_BOARD_SELECTED,
173 payload: {sectionName, sectionId, canSubmit}, 173 payload: {sectionName, sectionId, canSubmit},
@@ -176,26 +176,31 @@ export function boardSelected(sectionName, sectionId) { @@ -176,26 +176,31 @@ export function boardSelected(sectionName, sectionId) {
176 } 176 }
177 177
178 export function assetsSelected(assets) { 178 export function assetsSelected(assets) {
179 - return {  
180 - type: POSTING_ASSETS_SELECTED,  
181 - payload: assets,  
182 - }; 179 + return (dispatch, getState) => {
  180 + let canSubmit = canSubmitPost(getState(), null, null, null, assets);
  181 + dispatch({
  182 + type: POSTING_ASSETS_SELECTED,
  183 + payload: {assets, canSubmit},
  184 + });
  185 + }
183 } 186 }
184 187
185 -function canSubmitPost(state, newTitle = null, newContent = null, newSectionName = null) { 188 +function canSubmitPost(state, newTitle = null, newContent = null, newSectionName = null, nuewAssets = null) {
186 let {posting} = state; 189 let {posting} = state;
187 let {post} = posting; 190 let {post} = posting;
188 - let {title, content, sectionName} = post; 191 + let {title, content, sectionName, assets} = post;
189 192
190 let canSubmitPost = false; 193 let canSubmitPost = false;
191 194
192 let titleValue = newTitle !== null ? newTitle : title; 195 let titleValue = newTitle !== null ? newTitle : title;
193 let contentValue = newContent !== null ? newContent : content; 196 let contentValue = newContent !== null ? newContent : content;
194 let sectionNameValue = newSectionName !== null ? newSectionName : sectionName; 197 let sectionNameValue = newSectionName !== null ? newSectionName : sectionName;
  198 + let assetsValue = nuewAssets !== null ? nuewAssets : assets.toJS();
195 199
  200 + let hasAssets = assetsValue.length;
196 let hasTitleOrContent = titleValue.length > 0 || contentValue.length > 0; 201 let hasTitleOrContent = titleValue.length > 0 || contentValue.length > 0;
197 let hasSection = sectionNameValue.length > 0; 202 let hasSection = sectionNameValue.length > 0;
198 - if (hasTitleOrContent && hasSection) { 203 + if ((hasTitleOrContent || hasAssets) && hasSection) {
199 canSubmitPost = true; 204 canSubmitPost = true;
200 } 205 }
201 206
@@ -97,8 +97,8 @@ export default function postingReducer(state = initialState, action) { @@ -97,8 +97,8 @@ export default function postingReducer(state = initialState, action) {
97 } 97 }
98 98
99 case POSTING_ASSETS_SELECTED: { 99 case POSTING_ASSETS_SELECTED: {
100 - let assets = action.payload || [];  
101 - let nextState = state.setIn(['post', 'assets'], Immutable.fromJS(assets)); 100 + let {assets, canSubmit} = action.payload;
  101 + let nextState = state.setIn(['post', 'assets'], Immutable.fromJS(assets)).set('canSubmit',canSubmit);
102 return nextState; 102 return nextState;
103 } 103 }
104 104