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
| Function | Lines | Complexity | Covered | CRAP | Mutation |
|---|---|---|---|---|---|
| useEditorLayout | 9 to 29 | 1 | 0% | OkCRAP 2 | No data: mutation testing has not run on this repo yet |
| <anonymous:12> | 12 to 19 | 5 | 0% | WatchCRAP 30 | No data: mutation testing has not run on this repo yet |
| chooseLayout | 20 to 27 | 2 | 0% | WatchCRAP 6 | No 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];
}