Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 70 additions & 68 deletions src/components/atoms/MarkdownPreviewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,73 +92,10 @@ const MarkdownPreviewer = ({
const activeStorageId = useActiveStorageId()
const { pushMessage } = useToast()

const remarkAdmonitionOptions = {
tag: ':::',
icons: 'emoji',
infima: false,
}

const rehypeReactConfig = {
createElement: React.createElement,
Fragment: React.Fragment,
components: {
img: ({ src, ...props }: any) => {
if (src != null && !src.match('/')) {
const attachment = attachmentMap[src]
if (attachment != null) {
return <AttachmentImage attachment={attachment} {...props} />
}
}

return <ExpandableImage {...props} src={src} />
},
a: ({ href, children }: any) => {
return (
<a
className={'markdown__custom__note_link'}
href={href}
onClick={(event) => {
event.preventDefault()
if (href) {
if (isNoteLinkId(href)) {
navigateToNote(href)
} else {
openNew(href)
}
}
}}
>
{children}
</a>
)
},
input: (props: React.HTMLProps<HTMLInputElement>) => {
const { type, checked } = props

if (type !== 'checkbox') {
return <input {...props} />
}

return (
<MarkdownCheckbox
index={checkboxIndexRef.current++}
checked={checked}
updateContent={updateContent}
/>
)
},
pre: CodeFence,
flowchart: ({ children }: any) => {
return <Flowchart code={children[0]} />
},
chart: ({ children }: any) => {
return <Chart config={children[0]} />
},
'chart(yaml)': ({ children }: any) => {
return <Chart config={children[0]} isYml={true} />
},
},
}
const remarkAdmonitionOptions = useMemo(
() => ({ tag: ':::', icons: 'emoji', infima: false }),
[]
)

const navigateToNote = useCallback(
(noteId) => {
Expand Down Expand Up @@ -201,6 +138,71 @@ const MarkdownPreviewer = ({
[activeStorageId, pushMessage, storageMap, getNotePathname, replace]
)

const rehypeReactConfig = useMemo(
() => ({
createElement: React.createElement,
Fragment: React.Fragment,
components: {
img: ({ src, ...props }: any) => {
if (src != null && !src.match('/')) {
const attachment = attachmentMap[src]
if (attachment != null) {
return <AttachmentImage attachment={attachment} {...props} />
}
}

return <ExpandableImage {...props} src={src} />
},
a: ({ href, children }: any) => {
return (
<a
className={'markdown__custom__note_link'}
href={href}
onClick={(event) => {
event.preventDefault()
if (href) {
if (isNoteLinkId(href)) {
navigateToNote(href)
} else {
openNew(href)
}
}
}}
>
{children}
</a>
)
},
input: (props: React.HTMLProps<HTMLInputElement>) => {
const { type, checked } = props

if (type !== 'checkbox') {
return <input {...props} />
}

return (
<MarkdownCheckbox
index={checkboxIndexRef.current++}
checked={checked}
updateContent={updateContent}
/>
)
},
pre: CodeFence,
flowchart: ({ children }: any) => {
return <Flowchart code={children[0]} />
},
chart: ({ children }: any) => {
return <Chart config={children[0]} />
},
'chart(yaml)': ({ children }: any) => {
return <Chart config={children[0]} isYml={true} />
},
},
}),
[attachmentMap, updateContent, navigateToNote]
)

const markdownProcessor = useMemo(() => {
return unified()
.use(remarkParse)
Expand Down Expand Up @@ -258,7 +260,7 @@ const MarkdownPreviewer = ({
previousContentRef.current = content
previousThemeRef.current = codeBlockTheme
renderContent()
}, [content, codeBlockTheme, rendering, renderContent, renderedContent])
}, [content, codeBlockTheme, renderContent])

const StyledContainer = useMemo(() => {
return styled.div`
Expand Down
2 changes: 1 addition & 1 deletion src/components/organisms/ImportLegacyNotesForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ async function readdirOrEmpty(pathname: string) {
try {
return await readdir(pathname)
} catch (error) {
if (error.code === 'ENOENT') {
if (error.message?.includes('ENOENT')) {
return []
}
throw error
Expand Down
2 changes: 1 addition & 1 deletion src/lib/db/FSNoteDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ class FSNoteDb implements NoteDb {
const rawContent = await readFileAsString(jsonPathname)
this.data = JSON.parse(rawContent)
} catch (error) {
if (error.code === 'ENOENT') {
if (error.message?.includes('ENOENT')) {
const defaultBoostNoteJSON: StorageJSONData = {
folderMap: {},
tagMap: {},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/electronOnly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async function prepareDirectory(pathname: string) {
)
}
} catch (error) {
if (error.code === 'ENOENT') {
if (error.message?.includes('ENOENT')) {
await mkdir(pathname)
} else {
throw error
Expand Down
19 changes: 11 additions & 8 deletions src/shared/components/molecules/Form/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react'
import React, { useState, useEffect, useRef } from 'react'
import styled from '../../../lib/styled'
import { LoadingButton } from '../../atoms/Button'
import cc from 'classcat'
Expand All @@ -23,6 +23,13 @@ const Form: AppComponent<FormProps> = ({
className,
}) => {
const [submitState, setSubmitState] = useState(false)
const mountedRef = useRef(true)
useEffect(() => {
return () => {
mountedRef.current = false
}
}, [])

return (
<Container
onSubmit={async (event: React.FormEvent) => {
Expand All @@ -31,15 +38,11 @@ const Form: AppComponent<FormProps> = ({
}

event.preventDefault()
if (onSubmit == null) {
return
}
setSubmitState(true)
new Promise(async (resolve) => {
await onSubmit(event)
await onSubmit(event)
if (mountedRef.current) {
setSubmitState(false)
resolve(true)
})
}
}}
className={cc(['form', className])}
>
Expand Down