Skip to content

Commit 0c02631

Browse files
committed
feat: add feeds
1 parent bf56208 commit 0c02631

File tree

14 files changed

+425
-65
lines changed

14 files changed

+425
-65
lines changed

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
"description": "List all users",
3131
"mode": "view"
3232
},
33+
{
34+
"name": "feeds",
35+
"title": "Feeds",
36+
"description": "posts of users you followed",
37+
"mode": "view"
38+
},
3339
{
3440
"name": "like-top",
3541
"title": "Like Top",
@@ -49,7 +55,7 @@
4955
},
5056
"dependencies": {
5157
"@raycast/api": "^1.35.1",
52-
"jike-sdk": "^0.19.2",
58+
"jike-sdk": "^0.19.3",
5359
"react-use": "^17.4.0"
5460
},
5561
"devDependencies": {

pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/actions/user.tsx

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/components/actions/common.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Action, showHUD } from '@raycast/api'
2+
3+
export const OpenInBrowser = (props: Action.OpenInBrowser.Props) => (
4+
<Action.OpenInBrowser onOpen={() => showHUD('已打开')} {...props} />
5+
)

src/components/actions/post.tsx

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { useMemo } from 'react'
2+
import { Action, Toast, showToast } from '@raycast/api'
3+
import { ApiOptions } from 'jike-sdk'
4+
import { OpenInBrowser } from './common'
5+
6+
export const OpenPost = ({
7+
type,
8+
id,
9+
}: {
10+
type: ApiOptions.PostType
11+
id: string
12+
}) => {
13+
const webType = useMemo(
14+
() => (type === ApiOptions.PostType.ORIGINAL ? 'originalPost' : 'repost'),
15+
[type]
16+
)
17+
return (
18+
<>
19+
<OpenInBrowser
20+
icon="📲"
21+
title="打开动态 (macOS App)"
22+
url={`jike://page.jk/${webType}/${id}`}
23+
/>
24+
<OpenInBrowser
25+
title="打开动态 (PC Web 端)"
26+
url={`https://web.okjike.com/${webType}/${id}`}
27+
/>
28+
<OpenInBrowser
29+
title="打开动态 (手机 Web 端)"
30+
url={`https://m.okjike.com/${type}/${id}`}
31+
/>
32+
</>
33+
)
34+
}
35+
36+
export const LikePost = ({
37+
onAction,
38+
}: {
39+
onAction: () => Promise<boolean> | boolean
40+
}) => {
41+
const action = async () => {
42+
showToast({
43+
title: '操作中',
44+
style: Toast.Style.Animated,
45+
})
46+
if (!(await onAction())) return
47+
showToast({
48+
title: '点赞成功',
49+
style: Toast.Style.Success,
50+
})
51+
}
52+
return <Action icon="👍" title="点赞" onAction={action} />
53+
}
54+
55+
export const UnlikePost = ({
56+
onAction,
57+
}: {
58+
onAction: () => Promise<boolean> | boolean
59+
}) => {
60+
const action = async () => {
61+
showToast({
62+
title: '操作中',
63+
style: Toast.Style.Animated,
64+
})
65+
if (!(await onAction())) return
66+
showToast({
67+
title: '取消点赞成功',
68+
style: Toast.Style.Success,
69+
})
70+
}
71+
return <Action icon="💔" title="取消点赞" onAction={action} />
72+
}

src/components/actions/user.tsx

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { Action, ActionPanel, Icon } from '@raycast/api'
2+
import { Login } from '../../views/login'
3+
import { OpenInBrowser } from './common'
4+
5+
export const OpenProfile = ({
6+
username,
7+
split = true,
8+
}: {
9+
username: string
10+
split?: boolean
11+
}) => {
12+
const macOS = (
13+
<OpenInBrowser
14+
key="open-macos"
15+
title={split ? '打开用户页 (macOS App)' : 'macOS App'}
16+
icon="📲"
17+
url={`jike://page.jk/user/${username}`}
18+
/>
19+
)
20+
const pc = (
21+
<OpenInBrowser
22+
key="open-pc"
23+
title="PC Web 端"
24+
url={`https://web.okjike.com/u/${username}`}
25+
/>
26+
)
27+
const mobile = (
28+
<OpenInBrowser
29+
key="open-mobile"
30+
title="手机 Web 端"
31+
url={`https://m.okjike.com/users/${username}`}
32+
/>
33+
)
34+
return split ? (
35+
<>
36+
{macOS}
37+
<ActionPanel.Submenu
38+
key="openWith"
39+
title="打开用户页 (其他客户端)"
40+
icon={Icon.Window}
41+
>
42+
{pc}
43+
{mobile}
44+
</ActionPanel.Submenu>
45+
</>
46+
) : (
47+
<>
48+
{macOS}
49+
{pc}
50+
{mobile}
51+
</>
52+
)
53+
}
54+
55+
export const LoginNewUser = () => (
56+
<Action.Push
57+
key="login"
58+
title="登录新用户"
59+
target={<Login />}
60+
icon={Icon.Plus}
61+
shortcut={{ modifiers: ['cmd'], key: 'n' }}
62+
/>
63+
)

src/components/user-select.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { Form, Icon, Image } from '@raycast/api'
1+
import { Form, Icon } from '@raycast/api'
22
import { useUsers } from '../hooks/user'
3+
import { pictureWithCircle } from '../utils/icon'
34
import type { ConfigUser } from '../utils/config'
45

56
export function UserSelect({
@@ -20,10 +21,7 @@ export function UserSelect({
2021
<Form.Dropdown id="userId" title="用户" onChange={handleChange} {...props}>
2122
{users.map((user) => (
2223
<Form.Dropdown.Item
23-
icon={{
24-
source: user.avatarImage || Icon.Person,
25-
mask: Image.Mask.Circle,
26-
}}
24+
icon={pictureWithCircle(user.avatarImage || Icon.Person)}
2725
key={user.userId}
2826
title={user.screenName}
2927
value={user.userId}

src/feeds.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { Feeds } from './views/feeds'
2+
3+
export default Feeds

src/utils/icon.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Image } from '@raycast/api'
2+
3+
export const pictureWithCircle = (img: string) => ({
4+
source: img,
5+
mask: Image.Mask.Circle,
6+
})

0 commit comments

Comments
 (0)