File tree 3 files changed +25
-7
lines changed
3 files changed +25
-7
lines changed Original file line number Diff line number Diff line change
1
+ import { queryClient } from '~/providers/root/react-query-provider'
1
2
import { atom , useAtomValue } from 'jotai'
2
3
3
4
import { getToken } from '~/lib/cookie'
@@ -12,15 +13,23 @@ export interface UrlConfig {
12
13
}
13
14
14
15
const adminUrlAtom = atom < string | null > ( null )
16
+ const webUrlAtom = atom < string | null > ( null )
15
17
16
18
export const fetchAppUrl = async ( ) => {
17
- const { data } = await apiClient . proxy . options . url . get < {
18
- data : UrlConfig
19
- } > ( )
20
-
21
- jotaiStore . set ( adminUrlAtom , data . adminUrl )
19
+ const { data } = await queryClient . fetchQuery ( {
20
+ queryKey : [ 'app.url' ] ,
21
+ queryFn : ( ) =>
22
+ apiClient . proxy . options . url . get < {
23
+ data : UrlConfig
24
+ } > ( ) ,
25
+ } )
26
+
27
+ if ( data . adminUrl ) jotaiStore . set ( adminUrlAtom , data . adminUrl )
28
+ jotaiStore . set ( webUrlAtom , data . webUrl )
22
29
}
23
30
31
+ export const getWebUrl = ( ) => jotaiStore . get ( webUrlAtom )
32
+ export const setWebUrl = ( url : string ) => jotaiStore . set ( webUrlAtom , url )
24
33
export const getAdminUrl = ( ) => jotaiStore . get ( adminUrlAtom )
25
34
export const useAppUrl = ( ) => {
26
35
const url = useAggregationSelector ( ( a ) => a . url )
Original file line number Diff line number Diff line change
1
+ import { getWebUrl } from '~/atoms'
2
+
1
3
import { isClientSide , isDev } from './env'
2
4
3
5
export const getTweetId = ( url : URL ) => {
@@ -74,9 +76,13 @@ export const isBilibiliUrl = (url: URL) => {
74
76
75
77
export const isSelfArticleUrl = ( url : URL ) => {
76
78
if ( ! isClientSide ) return false
79
+
80
+ const webUrl = getWebUrl ( )
81
+ const webHost = webUrl ? new URL ( webUrl ) . hostname : ''
82
+
77
83
if ( isDev && url . hostname === 'innei.in' ) return true
78
84
return (
79
- url . hostname === location . hostname &&
85
+ ( url . hostname === location . hostname || webHost === location . hostname ) &&
80
86
[ '/posts/' , '/notes/' ] . some ( ( path ) => url . pathname . startsWith ( path ) )
81
87
)
82
88
}
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import type { AggregateRoot } from '@mx-space/api-client'
7
7
import type { AppConfig } from '~/app/config'
8
8
import type { FC , PropsWithChildren } from 'react'
9
9
10
- import { fetchAppUrl } from '~/atoms'
10
+ import { fetchAppUrl , setWebUrl } from '~/atoms'
11
11
import { login } from '~/atoms/owner'
12
12
import { useBeforeMounted } from '~/hooks/common/use-before-mounted'
13
13
import { jotaiStore } from '~/lib/store'
@@ -24,6 +24,7 @@ export const AggregationProvider: FC<
24
24
useBeforeMounted ( ( ) => {
25
25
if ( ! aggregationData ) return
26
26
jotaiStore . set ( aggregationDataAtom , aggregationData )
27
+ setWebUrl ( aggregationData . url . webUrl )
27
28
} )
28
29
useBeforeMounted ( ( ) => {
29
30
if ( ! appConfig ) return
@@ -38,9 +39,11 @@ export const AggregationProvider: FC<
38
39
useEffect ( ( ) => {
39
40
if ( ! aggregationData ) return
40
41
jotaiStore . set ( aggregationDataAtom , aggregationData )
42
+ setWebUrl ( aggregationData . url . webUrl )
41
43
} , [ aggregationData ] )
42
44
43
45
const callOnceRef = useRef ( false )
46
+
44
47
useEffect ( ( ) => {
45
48
if ( callOnceRef . current ) return
46
49
if ( ! aggregationData ?. user ) return
You can’t perform that action at this time.
0 commit comments