Track links and embeds in the composer reducer (#5593)

* Scaffold embed draft types

These don't map 1:1 to the record structure. Rather, we select data from the draft on posting.

* Prefill initial quote

* Implement the reducer
This commit is contained in:
dan
2024-10-05 03:39:33 +09:00
committed by GitHub
parent 6382fe4535
commit 282db85c06
2 changed files with 151 additions and 17 deletions
+15 -2
View File
@@ -190,7 +190,7 @@ export const ComposePost = ({
// TODO: Move more state here.
const [composerState, dispatch] = useReducer(
composerReducer,
{initImageUris},
{initImageUris, initQuoteUri: initQuote?.uri},
createComposerState,
)
@@ -337,6 +337,7 @@ export const ComposePost = ({
const onNewLink = useCallback(
(uri: string) => {
dispatch({type: 'embed_add_uri', uri})
if (extLink != null) return
setExtLink({uri, isLoading: true})
},
@@ -582,6 +583,7 @@ export const ComposePost = ({
const onSelectGif = useCallback(
(gif: Gif) => {
dispatch({type: 'embed_add_gif', gif})
setExtLink({
uri: `${gif.media_formats.gif.url}?hh=${gif.media_formats.gif.dims[1]}&ww=${gif.media_formats.gif.dims[0]}`,
isLoading: true,
@@ -600,6 +602,7 @@ export const ComposePost = ({
const handleChangeGifAltText = useCallback(
(altText: string) => {
dispatch({type: 'embed_update_gif', alt: altText})
setExtLink(ext =>
ext && ext.meta
? {
@@ -770,6 +773,11 @@ export const ComposePost = ({
link={extLink}
gif={extGif}
onRemove={() => {
if (extGif) {
dispatch({type: 'embed_remove_gif'})
} else {
dispatch({type: 'embed_remove_link'})
}
setExtLink(undefined)
setExtGif(undefined)
}}
@@ -818,7 +826,12 @@ export const ComposePost = ({
<QuoteEmbed quote={quote} />
</View>
{quote.uri !== initQuote?.uri && (
<QuoteX onRemove={() => setQuote(undefined)} />
<QuoteX
onRemove={() => {
dispatch({type: 'embed_remove_quote'})
setQuote(undefined)
}}
/>
)}
</View>
) : null}