Skip to content

Commit

Permalink
feat: Save editor settings on local storage; restore on page load
Browse files Browse the repository at this point in the history
  • Loading branch information
munshkr committed Oct 26, 2024
1 parent 5f94c1b commit 7c643d5
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions packages/web/src/routes/session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ declare global {

const panicCodes = panicCodesUntyped as { [target: string]: string };

const defaultEditorSettings: EditorSettings = {
lineNumbers: false,
vimMode: false,
fontFamily: "Inconsolata",
theme: "oneDark",
wrapText: true,
};

interface SessionLoaderParams {
name: string;
}
Expand Down Expand Up @@ -88,15 +96,24 @@ export function Component() {
const [documents, setDocuments] = useState<Document[]>([]);
const [hidden, setHidden] = useState<boolean>(false);

// Editor settings
const [editorSettings, setEditorSettings] = useState<EditorSettings>({
lineNumbers: false,
vimMode: false,
fontFamily: "Inconsolata",
theme: "oneDark",
wrapText: true,
// Editor settings: Try to restore from local storage or use default settings
const [editorSettings, setEditorSettings] = useState<EditorSettings>(() => {
const savedSettings = localStorage.getItem("editor-settings");
if (savedSettings) {
try {
return JSON.parse(savedSettings);
} catch (error) {
console.error("Error parsing saved editor settings:", error);
}
}
return defaultEditorSettings;
});

// Save editor settings to local storage
useEffect(() => {
localStorage.setItem("editor-settings", JSON.stringify(editorSettings));
}, [editorSettings]);

const [messagesPanelExpanded, setMessagesPanelExpanded] =
useState<boolean>(false);
const [messagesCount, setMessagesCount] = useState<number>(0);
Expand Down

0 comments on commit 7c643d5

Please sign in to comment.