* feat: initial user card hover * feat: flesh it out some more * fix: initialize middlewares once * chore: remove floating-ui react-native * chore: clean up * Update moderation apis, fix lint * Refactor profile hover card to alf * Clean up * Debounce, fix positioning when loading * Fix going away * Close on all link presses * Tweak styles * Disable on mobile web * cleanup some of the changes pt. 1 * cleanup some of the changes pt. 2 * cleanup some of the changes pt. 3 * cleanup some of the changes pt. 4 * Re-revert files * Fix handle presentation * Don't follow yourself, silly * Collapsed notifications group * ProfileCard * Tree view replies * Suggested follows * Fix hover-back-on-card edge case * Moar --------- Co-authored-by: Mary <git@mary.my.id> Co-authored-by: Hailey <me@haileyok.com>
33 lines
1,004 B
TypeScript
33 lines
1,004 B
TypeScript
import React from 'react'
|
|
import {RichText as RichTextAPI} from '@atproto/api'
|
|
|
|
import {getAgent} from '#/state/session'
|
|
|
|
export function useRichText(text: string): [RichTextAPI, boolean] {
|
|
const [prevText, setPrevText] = React.useState(text)
|
|
const [rawRT, setRawRT] = React.useState(() => new RichTextAPI({text}))
|
|
const [resolvedRT, setResolvedRT] = React.useState<RichTextAPI | null>(null)
|
|
if (text !== prevText) {
|
|
setPrevText(text)
|
|
setRawRT(new RichTextAPI({text}))
|
|
setResolvedRT(null)
|
|
// This will queue an immediate re-render
|
|
}
|
|
React.useEffect(() => {
|
|
let ignore = false
|
|
async function resolveRTFacets() {
|
|
// new each time
|
|
const resolvedRT = new RichTextAPI({text})
|
|
await resolvedRT.detectFacets(getAgent())
|
|
if (!ignore) {
|
|
setResolvedRT(resolvedRT)
|
|
}
|
|
}
|
|
resolveRTFacets()
|
|
return () => {
|
|
ignore = true
|
|
}
|
|
}, [text])
|
|
const isResolving = resolvedRT === null
|
|
return [resolvedRT ?? rawRT, isResolving]
|
|
}
|