mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: update memo related settings
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
import { Button, Divider, Input, Switch, Textarea } from "@mui/joy";
|
||||
import { Button, Switch, Textarea } from "@mui/joy";
|
||||
import { useState } from "react";
|
||||
import { toast } from "react-hot-toast";
|
||||
import { Link } from "react-router-dom";
|
||||
import { workspaceSettingServiceClient } from "@/grpcweb";
|
||||
import { WorkspaceSettingPrefix, useWorkspaceSettingStore } from "@/store/v1";
|
||||
import { WorkspaceGeneralSetting, WorkspaceMemoRelatedSetting } from "@/types/proto/api/v1/workspace_setting_service";
|
||||
import { WorkspaceGeneralSetting } from "@/types/proto/api/v1/workspace_setting_service";
|
||||
import { WorkspaceSettingKey } from "@/types/proto/store/workspace_setting";
|
||||
import { useTranslate } from "@/utils/i18n";
|
||||
import { showCommonDialog } from "../Dialog/CommonDialog";
|
||||
@ -17,11 +17,6 @@ const WorkspaceSection = () => {
|
||||
const [workspaceGeneralSetting, setWorkspaceGeneralSetting] = useState<WorkspaceGeneralSetting>(
|
||||
WorkspaceGeneralSetting.fromPartial(workspaceSettingStore.getWorkspaceSettingByKey(WorkspaceSettingKey.GENERAL)?.generalSetting || {}),
|
||||
);
|
||||
const [workspaceMemoRelatedSetting, setWorkspaceMemoRelatedSetting] = useState<WorkspaceMemoRelatedSetting>(
|
||||
WorkspaceMemoRelatedSetting.fromPartial(
|
||||
workspaceSettingStore.getWorkspaceSettingByKey(WorkspaceSettingKey.MEMO_RELATED)?.memoRelatedSetting || {},
|
||||
),
|
||||
);
|
||||
|
||||
const handleAllowSignUpChanged = async (value: boolean) => {
|
||||
const setting = { ...workspaceGeneralSetting, disallowSignup: !value };
|
||||
@ -104,56 +99,6 @@ const WorkspaceSection = () => {
|
||||
toast.success(t("message.update-succeed"));
|
||||
};
|
||||
|
||||
const handleDisablePublicMemosChanged = async (value: boolean) => {
|
||||
const update: WorkspaceMemoRelatedSetting = { ...workspaceMemoRelatedSetting, disallowPublicVisible: value };
|
||||
setWorkspaceMemoRelatedSetting(update);
|
||||
await workspaceSettingStore.setWorkspaceSetting({
|
||||
name: `${WorkspaceSettingPrefix}${WorkspaceSettingKey.MEMO_RELATED}`,
|
||||
memoRelatedSetting: update,
|
||||
});
|
||||
};
|
||||
|
||||
const handleMemoDisplayWithUpdatedTs = async (value: boolean) => {
|
||||
const update: WorkspaceMemoRelatedSetting = { ...workspaceMemoRelatedSetting, displayWithUpdateTime: value };
|
||||
setWorkspaceMemoRelatedSetting(update);
|
||||
await workspaceSettingStore.setWorkspaceSetting({
|
||||
name: `${WorkspaceSettingPrefix}${WorkspaceSettingKey.MEMO_RELATED}`,
|
||||
memoRelatedSetting: update,
|
||||
});
|
||||
};
|
||||
|
||||
const handleMemoEnableAutoCompact = async (value: boolean) => {
|
||||
const update: WorkspaceMemoRelatedSetting = { ...workspaceMemoRelatedSetting, enableAutoCompact: value };
|
||||
setWorkspaceMemoRelatedSetting(update);
|
||||
await workspaceSettingStore.setWorkspaceSetting({
|
||||
name: `${WorkspaceSettingPrefix}${WorkspaceSettingKey.MEMO_RELATED}`,
|
||||
memoRelatedSetting: update,
|
||||
});
|
||||
};
|
||||
|
||||
const handleMemoEnableDoubleClickToEdit = async (value: boolean) => {
|
||||
const update: WorkspaceMemoRelatedSetting = { ...workspaceMemoRelatedSetting, enableDoubleClickEdit: value };
|
||||
setWorkspaceMemoRelatedSetting(update);
|
||||
await workspaceSettingStore.setWorkspaceSetting({
|
||||
name: `${WorkspaceSettingPrefix}${WorkspaceSettingKey.MEMO_RELATED}`,
|
||||
memoRelatedSetting: update,
|
||||
});
|
||||
};
|
||||
|
||||
const handleMemoContentLengthLimitChanges = async (value: number) => {
|
||||
if (value < 8 * 1024) {
|
||||
toast.error("Content length limit should be greater than 8KB");
|
||||
return;
|
||||
}
|
||||
|
||||
const update: WorkspaceMemoRelatedSetting = { ...workspaceMemoRelatedSetting, contentLengthLimit: value };
|
||||
setWorkspaceMemoRelatedSetting(update);
|
||||
await workspaceSettingStore.setWorkspaceSetting({
|
||||
name: `${WorkspaceSettingPrefix}${WorkspaceSettingKey.MEMO_RELATED}`,
|
||||
memoRelatedSetting: update,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="w-full flex flex-col gap-2 pt-2 pb-4">
|
||||
<p className="font-medium text-gray-700 dark:text-gray-500">{t("common.basic")}</p>
|
||||
@ -225,45 +170,6 @@ const WorkspaceSection = () => {
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
<Divider className="!my-3" />
|
||||
<p className="font-medium text-gray-700 dark:text-gray-500">Memo related settings</p>
|
||||
<div className="w-full flex flex-row justify-between items-center">
|
||||
<span>{t("setting.system-section.disable-public-memos")}</span>
|
||||
<Switch
|
||||
checked={workspaceMemoRelatedSetting.disallowPublicVisible}
|
||||
onChange={(event) => handleDisablePublicMemosChanged(event.target.checked)}
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full flex flex-row justify-between items-center">
|
||||
<span>{t("setting.system-section.display-with-updated-time")}</span>
|
||||
<Switch
|
||||
checked={workspaceMemoRelatedSetting.displayWithUpdateTime}
|
||||
onChange={(event) => handleMemoDisplayWithUpdatedTs(event.target.checked)}
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full flex flex-row justify-between items-center">
|
||||
<span>{t("setting.system-section.enable-auto-compact")}</span>
|
||||
<Switch
|
||||
checked={workspaceMemoRelatedSetting.enableAutoCompact}
|
||||
onChange={(event) => handleMemoEnableAutoCompact(event.target.checked)}
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full flex flex-row justify-between items-center">
|
||||
<span>{t("setting.system-section.enable-double-click-to-edit")}</span>
|
||||
<Switch
|
||||
checked={workspaceMemoRelatedSetting.enableDoubleClickEdit}
|
||||
onChange={(event) => handleMemoEnableDoubleClickToEdit(event.target.checked)}
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full flex flex-row justify-between items-center">
|
||||
<span>Content length limit(Byte)</span>
|
||||
<Input
|
||||
className="w-32"
|
||||
type="number"
|
||||
defaultValue={workspaceMemoRelatedSetting.contentLengthLimit}
|
||||
onBlur={(event) => handleMemoContentLengthLimitChanges(Number(event.target.value))}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
Reference in New Issue
Block a user