@@ -19,6 +19,7 @@ import { fetchGitHubApi } from '~/lib/github'
19
19
import { clsxm } from '~/lib/helper'
20
20
import { getDominantColor } from '~/lib/image'
21
21
import { apiClient } from '~/lib/request'
22
+ import { useFeatureEnabled } from '~/providers/root/app-feature-provider'
22
23
23
24
import { LinkCardSource } from './enums'
24
25
import styles from './LinkCard.module.css'
@@ -73,6 +74,30 @@ const LinkCardImpl: FC<LinkCardProps> = (props) => {
73
74
[ fullUrl ] ,
74
75
)
75
76
77
+ const tmdbEnabled = useFeatureEnabled ( 'tmdb' )
78
+ const validTypeAndFetchFunction = useCallback (
79
+ ( source : LinkCardSource , id : string ) => {
80
+ const fetchDataFunctions = {
81
+ [ LinkCardSource . MixSpace ] : fetchMxSpaceData ,
82
+ [ LinkCardSource . GHRepo ] : fetchGitHubRepoData ,
83
+ [ LinkCardSource . GHCommit ] : fetchGitHubCommitData ,
84
+ [ LinkCardSource . GHPr ] : fetchGitHubPRData ,
85
+ [ LinkCardSource . Self ] : fetchMxSpaceData ,
86
+ } as Record < LinkCardSource , FetchObject >
87
+ if ( tmdbEnabled )
88
+ fetchDataFunctions [ LinkCardSource . TMDB ] = fetchTheMovieDBData
89
+
90
+ const fetchFunction = fetchDataFunctions [ source ]
91
+ if ( ! fetchFunction ) {
92
+ return { isValid : false , fetchFn : null }
93
+ }
94
+
95
+ const isValid = fetchFunction . isValid ( id )
96
+ return { isValid, fetchFn : isValid ? fetchFunction . fetch : null }
97
+ } ,
98
+ [ tmdbEnabled ] ,
99
+ )
100
+
76
101
const { isValid, fetchFn } = useMemo (
77
102
( ) => validTypeAndFetchFunction ( source , id ) ,
78
103
[ source , id ] ,
@@ -207,25 +232,6 @@ type FetchObject = {
207
232
fetch : FetchFunction
208
233
}
209
234
210
- function validTypeAndFetchFunction ( source : LinkCardSource , id : string ) {
211
- const fetchDataFunctions = {
212
- [ LinkCardSource . MixSpace ] : fetchMxSpaceData ,
213
- [ LinkCardSource . GHRepo ] : fetchGitHubRepoData ,
214
- [ LinkCardSource . GHCommit ] : fetchGitHubCommitData ,
215
- [ LinkCardSource . GHPr ] : fetchGitHubPRData ,
216
- [ LinkCardSource . Self ] : fetchMxSpaceData ,
217
- [ LinkCardSource . TMDB ] : fetchTheMovieDBData ,
218
- } as Record < LinkCardSource , FetchObject >
219
-
220
- const fetchFunction = fetchDataFunctions [ source ]
221
- if ( ! fetchFunction ) {
222
- return { isValid : false , fetchFn : null }
223
- }
224
-
225
- const isValid = fetchFunction . isValid ( id )
226
- return { isValid, fetchFn : isValid ? fetchFunction . fetch : null }
227
- }
228
-
229
235
const fetchGitHubRepoData : FetchObject = {
230
236
isValid : ( id ) => {
231
237
// owner/repo
0 commit comments