Skip to content

Commit 5c8713f

Browse files
committed
fix: 🐛 创建日记失败
1 parent 705fba6 commit 5c8713f

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

src/components/JournalButton.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
import { readTextFile, resolve } from '@/lib/bindings'
22
import dayjs from 'dayjs'
33
import { Pencil } from 'lucide-react'
4-
import React from 'react'
4+
import React, { useContext } from 'react'
55
import { Button } from '@/components/ui/button'
66
import { useToast } from '@/components/ui/use-toast'
77
import { useTranslation } from 'react-i18next'
8+
import { Context } from './Layout'
89

910
type Props = {
1011
openMd: (file: string, content?: string) => void
12+
dirPath: string
1113
}
1214

13-
export default function JournalButton({ openMd }: Props) {
15+
export default function JournalButton({ openMd, dirPath }: Props) {
1416
const { t } = useTranslation()
1517
const { toast } = useToast()
1618

19+
let { config } = useContext(Context)
20+
1721
const createOrOpenDailyNote = async () => {
1822
const fileName = dayjs().format('YYYY-MM-DD')
19-
const dirPath = JSON.parse(localStorage.getItem('dir-path') ?? '')
20-
const config = JSON.parse(localStorage.getItem('config') ?? '{}')
2123

2224
const fullPath = config.journalDir
2325
? config.journalDir + '/' + fileName

src/components/MoreDropdown.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { useTranslation } from 'react-i18next'
1515
import { makeDoc, makePrintDoc } from './utils/index'
1616
import { downloadFile } from '@/lib/bindings'
1717
import CheckUpdate from './CheckUpdate'
18+
import { clear } from '@/utils/storage'
1819

1920
type Props = {
2021
resultRef: any
@@ -27,7 +28,7 @@ export default function MoreDropdown({ resultRef }: Props) {
2728
const { t } = useTranslation()
2829

2930
const handleClear = () => {
30-
localStorage.clear()
31+
clear()
3132
window.location.reload()
3233
}
3334

src/components/Pen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ title: ${file}
428428
}
429429
/>
430430
<CopyBtn resultRef={resultRef} />
431-
<JournalButton openMd={openMd} />
431+
<JournalButton dirPath={dirPath} openMd={openMd} />
432432
</div>
433433
</>
434434
}

src/utils/storage.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ export function setItem(key: string, value: any) {
1616
storage.setItem(`${windowName}-config`, JSON.stringify(config))
1717
}
1818

19+
export function clear() {
20+
const windowName = getCurrent().label
21+
const storage = windowName === 'main' ? localStorage : sessionStorage
22+
storage.clear()
23+
}
24+
1925
export const useStorage = <T>(
2026
key: string,
2127
initialValue: T

0 commit comments

Comments
 (0)