Skip to the content

Capsid menu

app/components/editor/layout.ts

25 lines and 3 functions in DrDustinEdwards/carrel, at commit d5d5e82 on 2026-10-24. This file on GitHub.

Functions

The functions of layout.ts
FunctionLinesComplexityCoveredCRAPMutation
useEditorLayout9 to 2910%OkCRAP 2No data: mutation testing has not run on this repo yet
<anonymous:12>12 to 1950%WatchCRAP 30No data: mutation testing has not run on this repo yet
chooseLayout20 to 2720%WatchCRAP 6No data: mutation testing has not run on this repo yet

Imports

It imports no other module of this repo. Imported by app/routes/editor.tsx.

Source

// The editor's layout (Write, Split, Preview), remembered in this browser.

import { useEffect, useState } from "react";

export type Layout = "write" | "split" | "preview";

const LAYOUT_KEY = "carrel:editor-layout";

export function useEditorLayout(): [Layout, (next: Layout) => void] {
  const [layout, setLayout] = useState<Layout>("write");
  // Remembered in this browser; read after mount so the server and the first client paint agree.
  useEffect(() => {
    try {
      const stored = window.localStorage.getItem(LAYOUT_KEY);
      if (stored === "write" || stored === "split" || stored === "preview") setLayout(stored);
    } catch {
      // Storage disabled: Write, the default.
    }
  }, []);
  const chooseLayout = (next: Layout) => {
    setLayout(next);
    try {
      window.localStorage.setItem(LAYOUT_KEY, next);
    } catch {
      // As above.
    }
  };
  return [layout, chooseLayout];
}