+ {!contracts.length ? (
+
No results...
+ ) : (
+ contracts.map((contract, i) => (
+
+ ))
+ )}
+
+ )
+})
+
+// Just to keep the formatting pretty
+export { M as MentionList }
diff --git a/web/components/editor/contract-mention-suggestion.ts b/web/components/editor/contract-mention-suggestion.ts
new file mode 100644
index 00000000..39d024e7
--- /dev/null
+++ b/web/components/editor/contract-mention-suggestion.ts
@@ -0,0 +1,27 @@
+import type { MentionOptions } from '@tiptap/extension-mention'
+import { searchInAny } from 'common/util/parse'
+import { orderBy } from 'lodash'
+import { getCachedContracts } from 'web/hooks/use-contracts'
+import { MentionList } from './contract-mention-list'
+import { PluginKey } from 'prosemirror-state'
+import { makeMentionRender } from './mention-suggestion'
+
+type Suggestion = MentionOptions['suggestion']
+
+const beginsWith = (text: string, query: string) =>
+ text.toLocaleLowerCase().startsWith(query.toLocaleLowerCase())
+
+export const contractMentionSuggestion: Suggestion = {
+ char: '%',
+ allowSpaces: true,
+ pluginKey: new PluginKey('contract-mention'),
+ items: async ({ query }) =>
+ orderBy(
+ (await getCachedContracts()).filter((c) =>
+ searchInAny(query, c.question)
+ ),
+ [(c) => [c.question].some((s) => beginsWith(s, query))],
+ ['desc', 'desc']
+ ).slice(0, 5),
+ render: makeMentionRender(MentionList),
+}
diff --git a/web/components/editor/contract-mention.tsx b/web/components/editor/contract-mention.tsx
new file mode 100644
index 00000000..ddc81bc0
--- /dev/null
+++ b/web/components/editor/contract-mention.tsx
@@ -0,0 +1,42 @@
+import Mention from '@tiptap/extension-mention'
+import {
+ mergeAttributes,
+ NodeViewWrapper,
+ ReactNodeViewRenderer,
+} from '@tiptap/react'
+import clsx from 'clsx'
+import { useContract } from 'web/hooks/use-contract'
+import { ContractCard } from '../contract/contract-card'
+
+const name = 'contract-mention-component'
+
+const ContractMentionComponent = (props: any) => {
+ const contract = useContract(props.node.attrs.id)
+
+ return (
+