Skip to content

Commit bd80c46

Browse files
committed
feat(reader): add increase font and decrease font function
1 parent 62ffe2a commit bd80c46

File tree

8 files changed

+84
-6
lines changed

8 files changed

+84
-6
lines changed

src/i18n/en-US.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
"copy": {
1616
"title": "Copy url",
1717
"success": "Copied"
18-
}
18+
},
19+
"fontIncrease": "Larger",
20+
"fontDecrease": "Smaller"
1921
},
2022

2123
"form": {

src/i18n/zh-CN.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
"copy": {
1616
"title": "复制链接",
1717
"success": "已复制到剪贴板"
18-
}
18+
},
19+
"fontIncrease": "更大",
20+
"fontDecrease": "更小"
1921
},
2022

2123
"form": {

src/router/settings/electron-main/settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ export const router = new Router({ prefix: '/settings' })
55

66
// const getTheme = () => settings.appearance === 'auto' ? 'system' : settings.appearance
77

8-
router.use('get', () => settingService.get())
8+
router.use('get', (_, path) => settingService.get(path))
99

1010
router.use('set', (_, { path, value }: { path: string, value: any }) => settingService.set(path, value))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import intl from 'react-intl-universal'
2+
import { FontDecreaseRegular } from '@fluentui/react-icons'
3+
import { Button } from '@/ui/apps/reader/components/toolbar'
4+
import { store } from '@/ui/store'
5+
6+
const { readerStore } = store
7+
8+
export default function FontDecreaseButton() {
9+
return (
10+
<Button
11+
icon={FontDecreaseRegular}
12+
onClick={() => readerStore.decreaseFont()}
13+
fontSize={20}
14+
tip={intl.get('reader.action.fontDecrease')}
15+
/>
16+
)
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import intl from 'react-intl-universal'
2+
import { FontIncreaseRegular } from '@fluentui/react-icons'
3+
import { Button } from '@/ui/apps/reader/components/toolbar'
4+
import { store } from '@/ui/store'
5+
6+
const { readerStore } = store
7+
8+
export default function FontIncreaseButton() {
9+
return (
10+
<Button
11+
icon={FontIncreaseRegular}
12+
onClick={() => readerStore.increaseFont()}
13+
fontSize={20}
14+
tip={intl.get('reader.action.fontIncrease')}
15+
/>
16+
)
17+
}

src/ui/apps/reader/MainPanel/Article/Toolbar/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { MarkReadButton, StarButton } from '@/ui/apps/reader/components/toolbar'
33
import { store } from '@/ui/store'
44
import BackToListButton from './back-button'
55
import OpenExternalButton from './open-external-btn'
6+
import FontIncreaseButton from './font-increase-button'
7+
import FontDecreaseButton from './font-decrease-button'
68

79
const { readerStore } = store
810

@@ -18,6 +20,8 @@ function Toolbar() {
1820
<MarkReadButton />
1921
<StarButton id={activeId!} />
2022
<OpenExternalButton url={activeArticle!.url} />
23+
<FontDecreaseButton />
24+
<FontIncreaseButton />
2125
</div>
2226
</div>
2327
)

src/ui/apps/reader/MainPanel/Article/content.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const useStyles = makeStyles({
1919
marginTop: '20px',
2020
marginBottom: '20px',
2121
lineHeight: 1.625,
22-
fontSize: tokens.fontSizeBase400,
2322
},
2423

2524
'& pre': {
@@ -61,9 +60,26 @@ const useStyles = makeStyles({
6160
},
6261
})
6362

63+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
64+
const fontSizes = [
65+
'text-[12px]',
66+
'text-[13px]',
67+
'text-[14px]',
68+
'text-[15px]',
69+
'text-[16px]',
70+
'text-[17px]',
71+
'text-[18px]',
72+
'text-[19px]',
73+
'text-[20px]',
74+
'text-[21px]',
75+
'text-[22px]',
76+
'text-[23px]',
77+
'text-[24px]',
78+
]
79+
6480
function Content() {
6581
const styles = useStyles()
66-
const { activeArticle, feeds } = readerStore
82+
const { activeArticle, feeds, fontSize } = readerStore
6783

6884
if (!activeArticle) {
6985
return null
@@ -121,7 +137,7 @@ function Content() {
121137
</div>
122138
</div>
123139
</div>
124-
<div className="px-5">
140+
<div className={`px-5 text-[${fontSize}px]`}>
125141
<div
126142
ref={containerRef}
127143
className={styles.content}

src/ui/store/reader.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ import { Tab, Feed, Article } from '@/types/reader'
33
import * as remote from '@/services/remote/browser/remote'
44
import * as feedService from '@/services/reader/browser/feed'
55
import * as articleService from '@/services/reader/browser/article'
6+
import * as settingService from '@/services/settings/browser/settings'
67

78
import type { RootStore } from './index'
89

10+
const fontSizeKey = 'reader.fontSize'
11+
912
export class ReaderStore {
1013
rootStore: RootStore
1114

@@ -27,6 +30,8 @@ export class ReaderStore {
2730

2831
showKeyboardPanel = false
2932

33+
fontSize = 14
34+
3035
constructor(rootStore: RootStore) {
3136
makeAutoObservable(this, {
3237
rootStore: false,
@@ -44,6 +49,11 @@ export class ReaderStore {
4449
runInAction(() => { this.feeds = feeds || [] })
4550

4651
this.getArticles()
52+
53+
const fontSize = await settingService.get(fontSizeKey)
54+
runInAction(() => {
55+
this.fontSize = fontSize || 14
56+
})
4757
}
4858

4959
private initListeners() {
@@ -333,4 +343,14 @@ export class ReaderStore {
333343
toggleKeyboardPanel() {
334344
this.showKeyboardPanel = !this.showKeyboardPanel
335345
}
346+
347+
increaseFont() {
348+
this.fontSize = Math.min(this.fontSize + 1, 24)
349+
settingService.set(fontSizeKey, this.fontSize)
350+
}
351+
352+
decreaseFont() {
353+
this.fontSize = Math.max(this.fontSize - 1, 12)
354+
settingService.set(fontSizeKey, this.fontSize)
355+
}
336356
}

0 commit comments

Comments
 (0)