Persist full-width as user preference when toggled

closes #5562
This commit is contained in:
Tom Moor
2023-10-28 13:03:38 -04:00
parent 92ba095124
commit f2df25d115
3 changed files with 14 additions and 2 deletions

View File

@@ -9,6 +9,7 @@ import { toast } from "sonner";
import styled from "styled-components";
import breakpoint from "styled-components-breakpoint";
import { s, ellipsis } from "@shared/styles";
import { UserPreference } from "@shared/types";
import { getEventFiles } from "@shared/utils/files";
import Document from "~/models/Document";
import ContextMenu from "~/components/ContextMenu";
@@ -324,7 +325,13 @@ function DocumentMenu({
label={t("Full width")}
checked={document.fullWidth}
onChange={(ev) => {
document.fullWidth = ev.currentTarget.checked;
const fullWidth = ev.currentTarget.checked;
user.setPreference(
UserPreference.FullWidthDocuments,
fullWidth
);
void user.save();
document.fullWidth = fullWidth;
void document.save();
}}
/>

View File

@@ -4,6 +4,7 @@ import { useEffect } from "react";
import { useTranslation } from "react-i18next";
import { useHistory, useLocation, useRouteMatch } from "react-router-dom";
import { toast } from "sonner";
import { UserPreference } from "@shared/types";
import CenteredContent from "~/components/CenteredContent";
import Flex from "~/components/Flex";
import PlaceholderDocument from "~/components/PlaceholderDocument";
@@ -42,7 +43,9 @@ function DocumentNew({ template }: Props) {
const document = await documents.create({
collectionId: collection?.id,
parentDocumentId,
fullWidth: parentDocument?.fullWidth,
fullWidth:
parentDocument?.fullWidth ||
user.getPreference(UserPreference.FullWidthDocuments),
templateId: query.get("templateId") ?? undefined,
template,
title: "",

View File

@@ -116,6 +116,8 @@ export enum UserPreference {
CodeBlockLineNumers = "codeBlockLineNumbers",
/** Whether documents have a separate edit mode instead of always editing. */
SeamlessEdit = "seamlessEdit",
/** Whether documents should start in full-width mode. */
FullWidthDocuments = "fullWidthDocuments",
}
export type UserPreferences = { [key in UserPreference]?: boolean };