mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-18 19:01:38 +03:00
migrated scheduled posts apis
This commit is contained in:
parent
40420ef9e4
commit
942633583b
@ -396,45 +396,107 @@ export const searchTag = (q = '', limit = 20, random = 0) =>
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Schedule
|
|
||||||
export const schedule = (
|
|
||||||
user,
|
/**
|
||||||
|
* ************************************
|
||||||
|
* SCHEDULES ECENCY APIS IMPLEMENTATION
|
||||||
|
* ************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds new post to scheduled posts
|
||||||
|
* @param permlink
|
||||||
|
* @param title
|
||||||
|
* @param body
|
||||||
|
* @param meta
|
||||||
|
* @param options
|
||||||
|
* @param scheduleDate
|
||||||
|
* @returns All scheduled posts
|
||||||
|
*/
|
||||||
|
export const addSchedule = async (
|
||||||
|
permlink:string,
|
||||||
|
title:string,
|
||||||
|
body:string,
|
||||||
|
meta:any,
|
||||||
|
options:any,
|
||||||
|
scheduleDate:string
|
||||||
|
) => {
|
||||||
|
try {
|
||||||
|
const data = {
|
||||||
title,
|
title,
|
||||||
permlink,
|
permlink,
|
||||||
json,
|
meta,
|
||||||
tags,
|
|
||||||
body,
|
|
||||||
operationType,
|
|
||||||
upvote,
|
|
||||||
scheduleDate,
|
|
||||||
options = null,
|
|
||||||
) =>
|
|
||||||
api
|
|
||||||
.post('/schedules', {
|
|
||||||
username: user,
|
|
||||||
title,
|
|
||||||
permlink,
|
|
||||||
meta: json,
|
|
||||||
body,
|
body,
|
||||||
schedule: scheduleDate,
|
schedule: scheduleDate,
|
||||||
options,
|
options,
|
||||||
reblog: 0,
|
reblog: 0,
|
||||||
})
|
}
|
||||||
.then((resp) => resp.data)
|
const response = await ecencyApi
|
||||||
.catch((error) => bugsnag.notify(error));
|
.post('/private-api/schedules-add', data)
|
||||||
|
return response.data;
|
||||||
|
} catch(error) {
|
||||||
|
console.warn("Failed to add post to schedule", error)
|
||||||
|
bugsnag.notify(error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const getSchedules = (username) =>
|
/**
|
||||||
api
|
* Fetches all scheduled posts against current user
|
||||||
.get(`/schedules/${username}`)
|
* @returns array of app scheduled posts
|
||||||
.then((resp) => resp.data)
|
*/
|
||||||
.catch((error) => bugsnag.notify(error));
|
export const getSchedules = async () => {
|
||||||
|
try {
|
||||||
|
const response = await ecencyApi.post(`/private-api/schedules`)
|
||||||
|
return response.data;
|
||||||
|
} catch(error){
|
||||||
|
console.warn("Failed to get schedules")
|
||||||
|
bugsnag.notify(error)
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const removeSchedule = (username, id) => api.delete(`/schedules/${username}/${id}`);
|
/**
|
||||||
|
* Removes post from scheduled posts using post id;
|
||||||
|
* @param id
|
||||||
|
* @returns array of scheduled posts
|
||||||
|
*/
|
||||||
|
export const deleteScheduledPost = async (id:string) => {
|
||||||
|
try {
|
||||||
|
const data = { id };
|
||||||
|
const response = await ecencyApi.post(`/private-api/schedules-delete`, data);
|
||||||
|
return response;
|
||||||
|
}catch(error){
|
||||||
|
console.warn("Failed to delete scheduled post")
|
||||||
|
bugsnag.notify(error)
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const moveSchedule = (id, username) => api.put(`/schedules/${username}/${id}`);
|
/**
|
||||||
|
* Moves scheduled post to draft using schedule id
|
||||||
|
* @param id
|
||||||
|
* @returns Array of scheduled posts
|
||||||
|
*/
|
||||||
|
export const moveScheduledToDraft = async (id:string) => {
|
||||||
|
try {
|
||||||
|
const data = { id }
|
||||||
|
const response = await ecencyApi.post(`/private-api/schedules-move`, data);
|
||||||
|
return response.data;
|
||||||
|
} catch(error) {
|
||||||
|
console.warn("Failed to move scheduled post to drafts")
|
||||||
|
bugsnag.notify(error)
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Old image service
|
// Old image service
|
||||||
// Images
|
/**
|
||||||
|
* ************************************
|
||||||
|
* IMAGES ECENCY APIS IMPLEMENTATION
|
||||||
|
* ************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
export const getImages = async () => {
|
export const getImages = async () => {
|
||||||
|
@ -8,8 +8,8 @@ import {
|
|||||||
getDrafts,
|
getDrafts,
|
||||||
removeDraft,
|
removeDraft,
|
||||||
getSchedules,
|
getSchedules,
|
||||||
removeSchedule,
|
moveScheduledToDraft,
|
||||||
moveSchedule,
|
deleteScheduledPost,
|
||||||
} from '../../../providers/ecency/ecency';
|
} from '../../../providers/ecency/ecency';
|
||||||
import { toastNotification } from '../../../redux/actions/uiAction';
|
import { toastNotification } from '../../../redux/actions/uiAction';
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ const DraftsContainer = ({ currentAccount, intl, navigation, dispatch }) => {
|
|||||||
const _getSchedules = () => {
|
const _getSchedules = () => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
||||||
getSchedules(currentAccount.name)
|
getSchedules()
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
setSchedules(_sortDataS(data));
|
setSchedules(_sortDataS(data));
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
@ -75,7 +75,7 @@ const DraftsContainer = ({ currentAccount, intl, navigation, dispatch }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const _removeSchedule = (id) => {
|
const _removeSchedule = (id) => {
|
||||||
removeSchedule(currentAccount.name, id)
|
deleteScheduledPost(id)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
const newSchedules = [...schedules].filter((schedule) => schedule._id !== id);
|
const newSchedules = [...schedules].filter((schedule) => schedule._id !== id);
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ const DraftsContainer = ({ currentAccount, intl, navigation, dispatch }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const _moveScheduleToDraft = (id) => {
|
const _moveScheduleToDraft = (id) => {
|
||||||
moveSchedule(id, currentAccount.name)
|
moveScheduledToDraft(id)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
dispatch(
|
dispatch(
|
||||||
toastNotification(
|
toastNotification(
|
||||||
@ -100,7 +100,8 @@ const DraftsContainer = ({ currentAccount, intl, navigation, dispatch }) => {
|
|||||||
_getDrafts();
|
_getDrafts();
|
||||||
_getSchedules();
|
_getSchedules();
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch((error) => {
|
||||||
|
console.warn("Failed to move scheduled post to drafts")
|
||||||
dispatch(toastNotification(intl.formatMessage({ id: 'alert.fail' })));
|
dispatch(toastNotification(intl.formatMessage({ id: 'alert.fail' })));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -13,8 +13,8 @@ import {
|
|||||||
uploadImage,
|
uploadImage,
|
||||||
addDraft,
|
addDraft,
|
||||||
updateDraft,
|
updateDraft,
|
||||||
schedule,
|
|
||||||
getDrafts,
|
getDrafts,
|
||||||
|
addSchedule,
|
||||||
} from '../../../providers/ecency/ecency';
|
} from '../../../providers/ecency/ecency';
|
||||||
import { toastNotification, setRcOffer } from '../../../redux/actions/uiAction';
|
import { toastNotification, setRcOffer } from '../../../redux/actions/uiAction';
|
||||||
import {
|
import {
|
||||||
@ -938,19 +938,14 @@ class EditorContainer extends Component {
|
|||||||
beneficiaries: beneficiaries,
|
beneficiaries: beneficiaries,
|
||||||
});
|
});
|
||||||
|
|
||||||
schedule(
|
addSchedule(
|
||||||
data.author,
|
|
||||||
data.fields.title,
|
|
||||||
data.permlink,
|
data.permlink,
|
||||||
data.jsonMeta,
|
data.fields.title,
|
||||||
data.fields.tags,
|
|
||||||
data.fields.body,
|
data.fields.body,
|
||||||
'',
|
data.jsonMeta,
|
||||||
'',
|
|
||||||
data.scheduleDate,
|
|
||||||
options,
|
options,
|
||||||
)
|
data.scheduleDate,
|
||||||
.then(() => {
|
) .then(() => {
|
||||||
this.setState({
|
this.setState({
|
||||||
isPostSending: false,
|
isPostSending: false,
|
||||||
});
|
});
|
||||||
@ -977,7 +972,8 @@ class EditorContainer extends Component {
|
|||||||
});
|
});
|
||||||
}, 3000);
|
}, 3000);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((error) => {
|
||||||
|
console.warn("Failed to schedule post", error);
|
||||||
this.setState({
|
this.setState({
|
||||||
isPostSending: false,
|
isPostSending: false,
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user