Skip to content
This repository was archived by the owner on Aug 16, 2024. It is now read-only.

Commit 09abfd0

Browse files
committed
feat: paragraph margin
1 parent ea7a335 commit 09abfd0

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/pages/Content/components/TranslationItem.tsx

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from 'react'
1+
import React, { useEffect, useMemo, useState } from 'react'
22
import Clipboard from 'react-clipboard.js'
33
import { useSnackbar } from 'notistack'
44
import { Collapse } from 'react-collapse'
@@ -17,10 +17,14 @@ const TranslationItem: React.FC<{
1717
}> = ({ job }) => {
1818
const config = useConfig()
1919
const [loading, setLoading] = useState(true)
20-
const [result, setResult] = useState<string>()
20+
const [result, setResult] = useState<string[]>()
2121
const [collapse, setCollapse] = useState(true)
2222
const { enqueueSnackbar } = useSnackbar()
2323

24+
const textContent = useMemo((): string[] => {
25+
return job.text.split('\n')
26+
}, [job.text])
27+
2428
const findOriginal = () => {
2529
const { parentElement } = job
2630

@@ -51,7 +55,7 @@ const TranslationItem: React.FC<{
5155
payload,
5256
})
5357

54-
setResult(payload.translations.map((item) => item.text).join('\n'))
58+
setResult(payload.translations.map((item) => item.text))
5559

5660
setLoading(false)
5761
})
@@ -73,15 +77,23 @@ const TranslationItem: React.FC<{
7377
className="ate_TranslationItem__original"
7478
onClick={() => setCollapse((prev) => !prev)}>
7579
<Collapse isOpened={!collapse}>
76-
<div>{job.text}</div>
80+
<>
81+
{textContent.map((item, index) => (
82+
<div key={index}>{item}</div>
83+
))}
84+
</>
7785
</Collapse>
7886
</div>
7987

8088
{loading ? (
8189
<div className="ate_TranslationItem__result">翻译中…</div>
8290
) : undefined}
8391
{result ? (
84-
<div className="ate_TranslationItem__result">{result}</div>
92+
<div className="ate_TranslationItem__result">
93+
{result.map((item, index) => (
94+
<div key={index}>{item}</div>
95+
))}
96+
</div>
8597
) : undefined}
8698
</div>
8799
<div className="ate_TranslationItem__lower">

src/pages/Content/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ const getTextSelection = (
142142
selection: RangySelection,
143143
): TextSelection & { selection: RangySelection } => {
144144
const text = selection.toString().trim()
145+
// const html = selection.toHtml().trim()
145146

146147
return {
147148
selection,

src/pages/Content/styles/components/TranslationItem.scss

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@
2121

2222
@apply ease-in-out duration-300;
2323
}
24+
.ReactCollapse--content {
25+
@apply space-y-2;
26+
}
2427
}
2528
&__result {
26-
@apply rounded bg-yellow-50 p-3;
29+
@apply rounded bg-yellow-50 p-3 space-y-2;
2730
}
2831
&__source-lang-tag {
2932
@apply px-2 py-1 bg-green-50 text-green-600 text-sm rounded;

0 commit comments

Comments
 (0)