1
1
import { isMobile } from "@follow/components/hooks/useMobile.js"
2
- import { FeedViewType , UserRole } from "@follow/constants"
2
+ import { FeedViewType , UserRole , views } from "@follow/constants"
3
3
import { IN_ELECTRON } from "@follow/shared/constants"
4
- import { useCallback , useMemo } from "react"
4
+ import { useMemo } from "react"
5
5
6
6
import { useShowAISummaryAuto , useShowAISummaryOnce } from "~/atoms/ai-summary"
7
7
import { useShowAITranslationAuto , useShowAITranslationOnce } from "~/atoms/ai-translation"
8
8
import {
9
9
getReadabilityStatus ,
10
+ isInReadability ,
10
11
ReadabilityStatus ,
11
12
setReadabilityContent ,
12
13
setReadabilityStatus ,
14
+ useEntryInReadabilityStatus ,
13
15
} from "~/atoms/readability"
14
16
import { useShowSourceContent } from "~/atoms/source-content"
15
17
import { useUserRole , whoami } from "~/atoms/user"
@@ -25,41 +27,40 @@ import { useInboxById } from "~/store/inbox"
25
27
26
28
import { useRouteParamsSelector } from "./useRouteParams"
27
29
28
- export const useEntryReadabilityToggle = ( { id, url } : { id : string ; url : string } ) =>
29
- useCallback ( async ( ) => {
30
- const status = getReadabilityStatus ( ) [ id ]
31
- const isTurnOn = status !== ReadabilityStatus . INITIAL && ! ! status
30
+ export const toggleEntryReadability = async ( { id, url } : { id : string ; url : string } ) => {
31
+ const status = getReadabilityStatus ( ) [ id ]
32
+ const isTurnOn = status !== ReadabilityStatus . INITIAL && ! ! status
32
33
33
- if ( ! isTurnOn && url ) {
34
- setReadabilityStatus ( {
35
- [ id ] : ReadabilityStatus . WAITING ,
34
+ if ( ! isTurnOn && url ) {
35
+ setReadabilityStatus ( {
36
+ [ id ] : ReadabilityStatus . WAITING ,
37
+ } )
38
+ const result = await tipcClient
39
+ ?. readability ( {
40
+ url,
36
41
} )
37
- const result = await tipcClient
38
- ?. readability ( {
39
- url,
40
- } )
41
- . catch ( ( ) => {
42
- setReadabilityStatus ( {
43
- [ id ] : ReadabilityStatus . FAILURE ,
44
- } )
45
- } )
46
-
47
- if ( result ) {
48
- const status = getReadabilityStatus ( ) [ id ]
49
- if ( status !== ReadabilityStatus . WAITING ) return
42
+ . catch ( ( ) => {
50
43
setReadabilityStatus ( {
51
- [ id ] : ReadabilityStatus . SUCCESS ,
52
- } )
53
- setReadabilityContent ( {
54
- [ id ] : result ,
44
+ [ id ] : ReadabilityStatus . FAILURE ,
55
45
} )
56
- }
57
- } else {
46
+ } )
47
+
48
+ if ( result ) {
49
+ const status = getReadabilityStatus ( ) [ id ]
50
+ if ( status !== ReadabilityStatus . WAITING ) return
58
51
setReadabilityStatus ( {
59
- [ id ] : ReadabilityStatus . INITIAL ,
52
+ [ id ] : ReadabilityStatus . SUCCESS ,
53
+ } )
54
+ setReadabilityContent ( {
55
+ [ id ] : result ,
60
56
} )
61
57
}
62
- } , [ id , url ] )
58
+ } else {
59
+ setReadabilityStatus ( {
60
+ [ id ] : ReadabilityStatus . INITIAL ,
61
+ } )
62
+ }
63
+ }
63
64
64
65
export type EntryActionItem = {
65
66
id : FollowCommandId
@@ -70,8 +71,17 @@ export type EntryActionItem = {
70
71
disabled ?: boolean
71
72
}
72
73
73
- export const useEntryActions = ( { entryId, view } : { entryId : string ; view ?: FeedViewType } ) => {
74
+ export const useEntryActions = ( {
75
+ entryId,
76
+ view,
77
+ compact,
78
+ } : {
79
+ entryId : string
80
+ view ?: FeedViewType
81
+ compact ?: boolean
82
+ } ) => {
74
83
const entry = useEntry ( entryId )
84
+ const entryReadabilityStatus = useEntryInReadabilityStatus ( entry ?. entries . id )
75
85
const imageLength = entry ?. entries . media ?. filter ( ( a ) => a . type === "photo" ) . length || 0
76
86
const feed = useFeedById ( entry ?. feedId , ( feed ) => {
77
87
return {
@@ -208,17 +218,36 @@ export const useEntryActions = ({ entryId, view }: { entryId: string; view?: Fee
208
218
active : ! ! entry ?. read ,
209
219
shortcut : shortcuts . entry . toggleRead . key ,
210
220
} ,
221
+ {
222
+ id : COMMAND_ID . entry . tts ,
223
+ onClick : runCmdFn ( COMMAND_ID . entry . tts , [
224
+ { entryId, entryContent : entry ?. entries . content } ,
225
+ ] ) ,
226
+ hide : ! IN_ELECTRON || compact || ! entry ?. entries . content ,
227
+ shortcut : shortcuts . entry . tts . key ,
228
+ } ,
229
+ {
230
+ id : COMMAND_ID . entry . readability ,
231
+ onClick : runCmdFn ( COMMAND_ID . entry . readability , [
232
+ { entryId, entryUrl : entry ?. entries . url } ,
233
+ ] ) ,
234
+ hide : ! IN_ELECTRON || compact || ( view && views [ view ] ! . wideMode ) || ! entry ?. entries . url ,
235
+ active : isInReadability ( entryReadabilityStatus ) ,
236
+ } ,
211
237
{
212
238
id : COMMAND_ID . settings . customizeToolbar ,
213
239
onClick : runCmdFn ( COMMAND_ID . settings . customizeToolbar , [ ] ) ,
214
240
} ,
215
241
] . filter ( ( config ) => ! config . hide )
216
242
} , [
243
+ compact ,
217
244
entry ?. collections ,
245
+ entry ?. entries . content ,
218
246
entry ?. entries . url ,
219
247
entry ?. read ,
220
248
entry ?. view ,
221
249
entryId ,
250
+ entryReadabilityStatus ,
222
251
feed ?. id ,
223
252
feed ?. ownerUserId ,
224
253
hasEntry ,
@@ -241,11 +270,13 @@ export const useEntryActions = ({ entryId, view }: { entryId: string; view?: Fee
241
270
export const useSortedEntryActions = ( {
242
271
entryId,
243
272
view,
273
+ compact,
244
274
} : {
245
275
entryId : string
246
276
view ?: FeedViewType
277
+ compact ?: boolean
247
278
} ) => {
248
- const entryActions = useEntryActions ( { entryId, view } )
279
+ const entryActions = useEntryActions ( { entryId, view, compact } )
249
280
const orderMap = useToolbarOrderMap ( )
250
281
const mainAction = useMemo (
251
282
( ) =>
0 commit comments