Build a review sidebar

Use citation queries and subscriptions to keep a review sidebar up to date.

Render the review queue from a configured Smart Citations editor, then refresh it when citations change. Call the returned unsubscribe function when the sidebar unmounts.

Try the sidebar in the Smart Citations demo. Use Show citations to filter the list, then open a citation to jump to it and see the review actions.

import type { Editor } from '@tiptap/core'
import { getCitation, getCitations, subscribeCitations } from '@tiptap-pro/extension-smart-citations'
import type { Citation } from '@tiptap-pro/extension-smart-citations'

function watchReviewQueue(editor: Editor, render: (citations: readonly Citation[]) => void) {
  const refresh = () => render(getCitations({ editor, filter: { status: 'invalid' } }))
  refresh()
  return subscribeCitations({ editor, listener: refresh })
}

function goToCitation(editor: Editor, id: string) {
  const citation = getCitation({ editor, id })
  const range = citation?.ranges[0]
  if (!citation || !range) return

  const chain = editor.chain().focus()
  if (citation.kind === 'node') {
    chain.setNodeSelection(range.from)
  } else {
    chain.setTextSelection(range)
  }
  chain.scrollIntoView().run()
}

Keep the citation ID on each row. Several citations can share a source ID. Pass the citation ID to goToCitation and the review commands. Read fresh ranges on click because edits can move or remove a citation. The example navigates to the first surviving range.

Use citation clicks to open the relevant review item when a user clicks a citation.