Skip to content

Commit 75a68b7

Browse files
committed
doc feedback context
1 parent 9d37619 commit 75a68b7

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/components/DocFeedbackProvider.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ export function DocFeedbackProvider({
4141
const [blockContentHashes, setBlockContentHashes] = React.useState<
4242
Map<string, string>
4343
>(new Map())
44+
const [blockMarkdowns, setBlockMarkdowns] = React.useState<
45+
Map<string, string>
46+
>(new Map())
4447
const [hoveredBlockId, setHoveredBlockId] = React.useState<string | null>(
4548
null,
4649
)
@@ -81,6 +84,7 @@ export function DocFeedbackProvider({
8184
const blocks = findReferenceableBlocks(container)
8285
const selectorMap = new Map<string, string>()
8386
const hashMap = new Map<string, string>()
87+
const markdownMap = new Map<string, string>()
8488
const listeners = new Map<
8589
HTMLElement,
8690
{ enter: (e: MouseEvent) => void; leave: (e: MouseEvent) => void }
@@ -94,6 +98,7 @@ export function DocFeedbackProvider({
9498
const identifier = await getBlockIdentifier(block)
9599
selectorMap.set(blockId, identifier.selector)
96100
hashMap.set(blockId, identifier.contentHash)
101+
markdownMap.set(blockId, block.textContent?.trim() || '')
97102

98103
// Add hover handlers with visual feedback
99104
const handleMouseEnter = (e: MouseEvent) => {
@@ -139,6 +144,7 @@ export function DocFeedbackProvider({
139144
).then(() => {
140145
setBlockSelectors(new Map(selectorMap))
141146
setBlockContentHashes(new Map(hashMap))
147+
setBlockMarkdowns(new Map(markdownMap))
142148

143149
// Visual indicators will be updated by the separate effect below
144150
})
@@ -298,6 +304,7 @@ export function DocFeedbackProvider({
298304
type={creatingState.type}
299305
blockSelector={blockSelectors.get(creatingState.blockId) || ''}
300306
blockContentHash={blockContentHashes.get(creatingState.blockId) || ''}
307+
blockMarkdown={blockMarkdowns.get(creatingState.blockId) || ''}
301308
pagePath={pagePath}
302309
libraryId={libraryId}
303310
libraryVersion={libraryVersion}
@@ -439,6 +446,7 @@ function CreatingFeedbackPortal({
439446
type,
440447
blockSelector,
441448
blockContentHash,
449+
blockMarkdown,
442450
pagePath,
443451
libraryId,
444452
libraryVersion,
@@ -448,6 +456,7 @@ function CreatingFeedbackPortal({
448456
type: 'note' | 'improvement'
449457
blockSelector: string
450458
blockContentHash?: string
459+
blockMarkdown?: string
451460
pagePath: string
452461
libraryId: string
453462
libraryVersion: string
@@ -492,6 +501,7 @@ function CreatingFeedbackPortal({
492501
type={type}
493502
blockSelector={blockSelector}
494503
blockContentHash={blockContentHash}
504+
blockMarkdown={blockMarkdown}
495505
pagePath={pagePath}
496506
libraryId={libraryId}
497507
libraryVersion={libraryVersion}
@@ -506,6 +516,7 @@ function CreatingFeedbackNote({
506516
type,
507517
blockSelector,
508518
blockContentHash,
519+
blockMarkdown,
509520
pagePath,
510521
libraryId,
511522
libraryVersion,
@@ -514,6 +525,7 @@ function CreatingFeedbackNote({
514525
type: 'note' | 'improvement'
515526
blockSelector: string
516527
blockContentHash?: string
528+
blockMarkdown?: string
517529
pagePath: string
518530
libraryId: string
519531
libraryVersion: string
@@ -577,6 +589,7 @@ function CreatingFeedbackNote({
577589
libraryVersion: variables.data.libraryVersion,
578590
blockSelector: variables.data.blockSelector,
579591
blockContentHash: variables.data.blockContentHash || null,
592+
blockMarkdown: variables.data.blockMarkdown || null,
580593
status: 'pending',
581594
isDetached: false,
582595
isCollapsed: false,
@@ -645,6 +658,7 @@ function CreatingFeedbackNote({
645658
libraryVersion,
646659
blockSelector,
647660
blockContentHash,
661+
blockMarkdown,
648662
},
649663
})
650664
}

src/db/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ export const docFeedback = pgTable(
566566
libraryVersion: varchar('library_version', { length: 50 }).notNull(), // e.g., "v5.0.0"
567567
blockSelector: text('block_selector').notNull(), // hierarchical selector for resilience
568568
blockContentHash: varchar('block_content_hash', { length: 64 }), // SHA-256 hash for drift detection
569+
blockMarkdown: text('block_markdown'), // Captured content at time of feedback (guards against doc drift)
569570

570571
// State
571572
status: docFeedbackStatusEnum('status').notNull().default('pending'),

src/utils/docFeedback.functions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const createDocFeedback = createServerFn({ method: 'POST' })
3232
libraryVersion: z.string(),
3333
blockSelector: z.string(),
3434
blockContentHash: z.string().optional(),
35+
blockMarkdown: z.string().optional(),
3536
}),
3637
z.object({
3738
type: z.literal('improvement'),
@@ -43,6 +44,7 @@ export const createDocFeedback = createServerFn({ method: 'POST' })
4344
libraryVersion: z.string(),
4445
blockSelector: z.string(),
4546
blockContentHash: z.string().optional(),
47+
blockMarkdown: z.string().optional(),
4648
}),
4749
]),
4850
)
@@ -77,6 +79,7 @@ export const createDocFeedback = createServerFn({ method: 'POST' })
7779
libraryVersion: data.libraryVersion,
7880
blockSelector: data.blockSelector,
7981
blockContentHash: data.blockContentHash,
82+
blockMarkdown: data.blockMarkdown,
8083
characterCount,
8184
status: 'pending' as DocFeedbackStatus,
8285
})

0 commit comments

Comments
 (0)