Skip to content

Commit ec59772

Browse files
committed
feat(#311): 系统设置增加编辑器设置,增加打字机模式控制
1 parent 8ece2bb commit ec59772

File tree

10 files changed

+73
-6
lines changed

10 files changed

+73
-6
lines changed

messages/en.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
"error": "Failed"
2626
},
2727
"settings": {
28+
"editor": {
29+
"title": "Editor Settings",
30+
"desc": "Here, you can customize the Markdown editor, creating a writing experience tailored to your needs.",
31+
"typewriterMode": "Typewriter Mode",
32+
"typewriterModeDesc": "In typewriter mode, the editor will simulate a typewriter effect, helping you better immerse in writing."
33+
},
2834
"uploadStore": {
2935
"uploadConfirm": "Upload configuration please ensure the sync repository is private, otherwise the data will be leaked!",
3036
"downloadConfirm": "Download configuration will cover local configuration and restart to take effect!",

messages/ja.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
"error": "失敗"
2424
},
2525
"settings": {
26+
"editor": {
27+
"title": "エディタ設定です",
28+
"desc": "ここでは、Markdown エディタをカスタマイズして、より適した書き込み体験を提供できます。",
29+
"typewriterMode": "打字機モード",
30+
"typewriterModeDesc": "打字機モード下、エディタは打字機の効果を模倣し、より深く浸かる書き込み体験を提供します。"
31+
},
2632
"uploadStore": {
2733
"uploadConfirm": "同期リポジトリをプライベートに設定してください。",
2834
"downloadConfirm": "ダウンロード配置をローカル配置に上書きし、再起動して有効になります。",

messages/zh.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
"error": "失败"
2424
},
2525
"settings": {
26+
"editor": {
27+
"title": "编辑器设置",
28+
"desc": "在这里,你可以对 Markdown 编辑器进行自定义配置,打造更适合你的写作方式。",
29+
"typewriterMode": "打字机模式",
30+
"typewriterModeDesc": "打字机模式下,编辑器会模拟打字机效果,帮助你更好地沉浸在写作中。"
31+
},
2632
"uploadStore": {
2733
"uploadConfirm": "上传配置请确保同步仓库为私有,否则数据将会泄露!",
2834
"downloadConfirm": "下载配置将会覆盖本地配置,并且重启生效!",

src/app/core/article/md-editor.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ export function MdEditor() {
4444
}
4545
}
4646

47-
function init() {
47+
async function init() {
48+
const store = await Store.load('store.json');
49+
const typewriterMode = await store.get<boolean>('typewriterMode') || false
50+
4851
let toolbarConfig = [
4952
{ name: 'undo', tipPosition: 's' },
5053
{ name: 'redo', tipPosition: 's' },
@@ -121,6 +124,7 @@ export function MdEditor() {
121124
cdn: '',
122125
theme: theme === 'dark' ? 'dark' : 'classic',
123126
toolbar: toolbarConfig,
127+
typewriterMode,
124128
link: {
125129
isOpen: false,
126130
click: (dom: Element) => {

src/app/core/setting/components/setting-base.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function SettingType(
1414
</div>
1515
}
1616
export function SettingRow({border = false, children, className}: { border?: boolean, children: React.ReactNode, className?: string}) {
17-
return <div className={`${border ? "border-b py-4" : ""} flex justify-between text-sm items-center ${className}`}>
17+
return <div className={`${border ? "border-b py-4" : ""} flex justify-between text-sm items-start lg:items-center ${className}`}>
1818
{children}
1919
</div>
2020
}

src/app/core/setting/config.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ const baseConfig = [
4040
icon: <FolderOpen className="size-4 lg:size-6" />,
4141
anchor: 'file',
4242
},
43+
{
44+
icon: <UserRoundCog className="size-4 lg:size-6" />,
45+
anchor: 'editor',
46+
},
4347
{
4448
icon: <ScanText className="size-4 lg:size-6" />,
4549
anchor: 'ocr',

src/app/core/setting/dev/set-config.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default function SetConfig() {
4141
}
4242
}
4343
return (
44-
<SettingRow border className="gap-4 flex-col lg:flex-row !items-start lg:items-center">
44+
<SettingRow border className="gap-4 flex-col lg:flex-row items-start lg:items-center">
4545
<span>配置文件导入与导出,导入配置文件将覆盖当前配置,并且重启后生效。</span>
4646
<div className="flex gap-2">
4747
<Button onClick={handleImport}><HardDriveDownload />导入</Button>

src/app/core/setting/dev/setting-dev.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ export function SettingDev({id, icon}: {id: string, icon?: React.ReactNode}) {
7070

7171
return (
7272
<SettingType id={id} icon={icon} title={t('settings.dev.title')}>
73-
<SettingRow border className="gap-4 flex-col lg:flex-row !items-start lg:items-center">
73+
<SettingRow border className="gap-4 flex-col lg:flex-row items-start lg:items-center">
7474
<span>{t('settings.dev.proxy')}</span>
7575
<Input className="max-w-[400px]" placeholder={t('settings.dev.proxyPlaceholder')} value={proxy} onChange={proxyChangeHandler} />
7676
</SettingRow>
77-
<SettingRow border className="gap-4 flex-col lg:flex-row !items-start lg:items-center">
77+
<SettingRow border className="gap-4 flex-col lg:flex-row items-start lg:items-center">
7878
<span>清理数据信息,包括系统配置信息、数据库(包含记录)。</span>
7979
<Button variant={"destructive"} onClick={handleClearData}>清理</Button>
8080
</SettingRow>
81-
<SettingRow border className="gap-4 flex-col lg:flex-row !items-start lg:items-center">
81+
<SettingRow border className="gap-4 flex-col lg:flex-row items-start lg:items-center">
8282
<span>清理文件,包括图片、文章。</span>
8383
<Button variant={"destructive"} onClick={handleClearFile}>清理</Button>
8484
</SettingRow>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use client';
2+
import { UserRoundCog } from "lucide-react"
3+
import { SettingType } from "../components/setting-base";
4+
import { useTranslations } from 'next-intl';
5+
import TypewriterMode from './typewriter-mode';
6+
7+
export default function EditorSettingPage() {
8+
const t = useTranslations('settings.editor');
9+
return <SettingType id="editorSetting" icon={<UserRoundCog />} title={t('title')}>
10+
<TypewriterMode />
11+
</SettingType>
12+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Switch } from "@/components/ui/switch";
2+
import { SettingPanel } from "../components/setting-base";
3+
import { useTranslations } from 'next-intl';
4+
import { useEffect, useState } from "react";
5+
import { Store } from "@tauri-apps/plugin-store";
6+
7+
export default function TypewriterMode() {
8+
const t = useTranslations('settings.editor');
9+
const [state, setState] = useState(false)
10+
11+
useEffect(() => {
12+
async function init() {
13+
const store = await Store.load('store.json');
14+
const typewriterMode = await store.get<boolean>('typewriterMode') || false
15+
setState(typewriterMode)
16+
}
17+
init()
18+
}, [])
19+
20+
async function setStateHandler(state: boolean) {
21+
const store = await Store.load('store.json');
22+
await store.set('typewriterMode', state)
23+
setState(state)
24+
}
25+
26+
return <SettingPanel title={t('typewriterMode')} desc={t('typewriterModeDesc')}>
27+
<Switch checked={state} onCheckedChange={setStateHandler}/>
28+
</SettingPanel>
29+
}

0 commit comments

Comments
 (0)