Files
frontend-app-authoring/src/editors/hooks.js
Ben Warzeski 09e9d865c2 Chore: Test coverage hunt (#36)
* chore: add brand mocking in gallery view

* feat: dev gallery app

* chore: link mock block ids to real block type api

* feat: image settings page features

* chore: more tests

* chore: keystore util and more testing

* chore: more tests

* chore: re-install lint plugin...

* chore: lint fixes

* chore: moar tests

* chore: remove brand from module.config and link gallery to edx.org brand
2022-03-24 11:15:32 -04:00

46 lines
1.1 KiB
JavaScript

import {
useRef, useEffect, useCallback, useState,
} from 'react';
import { StrictDict } from './utils';
import * as module from './hooks';
export const state = StrictDict({
refReady: (val) => useState(val),
});
export const initializeApp = ({ initialize, data }) => useEffect(
() => initialize(data),
[],
);
export const prepareEditorRef = () => {
const editorRef = useRef(null);
const setEditorRef = useCallback((ref) => {
editorRef.current = ref;
}, []);
const [refReady, setRefReady] = module.state.refReady(false);
useEffect(() => setRefReady(true), []);
return { editorRef, refReady, setEditorRef };
};
export const navigateTo = (destination) => {
window.location.assign(destination);
};
export const navigateCallback = (destination) => () => module.navigateTo(destination);
export const saveBlock = ({
editorRef,
returnUrl,
saveFunction,
}) => {
saveFunction({
returnToUnit: module.navigateCallback(returnUrl),
content: editorRef.current.getContent(),
});
};
// for toast onClose to avoid console warnings
export const nullMethod = () => {};