Skip to content

Commit

Permalink
Implement the reducer
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Oct 4, 2024
1 parent a22058c commit a137a55
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/view/com/composer/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ export const ComposePost = ({

const onNewLink = useCallback(
(uri: string) => {
dispatch({type: 'embed_add_uri', uri})
if (extLink != null) return
setExtLink({uri, isLoading: true})
dispatch({type: 'embed_add_uri', uri})
},
[extLink, setExtLink],
)
Expand Down
97 changes: 85 additions & 12 deletions src/view/com/composer/state/composer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {ImagePickerAsset} from 'expo-image-picker'

import {isBskyPostUrl} from '#/lib/strings/url-helpers'
import {ComposerImage, createInitialImages} from '#/state/gallery'
import {Gif} from '#/state/queries/tenor'
import {ComposerOpts} from '#/state/shell/composer'
Expand Down Expand Up @@ -187,28 +188,100 @@ export function composerReducer(
}
}
case 'embed_add_uri': {
// TODO
return state
const prevQuote = state.embed.quote
const prevLink = state.embed.link
let nextQuote = prevQuote
let nextLink = prevLink
if (isBskyPostUrl(action.uri)) {
if (!prevQuote) {
nextQuote = {
type: 'link',
uri: action.uri,
}
}
} else {
if (!prevLink) {
nextLink = {
type: 'link',
uri: action.uri,
}
}
}
return {
...state,
embed: {
...state.embed,
quote: nextQuote,
link: nextLink,
},
}
}
case 'embed_remove_link': {
// TODO
return state
return {
...state,
embed: {
...state.embed,
link: undefined,
},
}
}
case 'embed_remove_quote': {
// TODO
return state
return {
...state,
embed: {
...state.embed,
quote: undefined,
},
}
}
case 'embed_add_gif': {
// TODO
return state
const prevMedia = state.embed.media
let nextMedia = prevMedia
if (!prevMedia) {
nextMedia = {
type: 'gif',
gif: action.gif,
alt: '',
}
}
return {
...state,
embed: {
...state.embed,
media: nextMedia,
},
}
}
case 'embed_update_gif': {
// TODO
return state
const prevMedia = state.embed.media
let nextMedia = prevMedia
if (prevMedia?.type === 'gif') {
nextMedia = {
...prevMedia,
alt: action.alt,
}
}
return {
...state,
embed: {
...state.embed,
media: nextMedia,
},
}
}
case 'embed_remove_gif': {
// TODO
return state
const prevMedia = state.embed.media
let nextMedia = prevMedia
if (prevMedia?.type === 'gif') {
nextMedia = undefined
}
return {
...state,
embed: {
...state.embed,
media: nextMedia,
},
}
}
default:
return state
Expand Down

0 comments on commit a137a55

Please sign in to comment.