Fix rendering issues with plugins
Plugins wouldn't render if the number of hooks changed. This was because the dynamic content substitution would create variable number of hooks. This has been fixed by creating an element instead of placing content.
This commit is contained in:
parent
cb8f6daccc
commit
e1c42c90d5
|
@ -3,19 +3,19 @@ import { useSelector, useDispatch } from "react-redux";
|
||||||
import { Box, Button, Clock } from "grommet";
|
import { Box, Button, Clock } from "grommet";
|
||||||
|
|
||||||
import { setPlugin, selectCore } from "./coreSlice";
|
import { setPlugin, selectCore } from "./coreSlice";
|
||||||
import * as plugins from "./plugins";
|
import plugins from "./plugins";
|
||||||
|
|
||||||
function Core() {
|
function Core() {
|
||||||
const coreState = useSelector(selectCore);
|
const coreState = useSelector(selectCore);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const plugin = plugins.default[coreState.plugin];
|
const plugin = plugins[coreState.plugin];
|
||||||
const props = {
|
const props = {
|
||||||
data: coreState.data,
|
data: coreState.data,
|
||||||
close: () => dispatch(setPlugin(false))
|
close: () => dispatch(setPlugin(false))
|
||||||
};
|
};
|
||||||
const dummyButtons = ["Maps", "Home Devices", "Phone"];
|
const dummyButtons = ["Maps", "Home Devices", "Phone"];
|
||||||
return <>
|
return <>
|
||||||
{plugin ? plugin(props) : (
|
{plugin ? React.createElement(plugin, props, null) : (
|
||||||
<Box
|
<Box
|
||||||
align="center"
|
align="center"
|
||||||
background="light-1"
|
background="light-1"
|
||||||
|
|
|
@ -17,8 +17,8 @@ function WebSocketProvider({ children }) {
|
||||||
socket = io.connect(WS_BASE);
|
socket = io.connect(WS_BASE);
|
||||||
|
|
||||||
socket.on("switchPlugin", (payload) => {
|
socket.on("switchPlugin", (payload) => {
|
||||||
|
dispatch(setData(payload.data || {}));
|
||||||
dispatch(setPlugin(payload.plugin));
|
dispatch(setPlugin(payload.plugin));
|
||||||
dispatch(setData(payload.data));
|
|
||||||
if (payload.time) {
|
if (payload.time) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
dispatch(setData({}));
|
dispatch(setData({}));
|
||||||
|
|
Loading…
Reference in New Issue