migrated scheduled posts apis

This commit is contained in:
Nouman Tahir 2021-07-02 16:47:43 +05:00
parent 40420ef9e4
commit 942633583b
3 changed files with 105 additions and 46 deletions

View File

@ -396,45 +396,107 @@ export const searchTag = (q = '', limit = 20, random = 0) =>
});
});
// Schedule
export const schedule = (
user,
title,
permlink,
json,
tags,
body,
operationType,
upvote,
scheduleDate,
options = null,
) =>
api
.post('/schedules', {
username: 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,
permlink,
meta: json,
meta,
body,
schedule: scheduleDate,
options,
reblog: 0,
})
.then((resp) => resp.data)
.catch((error) => bugsnag.notify(error));
}
const response = await ecencyApi
.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
.get(`/schedules/${username}`)
.then((resp) => resp.data)
.catch((error) => bugsnag.notify(error));
/**
* Fetches all scheduled posts against current user
* @returns array of app scheduled posts
*/
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
// Images
/**
* ************************************
* IMAGES ECENCY APIS IMPLEMENTATION
* ************************************
*/
export const getImages = async () => {

View File

@ -8,8 +8,8 @@ import {
getDrafts,
removeDraft,
getSchedules,
removeSchedule,
moveSchedule,
moveScheduledToDraft,
deleteScheduledPost,
} from '../../../providers/ecency/ecency';
import { toastNotification } from '../../../redux/actions/uiAction';
@ -38,7 +38,7 @@ const DraftsContainer = ({ currentAccount, intl, navigation, dispatch }) => {
const _getSchedules = () => {
setIsLoading(true);
getSchedules(currentAccount.name)
getSchedules()
.then((data) => {
setSchedules(_sortDataS(data));
setIsLoading(false);
@ -75,7 +75,7 @@ const DraftsContainer = ({ currentAccount, intl, navigation, dispatch }) => {
};
const _removeSchedule = (id) => {
removeSchedule(currentAccount.name, id)
deleteScheduledPost(id)
.then((res) => {
const newSchedules = [...schedules].filter((schedule) => schedule._id !== id);
@ -87,7 +87,7 @@ const DraftsContainer = ({ currentAccount, intl, navigation, dispatch }) => {
};
const _moveScheduleToDraft = (id) => {
moveSchedule(id, currentAccount.name)
moveScheduledToDraft(id)
.then((res) => {
dispatch(
toastNotification(
@ -100,7 +100,8 @@ const DraftsContainer = ({ currentAccount, intl, navigation, dispatch }) => {
_getDrafts();
_getSchedules();
})
.catch(() => {
.catch((error) => {
console.warn("Failed to move scheduled post to drafts")
dispatch(toastNotification(intl.formatMessage({ id: 'alert.fail' })));
});
};

View File

@ -13,8 +13,8 @@ import {
uploadImage,
addDraft,
updateDraft,
schedule,
getDrafts,
addSchedule,
} from '../../../providers/ecency/ecency';
import { toastNotification, setRcOffer } from '../../../redux/actions/uiAction';
import {
@ -938,19 +938,14 @@ class EditorContainer extends Component {
beneficiaries: beneficiaries,
});
schedule(
data.author,
data.fields.title,
addSchedule(
data.permlink,
data.jsonMeta,
data.fields.tags,
data.fields.title,
data.fields.body,
'',
'',
data.scheduleDate,
data.jsonMeta,
options,
)
.then(() => {
data.scheduleDate,
) .then(() => {
this.setState({
isPostSending: false,
});
@ -977,7 +972,8 @@ class EditorContainer extends Component {
});
}, 3000);
})
.catch((err) => {
.catch((error) => {
console.warn("Failed to schedule post", error);
this.setState({
isPostSending: false,
});