@@ -7,6 +7,7 @@ import { DocFeedbackFloatingButton } from './DocFeedbackFloatingButton'
77import { getDocFeedbackForPageQueryOptions } from '~/queries/docFeedback'
88import { createDocFeedback } from '~/utils/docFeedback.functions'
99import { useCurrentUser } from '~/hooks/useCurrentUser'
10+ import { useLoginModal } from '~/contexts/LoginModalContext'
1011import {
1112 findReferenceableBlocks ,
1213 getBlockIdentifier ,
@@ -28,6 +29,7 @@ export function DocFeedbackProvider({
2829 libraryVersion,
2930} : DocFeedbackProviderProps ) {
3031 const user = useCurrentUser ( )
32+ const { openLoginModal } = useLoginModal ( )
3133 const containerRef = React . useRef < HTMLDivElement > ( null )
3234
3335 const [ creatingState , setCreatingState ] = React . useState < {
@@ -76,9 +78,9 @@ export function DocFeedbackProvider({
7678 )
7779 } , [ feedbackData , user ] )
7880
79- // Find blocks and compute selectors after render
81+ // Find blocks and compute selectors after render (runs for all users to show teasers)
8082 React . useEffect ( ( ) => {
81- if ( ! user || ! containerRef . current ) return
83+ if ( ! containerRef . current ) return
8284
8385 const container = containerRef . current
8486 const blocks = findReferenceableBlocks ( container )
@@ -164,7 +166,7 @@ export function DocFeedbackProvider({
164166 }
165167 } )
166168 }
167- } , [ user , children ] )
169+ } , [ children ] )
168170
169171 // Update block indicators when notes or improvements change
170172 React . useEffect ( ( ) => {
@@ -205,6 +207,17 @@ export function DocFeedbackProvider({
205207 const selector = blockSelectors . get ( blockId )
206208 if ( ! selector ) return
207209
210+ // If not logged in, show login modal
211+ if ( ! user ) {
212+ openLoginModal ( {
213+ onSuccess : ( ) => {
214+ // After login, open the creating interface
215+ setCreatingState ( { blockId, type } )
216+ } ,
217+ } )
218+ return
219+ }
220+
208221 // Check if there's existing feedback for this block
209222 const existingNote = userNotes . find ( ( n ) => n . blockSelector === selector )
210223 const existingImprovement = userImprovements . find (
@@ -226,27 +239,25 @@ export function DocFeedbackProvider({
226239 type,
227240 } )
228241 } ,
229- [ blockSelectors , userNotes , userImprovements ] ,
242+ [ blockSelectors , userNotes , userImprovements , user , openLoginModal ] ,
230243 )
231244
232- if ( ! user ) {
233- return < div ref = { containerRef } > { children } </ div >
234- }
235-
236245 return (
237246 < div ref = { containerRef } className = "relative" >
238247 { children }
239248
240- { /* Render floating buttons for each block */ }
249+ { /* Render floating buttons for each block (visible to all users) */ }
241250 { Array . from ( blockSelectors . keys ( ) ) . map ( ( blockId ) => {
242251 const selector = blockSelectors . get ( blockId )
243252 if ( ! selector ) return null
244253
245- // Check if this block has a note or improvement
246- const note = userNotes . find ( ( n ) => n . blockSelector === selector )
247- const improvement = userImprovements . find (
248- ( n ) => n . blockSelector === selector ,
249- )
254+ // Check if this block has a note or improvement (only for logged-in users)
255+ const note = user
256+ ? userNotes . find ( ( n ) => n . blockSelector === selector )
257+ : undefined
258+ const improvement = user
259+ ? userImprovements . find ( ( n ) => n . blockSelector === selector )
260+ : undefined
250261 const isHovered = hoveredBlockId === blockId
251262
252263 return (
@@ -267,7 +278,7 @@ export function DocFeedbackProvider({
267278 )
268279 } ) }
269280
270- { /* Render notes inline */ }
281+ { /* Render notes inline (only for logged-in users) */ }
271282 { userNotes . map ( ( note ) => {
272283 // Find the block ID for this note's selector
273284 const blockId = Array . from ( blockSelectors . entries ( ) ) . find (
0 commit comments