Composer update (react-query refactor) (#1899)
* Move composer state to a context * Rework composer to use RQ --------- Co-authored-by: Eric Bailey <git@esb.lol>
This commit is contained in:
@@ -11,13 +11,15 @@ import {Paragraph} from '@tiptap/extension-paragraph'
|
||||
import {Placeholder} from '@tiptap/extension-placeholder'
|
||||
import {Text} from '@tiptap/extension-text'
|
||||
import isEqual from 'lodash.isequal'
|
||||
import {UserAutocompleteModel} from 'state/models/discovery/user-autocomplete'
|
||||
import {createSuggestion} from './web/Autocomplete'
|
||||
import {useColorSchemeStyle} from 'lib/hooks/useColorSchemeStyle'
|
||||
import {isUriImage, blobToDataUri} from 'lib/media/util'
|
||||
import {Emoji} from './web/EmojiPicker.web'
|
||||
import {LinkDecorator} from './web/LinkDecorator'
|
||||
import {generateJSON} from '@tiptap/html'
|
||||
import {ActorAutocomplete} from '#/state/queries/actor-autocomplete'
|
||||
import {useSession} from '#/state/session'
|
||||
import {useMyFollowsQuery} from '#/state/queries/my-follows'
|
||||
|
||||
export interface TextInputRef {
|
||||
focus: () => void
|
||||
@@ -28,7 +30,6 @@ interface TextInputProps {
|
||||
richtext: RichText
|
||||
placeholder: string
|
||||
suggestedLinks: Set<string>
|
||||
autocompleteView: UserAutocompleteModel
|
||||
setRichText: (v: RichText | ((v: RichText) => RichText)) => void
|
||||
onPhotoPasted: (uri: string) => void
|
||||
onPressPublish: (richtext: RichText) => Promise<void>
|
||||
@@ -43,7 +44,6 @@ export const TextInput = React.forwardRef(function TextInputImpl(
|
||||
richtext,
|
||||
placeholder,
|
||||
suggestedLinks,
|
||||
autocompleteView,
|
||||
setRichText,
|
||||
onPhotoPasted,
|
||||
onPressPublish,
|
||||
@@ -52,6 +52,16 @@ export const TextInput = React.forwardRef(function TextInputImpl(
|
||||
TextInputProps,
|
||||
ref,
|
||||
) {
|
||||
const {agent} = useSession()
|
||||
const autocomplete = React.useMemo(
|
||||
() => new ActorAutocomplete(agent),
|
||||
[agent],
|
||||
)
|
||||
const {data: follows} = useMyFollowsQuery()
|
||||
if (follows) {
|
||||
autocomplete.setFollows(follows)
|
||||
}
|
||||
|
||||
const modeClass = useColorSchemeStyle('ProseMirror-light', 'ProseMirror-dark')
|
||||
const extensions = React.useMemo(
|
||||
() => [
|
||||
@@ -61,7 +71,7 @@ export const TextInput = React.forwardRef(function TextInputImpl(
|
||||
HTMLAttributes: {
|
||||
class: 'mention',
|
||||
},
|
||||
suggestion: createSuggestion({autocompleteView}),
|
||||
suggestion: createSuggestion({autocomplete}),
|
||||
}),
|
||||
Paragraph,
|
||||
Placeholder.configure({
|
||||
@@ -71,7 +81,7 @@ export const TextInput = React.forwardRef(function TextInputImpl(
|
||||
History,
|
||||
Hardbreak,
|
||||
],
|
||||
[autocompleteView, placeholder],
|
||||
[autocomplete, placeholder],
|
||||
)
|
||||
|
||||
React.useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user