@@ -8,17 +8,18 @@ import { useIsClient } from '~/hooks/common/use-is-client'
8
8
import { routeBuilder , Routes } from '~/lib/route-builder'
9
9
import { toast } from '~/lib/toast'
10
10
import { urlBuilder } from '~/lib/url-builder'
11
- import { getCurrentNoteData } from '~/providers/note/CurrentNoteDataProvider'
12
- import { useCurrentNoteId } from '~/providers/note/CurrentNoteIdProvider'
13
11
import {
12
+ getCurrentPostData ,
14
13
setCurrentPostData ,
15
14
useCurrentPostDataSelector ,
16
15
} from '~/providers/post/CurrentPostDataProvider'
16
+ import { useModalStack } from '~/providers/root/modal-stack-provider'
17
17
import { isLikedBefore , setLikeId } from '~/utils/cookie'
18
18
import { clsxm } from '~/utils/helper'
19
19
import { apiClient } from '~/utils/request'
20
20
21
21
import { DonateButton } from '../shared/DonateButton'
22
+ import { ShareModal } from '../shared/ShareModal'
22
23
23
24
export const PostActionAside : Component = ( { className } ) => {
24
25
return (
@@ -40,12 +41,12 @@ const LikeButton = () => {
40
41
const [ update ] = useForceUpdate ( )
41
42
42
43
const id = useCurrentPostDataSelector ( ( data ) => data ?. id )
43
- const nid = useCurrentNoteId ( )
44
+
44
45
if ( ! id ) return null
45
46
const handleLike = ( ) => {
46
47
if ( isLikedBefore ( id ) ) return
47
- if ( ! nid ) return
48
- apiClient . note . likeIt ( id ) . then ( ( ) => {
48
+
49
+ apiClient . post . thumbsUp ( id ) . then ( ( ) => {
49
50
setLikeId ( id )
50
51
setCurrentPostData ( ( draft ) => {
51
52
draft . count . like += 1
@@ -105,32 +106,44 @@ const LikeButton = () => {
105
106
}
106
107
107
108
const ShareButton = ( ) => {
108
- const hasShare = 'share' in navigator
109
109
const isClient = useIsClient ( )
110
- void useCurrentNoteId ( )
111
- const note = getCurrentNoteData ( ) ?. data
110
+ const { present } = useModalStack ( )
112
111
113
112
if ( ! isClient ) return null
114
- if ( ! note ) return null
115
-
116
- if ( ! hasShare ) {
117
- return null
118
- }
119
113
120
114
return (
121
115
< MotionButtonBase
122
- aria-label = "Share this post "
116
+ aria-label = "Share This Post Button "
123
117
className = "flex flex-col space-y-2"
124
118
onClick = { ( ) => {
125
- navigator . share ( {
126
- title : note . title ,
127
- text : note . text ,
128
- url : urlBuilder (
129
- routeBuilder ( Routes . Note , {
130
- id : note . nid . toString ( ) ,
131
- } ) ,
132
- ) . href ,
133
- } )
119
+ const post = getCurrentPostData ( )
120
+
121
+ if ( ! post ) return
122
+
123
+ const hasShare = 'share' in navigator
124
+
125
+ const title = '分享一片宝藏文章'
126
+ const url = urlBuilder (
127
+ routeBuilder ( Routes . Post , {
128
+ slug : post . slug ,
129
+ category : post . category . slug ,
130
+ } ) ,
131
+ ) . href
132
+
133
+ const text = `嘿,我发现了一片宝藏文章「${ post . title } 」哩,快来看看吧!${ url } `
134
+
135
+ if ( hasShare )
136
+ navigator . share ( {
137
+ title : post . title ,
138
+ text : post . text ,
139
+ url,
140
+ } )
141
+ else {
142
+ present ( {
143
+ title : '分享此内容' ,
144
+ content : ( ) => < ShareModal text = { text } title = { title } url = { url } /> ,
145
+ } )
146
+ }
134
147
} }
135
148
>
136
149
< i className = "icon-[mingcute--share-forward-fill] text-[24px] opacity-80 duration-200 hover:text-uk-cyan-light hover:opacity-100" />
0 commit comments