🐛 fix broken useState

This commit is contained in:
ghalestrilo 2020-07-20 18:37:50 -03:00
parent 627cfbf709
commit 234c4ffe14

View file

@ -83,17 +83,11 @@ const getConsoleFeedStyle = (theme, times, fontSize) => {
} }
}; };
// 1 . FIXME: Object is not a function 🤷🏻
const Console = () => { const Console = () => {
const consoleEvents = useSelector(state => state.console); const consoleEvents = useSelector(state => state.console);
const isExpanded = useSelector(state => state.ide.consoleIsExpanded); const isExpanded = useSelector(state => state.ide.consoleIsExpanded);
const { theme, fontSize } = useSelector(state => state.preferences); const { theme, fontSize } = useSelector(state => state.preferences);
const [cm, setCm] = useState({});
// 2. FIXME: Console is not opening/closing, and I suspect it has to do with this
useDidUpdate(() => { if (cm) cm.scrollTop = cm.scrollHeight; });
const { const {
collapseConsole, expandConsole, clearConsole, dispatchConsoleEvent collapseConsole, expandConsole, clearConsole, dispatchConsoleEvent
} = bindActionCreators({ ...IDEActions, ...ConsoleActions }, useDispatch()); } = bindActionCreators({ ...IDEActions, ...ConsoleActions }, useDispatch());
@ -101,11 +95,23 @@ const Console = () => {
useDidUpdate(() => { useDidUpdate(() => {
clearConsole(); clearConsole();
dispatchConsoleEvent(consoleEvents); dispatchConsoleEvent(consoleEvents);
}, [theme, fontSize]); }, [theme, fontSize]); //
// const [consoleMessages, setConsoleMessages] = useState({}); // const [consoleMessages, setConsoleMessages] = useState({});
// this.consoleMessages.scrollTop = this.consoleMessages.scrollHeight; // this.consoleMessages.scrollTop = this.consoleMessages.scrollHeight;
// const clearConsole = () => {};
// const collapseConsole = () => {};
// const expandConsole = () => {};
// const isExpanded = true;
// const fontSize = 16;
// const theme = {};
// // 2. FIXME: Console is not opening/closing, and I suspect it has to do with this
const cm = useRef({});
useDidUpdate(() => { if (cm.current) cm.current.scrollTop = cm.current.scrollHeight; });
const consoleClass = classNames({ const consoleClass = classNames({
'preview-console': true, 'preview-console': true,
@ -132,7 +138,7 @@ const Console = () => {
</button> </button>
</div> </div>
</header> </header>
<div ref={element => setCm(element)} className="preview-console__messages"> <div ref={cm} className="preview-console__messages">
{consoleEvents.map((consoleEvent) => { {consoleEvents.map((consoleEvent) => {
const { method, times } = consoleEvent; const { method, times } = consoleEvent;
return ( return (