Skip to content

Commit

Permalink
fix: added title content updation with settings save button #529
Browse files Browse the repository at this point in the history
fixed and added title and content updation with post settings save
  • Loading branch information
jasurobo committed Jan 11, 2022
1 parent 87e3f8e commit 6f90766
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
1 change: 0 additions & 1 deletion component/myblogs/WriteNav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ export default function WriteNav({
meta_title: metaTitle,
meta_description: metaDes,
slug: postUrl,
mobiledoc: currentPost.mobiledoc
};
if (settingsData.slug === "") {
delete settingsData.slug;
Expand Down
60 changes: 37 additions & 23 deletions pages/posts/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import PostService from "../../services/PostService";
import { editorUrl } from "../../config/config";
import { getCookieValue } from "../../lib/cookie";
import notify from "../../lib/notify";
import { data } from "remark";

const TARGET = editorUrl;

Expand Down Expand Up @@ -150,19 +151,18 @@ export default function Write({
TARGET
);
} catch (err) {
notify(err?.response?.data?.message ?? err?.message, 'error');
notify(err?.response?.data?.message ?? err?.message, "error");
}
}


async function updatePostById(updateData, newPostId) {
try {
const res = await PostService.updatePostById(updateData, newPostId);
if (res) {
notify(res?.message);
}
} catch (err) {
notify(err?.response?.data?.message ?? err?.message, 'error');
notify(err?.response?.data?.message ?? err?.message, "error");
}
}

Expand All @@ -178,39 +178,53 @@ export default function Write({
if (postId) {
//updatePost
const newUpdatedPost = {
status: 'drafted',
status: "drafted",
title: title,
mobiledoc: newMobiledoc,
mobiledoc: newMobiledoc
};
updatePostById(postId, newUpdatedPost);
notify();
updatePostById(postId, newUpdatedPost);
notify();
}
}, 500);

};

async function submitForReview() {
iframeRef.current.contentWindow.postMessage({ msg: "savePost" }, TARGET);
setTimeout(() => {
//change status to "pending" if submitted for review
const newMobiledoc = postElement?.current.scratch;
const title = postElement?.current.titleScratch || "[Untitled]";
try {
const statusUpdate = {
status: "pending",
title: title,
mobiledoc: newMobiledoc,
};
updatePostById(postId,statusUpdate);
} catch (err) {
notify(err?.response?.data?.message ?? err?.message, 'error');
}
}, 500);
//change status to "pending" if submitted for review
const newMobiledoc = postElement?.current.scratch;
const title = postElement?.current.titleScratch || "[Untitled]";
try {
const statusUpdate = {
status: "pending",
title: title,
mobiledoc: newMobiledoc
};
updatePostById(postId, statusUpdate);
} catch (err) {
notify(err?.response?.data?.message ?? err?.message, "error");
}
}, 500);
}

const getSettings = async (settingsData) => {
const newMobiledoc = postElement?.current?.scratch;
const title = postElement?.current?.titleScratch || "[Untitled]";

const settingsParam = {
banner_image: settingsData.banner_image,
og_description: settingsData.og_description,
meta_title: settingsData.meta_title,
meta_description: settingsData.meta_description,
slug: settingsData.slug,
title: title,
mobiledoc: newMobiledoc
};
if (settingsParam.slug === "") {
delete settingsParam.slug;
}
if (postId) {
updatePostById(postId,settingsData);
updatePostById(postId, settingsParam);
}
};

Expand Down

0 comments on commit 6f90766

Please sign in to comment.