...
|
...
|
@@ -8,6 +8,7 @@ |
|
|
|
|
|
import {Actions} from 'react-native-router-flux';
|
|
|
import PostingService from '../../services/PostingService';
|
|
|
import Immutable, {List, Record} from 'immutable';
|
|
|
|
|
|
const {
|
|
|
POSTING_BOARD_REQUEST,
|
...
|
...
|
@@ -17,6 +18,11 @@ const { |
|
|
POSTING_ASSETS_SELECTED,
|
|
|
POSTING_TITLE_EDITED,
|
|
|
POSTING_CONTENT_EDITED,
|
|
|
POSTING_POST_START,
|
|
|
POSTING_POST_FAILURE,
|
|
|
POSTING_UPLOAD_UPDATE,
|
|
|
POSTING_POST_FINISHED,
|
|
|
POSTING_STATE_RESET,
|
|
|
} = require('../../constants/actionTypes').default;
|
|
|
|
|
|
export function titleEdited(title) {
|
...
|
...
|
@@ -60,6 +66,109 @@ export function getBoardFailure(error) { |
|
|
}
|
|
|
}
|
|
|
|
|
|
export function postStart() {
|
|
|
return {
|
|
|
type: POSTING_POST_START,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function uploadImageStateChanged(payloadData) {
|
|
|
return {
|
|
|
type: POSTING_UPLOAD_UPDATE,
|
|
|
payload:payloadData,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function postFinished(success) {
|
|
|
return {
|
|
|
type:POSTING_POST_FINISHED,
|
|
|
payload:success,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function updateUploadState(url,fileName) {
|
|
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
|
|
let {posting} = getState();
|
|
|
|
|
|
let assets = posting.assets.toJS();
|
|
|
for (var i = 0; i < assets.length; i++) {
|
|
|
if (assets[i].name == fileName) {
|
|
|
assets[i].webURL = url;
|
|
|
assets[i].finished = true;
|
|
|
}
|
|
|
}
|
|
|
let finishCount = posting.finishedCount;
|
|
|
finishCount++;
|
|
|
let percent = parseFloat(finishCount)/assets.length;
|
|
|
console.log(percent);
|
|
|
let payloadData = {assets,finishCount,percent};
|
|
|
dispatch(uploadImageStateChanged(payloadData));
|
|
|
|
|
|
dispatch(() => {
|
|
|
let {posting} = getState();
|
|
|
if (posting.postPercent == 1) {
|
|
|
let assets = posting.assets.toJS();
|
|
|
let imageStr = '';
|
|
|
for (let i = 0; i < assets.length; i++) {
|
|
|
imageStr += assets[i].webURL+',';
|
|
|
}
|
|
|
let param = {
|
|
|
postTitle: posting.title,
|
|
|
uid: '111213',
|
|
|
forumCode: posting.currentBoardId,
|
|
|
contentData: posting.content,
|
|
|
images: imageStr,
|
|
|
}
|
|
|
|
|
|
return new PostingService().commitPost(param).then(json => {
|
|
|
console.log(json);
|
|
|
dispatch(postFinished(true));
|
|
|
dispatch(resetState());
|
|
|
}).catch(error => {
|
|
|
dispatch(postFinished(false));
|
|
|
})
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function resetState() {
|
|
|
return {
|
|
|
type: POSTING_STATE_RESET,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function postFail() {
|
|
|
return {
|
|
|
type: POSTING_POST_FAILURE,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function startPosting(assets) {
|
|
|
|
|
|
return dispatch => {
|
|
|
dispatch(postStart());
|
|
|
for (let i = 0; i < assets.length; i++) {
|
|
|
let asset = assets[i]
|
|
|
if (asset.finished) {
|
|
|
continue;
|
|
|
}
|
|
|
new PostingService().uploadImageAsset(asset)
|
|
|
.then(response => {
|
|
|
console.log(response);
|
|
|
dispatch(updateUploadState(response,asset.name));
|
|
|
}).catch(error => {
|
|
|
|
|
|
console.log(error);
|
|
|
dispatch(postFail());
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
export function getBoardList() {
|
|
|
return dispatch => {
|
|
|
dispatch(getBoardRequest());
|
...
|
...
|
|