Skip to content

Commit

Permalink
answer block highlight dotted and publish quiz on publish page
Browse files Browse the repository at this point in the history
  • Loading branch information
randhirexpresstech committed Mar 26, 2024
1 parent 8798b40 commit 630d13f
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 31 deletions.
20 changes: 20 additions & 0 deletions blocks/block.php
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,26 @@ public function save_quiz( WP_REST_Request $request ) {
$mlwQuizMasterNext->quizCreator->edit_quiz_name( $quiz_id, $quiz_name, $post_id );
}
}

//Update status
if ( ! empty( $quiz_id ) && ! empty( $post_id ) ) {

//Default post status
$post_status = 'publish';

//page status which conatin quiz
if ( ! empty( $_POST['post_status'] )) {
$post_status = sanitize_key( wp_unslash( $_POST['post_status'] ) );
}

//Update quiz status
if ( 'publish' === $post_status ) {
wp_update_post( array(
'ID' => $post_id,
'post_status' => 'publish',
) );
}
}

//Save Pages
if ( ! empty( $_POST['quizData']['pages'] ) ) {
Expand Down
4 changes: 4 additions & 0 deletions blocks/build/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
"quiz-master-next/quizID": "quizID",
"quiz-master-next/quizAttr": "quizAttr"
},
"usesContext": [
"postId",
"postStatus"
],
"example": {},
"supports": {
"html": false
Expand Down
2 changes: 1 addition & 1 deletion blocks/build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-editor', 'wp-element', 'wp-html-entities', 'wp-i18n', 'wp-notices'), 'version' => '3bec0faae5335384534d');
<?php return array('dependencies' => array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-editor', 'wp-element', 'wp-html-entities', 'wp-i18n', 'wp-notices'), 'version' => '9ae62c1e6dbc6a16c846');
2 changes: 1 addition & 1 deletion blocks/build/index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion blocks/build/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion blocks/build/question/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('wp-api-fetch', 'wp-blob', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-notices'), 'version' => '8c84bc3be26cb4988adf');
<?php return array('dependencies' => array('wp-api-fetch', 'wp-blob', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-notices'), 'version' => '45906d9cb21e070d8451');
2 changes: 1 addition & 1 deletion blocks/build/question/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions blocks/src/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"quiz-master-next/quizID": "quizID",
"quiz-master-next/quizAttr": "quizAttr"
},
"usesContext": [ "postId", "postStatus" ],
"example": {},
"supports": {
"html": false
Expand Down
2 changes: 1 addition & 1 deletion blocks/src/component/icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const warningIcon = () => (
export const plusIcon = () => (
<Icon
icon={ () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" ariaHidden="true" focusable="false"><path d="M18 11.2h-5.2V6h-1.6v5.2H6v1.6h5.2V18h1.6v-5.2H18z"></path></svg>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"><path d="M18 11.2h-5.2V6h-1.6v5.2H6v1.6h5.2V18h1.6v-5.2H18z"></path></svg>
) }
/>
);
19 changes: 18 additions & 1 deletion blocks/src/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export default function Edit( props ) {
return null;
}

const { className, attributes, setAttributes, isSelected, clientId } = props;
const { className, attributes, setAttributes, isSelected, clientId, context } = props;

const page_post_id = context['postId'];
const { createNotice } = useDispatch( noticesStore );
//quiz attribute
const globalQuizsetting = qsmBlockData.globalQuizsetting;
Expand Down Expand Up @@ -67,6 +69,10 @@ export default function Edit( props ) {
return isSavingPost() && ! isAutosavingPost();
}, [] );

const editorSelectors = useSelect( ( select ) => {
return select( 'core/editor' );
}, [] );

const { getBlock } = useSelect( blockEditorStore );

/**Initialize block from server */
Expand Down Expand Up @@ -478,11 +484,22 @@ export default function Edit( props ) {
let quizData = getQuizDataToSave();
//save quiz status
setSaveQuiz( true );

//post status
let post_status = 'publish';
if ( ! qsmIsEmpty( editorSelectors ) ) {
post_status = editorSelectors.getEditedPostAttribute( 'status' );
}
if ( qsmIsEmpty( post_status ) ) {
post_status = 'publish';
}

quizData = qsmFormData({
'save_entire_quiz': '1',
'quizData': JSON.stringify( quizData ),
'qsm_block_quiz_nonce' : qsmBlockData.nonce,
'page_post_id' : qsmIsEmpty( page_post_id ) ? 0: page_post_id ,
'post_status' : post_status,
"nonce": qsmBlockData.saveNonce,//save pages nonce
});

Expand Down
8 changes: 8 additions & 0 deletions blocks/src/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,20 @@

/*Question options*/
.wp-block-qsm-quiz-answer-option{
padding-left: 0.8rem;
&.block-editor-block-list__block.is-highlighted:after{
box-shadow: none;
border: 2px dotted #c3c5cc;
}
input:disabled{
border-color: inherit;
}
input[type="radio"]:disabled, input[type="checkbox"]:disabled{
opacity: 1;
}
.qsm-question-answer-option.rich-text{
margin-left: 5px;
}
}
.qsm-question-answer-option{
color: $qsm_primary_color;
Expand Down
25 changes: 1 addition & 24 deletions blocks/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,4 @@ registerBlockType( metadata.name, {
*/
edit: Edit,
save: save,
} );


const withMyPluginControls = createHigherOrderComponent( ( BlockEdit ) => {
return ( props ) => {
const { name, className, attributes, setAttributes, isSelected, clientId, context } = props;
if ( 'core/group' !== name ) {
return <BlockEdit key="edit" { ...props } />;
}

console.log("props",props);
return (
<>
<BlockEdit key="edit" { ...props } />
</>
);
};
}, 'withMyPluginControls' );

wp.hooks.addFilter(
'editor.BlockEdit',
'my-plugin/with-inspector-controls',
withMyPluginControls
);
} );

0 comments on commit 630d13f

Please sign in to comment.