Skip to content

Commit

Permalink
fix #7 and attempt on #6
Browse files Browse the repository at this point in the history
  • Loading branch information
GraemeFulton committed Aug 26, 2024
1 parent 2da8687 commit 1b19800
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 28 deletions.
6 changes: 5 additions & 1 deletion src/Editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const Editor = ({
extensions,
editorSettings,
autosave,
router
}) => {
// const { user } = useUser({
// redirectIfFound: false,
Expand Down Expand Up @@ -135,7 +136,10 @@ const Editor = ({
});

useEffect(() => {
setShouldUpdateContent(true);
if (postObject?.id !== undefined && typeof postObject?.id !== 'undefined' && postObject?.id !== false) {
console.log('--',postObject?.id)
setShouldUpdateContent(true);
}
}, [postObject?.id]);

useEffect(() => {
Expand Down
3 changes: 1 addition & 2 deletions src/Editor/UI/PublishChangesDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ export const PublishChangesDialog = ({

const onSubmit = async () => {
setSubmitting(true);
forceSave({ publish: true, editor: editor });

await forceSave({ publish: true, editor: editor });
setSubmitOpen(false);
};

Expand Down
62 changes: 40 additions & 22 deletions src/Editor/UI/PublishDialogButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ export const PublishDialogButton = ({
const modalText = {
publish: {
title: "Save and Publish",
description:
"Publish your post and make it live.",
description: "Publish your post and make it live.",
button: "Publish",
},
unpublish: {
Expand All @@ -43,7 +42,7 @@ export const PublishDialogButton = ({
button: "Unpublish",
},
revert: {
title: "Revert to Draft",
title: "Revert to Draft",
description:
"Your story is currently published. Reverting to draft will unpublish it so it is no longer visible to the public.",
button: "Revert to Draft",
Expand All @@ -63,14 +62,19 @@ export const PublishDialogButton = ({

const onSubmit = async () => {
setSubmitting(true);
if (!enablePublishingFlow && (postObject?.status == POST_STATUSES.DRAFT || postObject?.status == null || postObject?.status == undefined)) {
forceSave({ publish: true, editor: editor });
if (
!enablePublishingFlow &&
(postObject?.status == POST_STATUSES.DRAFT ||
postObject?.status == null ||
postObject?.status == undefined)
) {
await forceSave({ publish: true, editor: editor });
} else if (
!enablePublishingFlow &&
(postObject?.status == POST_STATUSES.PUBLISHED ||
postObject?.status == POST_STATUSES.PENDING)
) {
forceSave({ unpublish: true, editor: editor });
await forceSave({ unpublish: true, editor: editor });
} else {
onSave({ forReview: true });
}
Expand All @@ -89,9 +93,11 @@ export const PublishDialogButton = ({
}, [submitOpen]);

const disabled =
(!(!enablePublishingFlow &&
(postObject?.status == POST_STATUSES.PUBLISHED ||
postObject?.status == POST_STATUSES.PENDING))) &&
!(
!enablePublishingFlow &&
(postObject?.status == POST_STATUSES.PUBLISHED ||
postObject?.status == POST_STATUSES.PENDING)
) &&
(!canPublish ||
((postObject?.status == POST_STATUSES.PENDING ||
postObject?.status == POST_STATUSES.PUBLISHED) &&
Expand Down Expand Up @@ -124,7 +130,7 @@ export const PublishDialogButton = ({
disabled ? "opacity-50 cursor-not-allowed" : ""
} ${className} !rounded-full`}
>
{!enablePublishingFlow && (postObject?.status == POST_STATUSES.PENDING)
{!enablePublishingFlow && postObject?.status == POST_STATUSES.PENDING
? "Revert to Draft"
: !enablePublishingFlow &&
postObject?.status == POST_STATUSES.PUBLISHED
Expand All @@ -142,22 +148,28 @@ export const PublishDialogButton = ({
<DialogContentLarge variant="big">
<div>
<DialogTitle>
{(!enablePublishingFlow && postObject?.status == POST_STATUSES.PENDING)
{!enablePublishingFlow &&
postObject?.status == POST_STATUSES.PENDING
? modalText.revert.title
: (!enablePublishingFlow && postObject?.status == POST_STATUSES.PUBLISHED)
: !enablePublishingFlow &&
postObject?.status == POST_STATUSES.PUBLISHED
? modalText.revert.title
: (!enablePublishingFlow && postObject?.status == POST_STATUSES.DRAFT)
? modalText.publish.title
: !enablePublishingFlow &&
postObject?.status == POST_STATUSES.DRAFT
? modalText.publish.title
: modalText.submit.title}
</DialogTitle>
<DialogDescription>
<p className="mb-4">
{(!enablePublishingFlow && postObject?.status == POST_STATUSES.PENDING)
{!enablePublishingFlow &&
postObject?.status == POST_STATUSES.PENDING
? modalText.revert.description
: (!enablePublishingFlow && postObject?.status == POST_STATUSES.PUBLISHED)
: !enablePublishingFlow &&
postObject?.status == POST_STATUSES.PUBLISHED
? modalText.revert.description
: (!enablePublishingFlow && postObject?.status == POST_STATUSES.DRAFT)
? modalText.publish.description
: !enablePublishingFlow &&
postObject?.status == POST_STATUSES.DRAFT
? modalText.publish.description
: modalText.submit.description}
</p>
</DialogDescription>
Expand All @@ -172,13 +184,19 @@ export const PublishDialogButton = ({
>
{submitting ? (
<Spinner size="sm" className="mx-auto p-1 cursor-loading " />
) : (!enablePublishingFlow && postObject?.status == POST_STATUSES.PENDING) ? (
) : !enablePublishingFlow &&
postObject?.status == POST_STATUSES.PENDING ? (
modalText.revert.button
) : (!enablePublishingFlow && postObject?.status == POST_STATUSES.PUBLISHED) ? (
) : !enablePublishingFlow &&
postObject?.status == POST_STATUSES.PUBLISHED ? (
modalText.unpublish.button
) : (!enablePublishingFlow && (postObject?.status == POST_STATUSES.DRAFT || postObject?.status == null || postObject?.status == undefined)) ? (
) : !enablePublishingFlow &&
(postObject?.status == POST_STATUSES.DRAFT ||
postObject?.status == null ||
postObject?.status == undefined) ? (
modalText.publish.button
) : (!enablePublishingFlow && postObject?.status == POST_STATUSES.PUBLISHED) ? (
) : !enablePublishingFlow &&
postObject?.status == POST_STATUSES.PUBLISHED ? (
"Publish changes"
) : (
"Submit"
Expand Down
10 changes: 7 additions & 3 deletions src/EditorWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,14 @@ export default function EditorWrapper(props) {
* bypass debounce and save immediately
* @param {*} param0
*/
const forceSave = ({ editor, json, forReview, publish, unpublish }) => {
const forceSave = async ({ editor, json, forReview, publish, unpublish }) => {
setSaving(false);
if (publish !== undefined || unpublish !== undefined) {
_savePost({ editor, forReview, forced: true, publish, unpublish });
const res = await _savePost({ editor, forReview, forced: true, publish, unpublish });
return res
} else {
_savePost({ editor, forReview, forced: true });
const res = await _savePost({ editor, forReview, forced: true });
return res
}
};

Expand Down Expand Up @@ -483,6 +485,7 @@ export default function EditorWrapper(props) {
extensions,
editorSettings,
autosave: mergedProps.autosave,
router,
...childProps, // Spread custom props to override defaults
})
) : (
Expand Down Expand Up @@ -517,6 +520,7 @@ export default function EditorWrapper(props) {
extensions={extensions}
editorSettings={editorSettings}
autosave={mergedProps.autosave}
router={router}
/>
)}
</div>
Expand Down

0 comments on commit 1b19800

Please sign in to comment.