Skip to content

Commit e596f52

Browse files
committed
feat(feeds): add open image
1 parent e00abe9 commit e596f52

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/views/feeds.tsx

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { Action, ActionPanel, Icon, List, Toast, showToast } from '@raycast/api'
1+
import {
2+
Action,
3+
ActionPanel,
4+
Icon,
5+
List,
6+
Toast,
7+
open,
8+
showToast,
9+
} from '@raycast/api'
210
import { ApiOptions, JikePostWithDetail, limit } from 'jike-sdk'
311
import { createContext, useContext, useEffect, useMemo, useState } from 'react'
412
import { useUser } from '../hooks/user'
@@ -200,15 +208,22 @@ const UserInteract = ({
200208
)
201209

202210
const OriginalPost = ({ post }: { post: JikePostWithDetail }) => {
203-
const [detail, setDetail] = useState(post.detail)
211+
// TODO: repost
212+
const [detail, setDetail] = useState(post.detail as Entity.OriginalPost)
204213
const markdown = useMemo(
205214
() => `${detail.content
206215
.replaceAll('\n', '\n\n')
207216
.replaceAll(/([!#()*+.[\\\]_`{}-])/g, `\\$1`)}
208217
209218
${detail.pictures
210219
?.map((picture: Entity.Picture) => `![图片](${picture.middlePicUrl})`)
211-
.join('\n\n')}`,
220+
.join('\n\n')}
221+
222+
${
223+
detail.linkInfo
224+
? `[ <img height="16" src="${detail.linkInfo.pictureUrl}"/> ${detail.linkInfo.title}](${detail.linkInfo.linkUrl})`
225+
: ''
226+
}`,
212227
[detail.content, detail.pictures]
213228
)
214229

@@ -233,6 +248,11 @@ ${detail.pictures
233248
return false
234249
}
235250
}
251+
const openImage = async () => {
252+
for (const pic of detail.pictures ?? []) {
253+
await open(pic.picUrl)
254+
}
255+
}
236256

237257
return (
238258
<List.Item
@@ -246,6 +266,14 @@ ${detail.pictures
246266
) : (
247267
<LikePost onAction={onAction('like')} />
248268
)}
269+
{(detail.pictures ?? []).length > 0 && (
270+
<Action
271+
title="打开图片"
272+
icon={Icon.Document}
273+
shortcut={{ modifiers: ['cmd', 'shift'], key: 'o' }}
274+
onAction={openImage}
275+
/>
276+
)}
249277
<OpenPost type={ApiOptions.PostType.ORIGINAL} id={post.id} />
250278
<Pager />
251279
<CopyUpdate object={detail} />

0 commit comments

Comments
 (0)