Skip to content

Commit 400df0e

Browse files
committed
feat: add fallback for not recognized copilotDoc types
1 parent 85bc9bd commit 400df0e

File tree

8 files changed

+274
-189
lines changed

8 files changed

+274
-189
lines changed

src/components/AccountManager.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ export const AccountAuthDialog: ComponentType<{
257257
isOpen={open}
258258
onClose={onClose}
259259
>
260-
<div className="flex flex-col px-4 pt-2">
260+
<div className="flex flex-col p-4 pt-2">
261261
<GlobalErrorBoundary>
262262
<Tabs
263263
// renderActiveTabPanelOnly: avoid autocomplete on inactive panel

src/components/OperationCard.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ export const OperationCard = ({
109109
<div className="flex">
110110
<div className="text-gray-700 leading-normal w-1/2">
111111
{/* <div className="text-sm text-zinc-600 mb-2 font-bold">作业描述</div> */}
112-
<Paragraphs content={operationDoc.doc.details} linkify />
112+
<Paragraphs
113+
content={operationDoc.doc.details}
114+
limitHeight={21 * 13.5} // 13 lines, 21px per line; the extra 0.5 line is intentional so the `mask` effect is obvious
115+
/>
113116
</div>
114117
<div className="w-1/2 ml-4">
115118
<div className="text-sm text-zinc-600 mb-2 font-bold">

src/components/Paragraphs.tsx

Lines changed: 64 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,71 @@
11
import Linkify from 'linkify-react'
2-
import { FC, memo } from 'react'
2+
import { FC, memo, useEffect, useRef, useState } from 'react'
33

4-
export const Paragraphs: FC<{ content?: string; linkify?: boolean }> = memo(
5-
({ content, linkify }) => {
6-
const paragraphs = content?.split('\n').map((el) => el.trim())
7-
const child = (
8-
<>
4+
export const Paragraphs: FC<{
5+
content?: string
6+
linkify?: boolean
7+
limitHeight?: number
8+
}> = memo(({ content, linkify, limitHeight }) => {
9+
const paragraphElementRef = useRef<HTMLDivElement>(null)
10+
const paragraphs = content?.split('\n').map((el) => el.trim())
11+
12+
// exceededLimitHeight
13+
const [exceededLimitHeight, setExceededLimitHeight] = useState(false)
14+
15+
useEffect(() => {
16+
if (!paragraphElementRef.current || !limitHeight) {
17+
return
18+
}
19+
20+
const { height } = paragraphElementRef.current.getBoundingClientRect()
21+
22+
setExceededLimitHeight(height > limitHeight)
23+
}, [paragraphElementRef.current, limitHeight])
24+
25+
const mask = exceededLimitHeight
26+
? 'linear-gradient(to bottom, rgba(0,0,0,1) 0%, rgba(0,0,0,1) calc(100% - 2rem), rgba(0,0,0,0) 100%)'
27+
: 'none'
28+
29+
const child = (
30+
<div
31+
className="text-gray-700 leading-normal"
32+
style={{
33+
maxHeight: limitHeight,
34+
overflow: 'hidden',
35+
mask,
36+
WebkitMask: mask,
37+
background: exceededLimitHeight
38+
? 'linear-gradient(to bottom, rgba(0,0,0,0) 0%, rgba(0,0,0,0) calc(100% - 2rem), rgba(0,0,0,0.1) 100%)'
39+
: 'none',
40+
}}
41+
>
42+
<div ref={paragraphElementRef}>
943
{paragraphs?.map((paragraph, index) => (
1044
<p key={index}>{paragraph}</p>
1145
))}
12-
</>
13-
)
14-
15-
return linkify ? (
16-
<Linkify
17-
options={{
18-
attributes: {
19-
target: '_blank',
20-
rel: 'noopener noreferrer',
21-
},
22-
className: 'break-all',
23-
format: {
24-
url: (value) =>
25-
value.length > 50 ? value.slice(0, 50) + '…' : value,
26-
},
27-
}}
28-
>
29-
{child}
30-
</Linkify>
31-
) : (
32-
child
33-
)
34-
},
35-
)
46+
</div>
47+
</div>
48+
)
49+
50+
return linkify ? (
51+
<Linkify
52+
options={{
53+
attributes: {
54+
target: '_blank',
55+
rel: 'noopener noreferrer',
56+
},
57+
className: 'break-all',
58+
format: {
59+
url: (value) =>
60+
value.length > 50 ? value.slice(0, 50) + '…' : value,
61+
},
62+
}}
63+
>
64+
{child}
65+
</Linkify>
66+
) : (
67+
child
68+
)
69+
})
3670

3771
Paragraphs.displayName = 'Paragraphs'

src/components/account/EditDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const EditDialog: FC<EditDialogProps> = ({ isOpen, onClose }) => {
3232

3333
return (
3434
<Dialog title="修改账户信息" icon="user" isOpen={isOpen} onClose={onClose}>
35-
<div className="px-4 pt-2">
35+
<div className="p-4 pt-2">
3636
<GlobalErrorBoundary>
3737
<Tabs
3838
// renderActiveTabPanelOnly: avoid autocomplete on inactive panel

src/components/account/ResetPasswordDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const ResetPasswordDialog: FC<ResetPasswordDialogProps> = ({
6464
isOpen={isOpen}
6565
onClose={onClose}
6666
>
67-
<div className="px-4 pt-2">
67+
<div className="p-4 pt-2">
6868
<GlobalErrorBoundary>
6969
<form>
7070
{globalError && (

0 commit comments

Comments
 (0)