Skip to content
Snippets Groups Projects
Select Git revision
  • 0f7cef5afae6d461a192511ccf16d518f8410738
  • master default protected
  • 1-issue-czi-wtf
  • update-deps
4 results

useLayout.ts

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    useLayout.ts 821 B
    import {useEffect, useRef, useState} from "react";
    import {LayoutConfig} from "../types/LayoutConfig";
    import {LayoutService} from "../services/LayoutService";
    
    export default function useLayout(): LayoutConfig | null {
      const currentId = useRef<string | null>(null);
      const [layout, setLayout] = useState<LayoutConfig | null>(null);
    
      useEffect(() => {
        LayoutService.init().then(() => {
          const refresh = () => {
            const activeLayout = LayoutService.getActiveLayout();
    
            if(currentId.current !== activeLayout.id) {
              console.log("Switching from", currentId.current, "to", activeLayout.id)
              currentId.current = activeLayout.id;
              setLayout(activeLayout);
            }
          };
    
          window.setInterval(refresh, 10000);
          refresh();
        });
      }, []);
    
      return layout;
    }