Skip to content

Commit 0a4eff2

Browse files
committed
feat: show/hide citations
1 parent 03e746b commit 0a4eff2

2 files changed

Lines changed: 48 additions & 3 deletions

File tree

frontend/app/transcriptions/[transcriptionId]/MinuteTab/components/editor/tiptap-editor.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ function SimpleEditor({
3333
onContentChange,
3434
isEditing,
3535
currentTranscription,
36+
hideCitations,
3637
}: {
3738
initialContent: string
3839
onContentChange: (newContent: string) => void
3940
isEditing: boolean
4041
currentTranscription: Transcription
42+
hideCitations: boolean
4143
}) {
4244
const {
4345
citationPopover,
@@ -56,7 +58,7 @@ function SimpleEditor({
5658
props: {
5759
decorations(state) {
5860
const decorations: Decoration[] = []
59-
const citationRegex = /\[(\d+)\]/g
61+
const citationRegex = /(\s?)\[(\d+)\]/g
6062

6163
state.doc.descendants((node, pos) => {
6264
if (node.isText) {
@@ -67,6 +69,11 @@ function SimpleEditor({
6769
const to = from + match[0].length
6870
decorations.push(
6971
Decoration.inline(from, to, {
72+
style: 'display: var(--citation-display);',
73+
})
74+
)
75+
decorations.push(
76+
Decoration.inline(from + match[1].length, to, {
7077
class: 'citation-link',
7178
style:
7279
'color: blue; cursor: pointer; text-decoration: underline;',
@@ -266,7 +273,15 @@ function SimpleEditor({
266273
</div>
267274
)}
268275

269-
<EditorContent editor={editorObject} className={cn('editor-content')} />
276+
<EditorContent
277+
editor={editorObject}
278+
className={cn('editor-content')}
279+
style={
280+
{
281+
'--citation-display': hideCitations ? 'none' : 'unset',
282+
} as React.CSSProperties
283+
}
284+
/>
270285

271286
{citationPopover && (
272287
<CitationPopoverWrapper

frontend/app/transcriptions/[transcriptionId]/MinuteTab/minute-editor/minute-editor.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
2323
import {
2424
Download,
2525
Edit,
26+
Eye,
27+
EyeOff,
2628
FilePenLine,
2729
FileQuestion,
2830
FileX2,
@@ -46,6 +48,7 @@ export function MinuteEditor({
4648
minute: MinuteListItem
4749
}) {
4850
const [version, setVersion] = useState(0)
51+
const [hideCitations, setHideCitations] = useState(false)
4952
const { data: minuteVersions = [], isLoading } = useQuery({
5053
...listMinuteVersionsMinutesMinuteIdVersionsGetOptions({
5154
path: { minute_id: minute.id! },
@@ -82,6 +85,12 @@ export function MinuteEditor({
8285
}
8386
}, [form, minuteVersion])
8487
const htmlContent = form.watch('html')
88+
const contentToCopy = useMemo(() => {
89+
return htmlContent?.replaceAll(/\s?\[(\d+)\]/g, '') || ''
90+
}, [htmlContent])
91+
const hasCitations = useMemo(() => {
92+
return !!htmlContent?.match(/\[(\d+)\]/)
93+
}, [htmlContent])
8594
useEffect(() => {}, [htmlContent])
8695
const { mutate: saveEdit } = useMutation({
8796
...createMinuteVersionMinutesMinuteIdVersionsPostMutation(),
@@ -250,9 +259,29 @@ export function MinuteEditor({
250259
Download
251260
</Button>
252261
<CopyButton
253-
textToCopy={htmlContent}
262+
textToCopy={contentToCopy}
254263
posthogEvent="editor_content_copied"
255264
/>
265+
{hasCitations && (
266+
<Button
267+
variant="outline"
268+
onClick={() => setHideCitations((h) => !h)}
269+
disabled={isEditable}
270+
>
271+
{isEditable ? (
272+
'Citations shown when editing'
273+
) : hideCitations ? (
274+
<>
275+
<Eye /> Show Citations
276+
</>
277+
) : (
278+
<>
279+
<EyeOff />
280+
Hide Citations
281+
</>
282+
)}
283+
</Button>
284+
)}
256285
</div>
257286
<div className="flex gap-2">
258287
<RatingButton
@@ -272,6 +301,7 @@ export function MinuteEditor({
272301
initialContent={minuteVersion.html_content || ''}
273302
isEditing={isEditable}
274303
onContentChange={onChange}
304+
hideCitations={hideCitations && !isEditable}
275305
/>
276306
)}
277307
/>

0 commit comments

Comments
 (0)