Last active
April 3, 2025 04:57
-
-
Save tecoholic/094b86944be692a165780a33b58380b4 to your computer and use it in GitHub Desktop.
Unit page header slot with buttons to scroll to the corresponding XBlock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {useState} from "react"; | |
import {PLUGIN_OPERATIONS, DIRECT_PLUGIN} from '@openedx/frontend-plugin-framework'; | |
import {Button, Sheet} from '@openedx/paragon'; | |
import {useIframe} from "CourseAuthoring/course-unit/context/hooks"; | |
const UnitPageSidebar = ({verticalBlocks}) => { | |
const [show, setShow] = useState(false); | |
const {sendMessageToIframe} = useIframe(); | |
return ( | |
<> | |
<Button onClick={() => setShow(!show)}>Sidebar</Button> | |
<Sheet | |
position="right" | |
show={show} | |
blocking={false} | |
onClose={() => setShow(false)} | |
> | |
{verticalBlocks.map((block) => ( | |
<Button | |
key={block.id} | |
className="my-2" | |
block onClick={ | |
() => sendMessageToIframe("scrollToXBlock", {locator: block.id}) | |
}> | |
{block.name} | |
</Button> | |
))} | |
</Sheet> | |
</> | |
) | |
} | |
// Load environment variables from .env file | |
const config = { | |
...process.env, | |
pluginSlots: { | |
course_unit_header_actions_slot: { | |
keepDefault: true, | |
plugins: [ | |
{ | |
op: PLUGIN_OPERATIONS.Insert, | |
widget: { | |
id: 'unit-analytics', | |
type: DIRECT_PLUGIN, | |
priority: 51, | |
RenderWidget: UnitPageSidebar, | |
} | |
}, | |
] | |
}, | |
} | |
}; | |
export default config; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git i/cms/static/js/views/pages/container.js w/cms/static/js/views/pages/container.js | |
index 684bd0ab7d..07fdb580c1 100644 | |
--- i/cms/static/js/views/pages/container.js | |
+++ w/cms/static/js/views/pages/container.js | |
@@ -169,6 +169,9 @@ function($, _, Backbone, gettext, BasePage, | |
case 'addXBlock': | |
this.createComponent(this, xblockElement, data); | |
break; | |
+ case 'scrollToXBlock': | |
+ document.getElementById(data.payload.locator).scrollIntoView({behavior: "smooth"}); | |
+ break; | |
default: | |
console.warn('Unhandled message type:', data.type); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment