Add modal state provider, replace usage except methods (#1833)
* Add modal state provider, replace usage except methods * Replace easy spots * Fix sticky spots * Replace final usages * Memorize context objects * Add more warnings
This commit is contained in:
parent
5eadadffbf
commit
f18b15241a
70 changed files with 634 additions and 498 deletions
|
@ -16,6 +16,7 @@ import {useStores} from 'state/index'
|
|||
import {RepostButton} from './RepostButton'
|
||||
import {Haptics} from 'lib/haptics'
|
||||
import {HITSLOP_10, HITSLOP_20} from 'lib/constants'
|
||||
import {useModalControls} from '#/state/modals'
|
||||
|
||||
interface PostCtrlsOpts {
|
||||
itemUri: string
|
||||
|
@ -51,6 +52,7 @@ interface PostCtrlsOpts {
|
|||
export function PostCtrls(opts: PostCtrlsOpts) {
|
||||
const store = useStores()
|
||||
const theme = useTheme()
|
||||
const {closeModal} = useModalControls()
|
||||
const defaultCtrlColor = React.useMemo(
|
||||
() => ({
|
||||
color: theme.palette.default.postCtrl,
|
||||
|
@ -58,17 +60,17 @@ export function PostCtrls(opts: PostCtrlsOpts) {
|
|||
[theme],
|
||||
) as StyleProp<ViewStyle>
|
||||
const onRepost = useCallback(() => {
|
||||
store.shell.closeModal()
|
||||
closeModal()
|
||||
if (!opts.isReposted) {
|
||||
Haptics.default()
|
||||
opts.onPressToggleRepost().catch(_e => undefined)
|
||||
} else {
|
||||
opts.onPressToggleRepost().catch(_e => undefined)
|
||||
}
|
||||
}, [opts, store.shell])
|
||||
}, [opts, closeModal])
|
||||
|
||||
const onQuote = useCallback(() => {
|
||||
store.shell.closeModal()
|
||||
closeModal()
|
||||
store.shell.openComposer({
|
||||
quote: {
|
||||
uri: opts.itemUri,
|
||||
|
@ -86,6 +88,7 @@ export function PostCtrls(opts: PostCtrlsOpts) {
|
|||
opts.itemUri,
|
||||
opts.text,
|
||||
store.shell,
|
||||
closeModal,
|
||||
])
|
||||
|
||||
const onPressToggleLikeWrapper = async () => {
|
||||
|
|
|
@ -5,8 +5,8 @@ import {s, colors} from 'lib/styles'
|
|||
import {useTheme} from 'lib/ThemeContext'
|
||||
import {Text} from '../text/Text'
|
||||
import {pluralize} from 'lib/strings/helpers'
|
||||
import {useStores} from 'state/index'
|
||||
import {HITSLOP_10, HITSLOP_20} from 'lib/constants'
|
||||
import {useModalControls} from '#/state/modals'
|
||||
|
||||
interface Props {
|
||||
isReposted: boolean
|
||||
|
@ -23,8 +23,8 @@ export const RepostButton = ({
|
|||
onRepost,
|
||||
onQuote,
|
||||
}: Props) => {
|
||||
const store = useStores()
|
||||
const theme = useTheme()
|
||||
const {openModal} = useModalControls()
|
||||
|
||||
const defaultControlColor = React.useMemo(
|
||||
() => ({
|
||||
|
@ -34,13 +34,13 @@ export const RepostButton = ({
|
|||
)
|
||||
|
||||
const onPressToggleRepostWrapper = useCallback(() => {
|
||||
store.shell.openModal({
|
||||
openModal({
|
||||
name: 'repost',
|
||||
onRepost: onRepost,
|
||||
onQuote: onQuote,
|
||||
isReposted,
|
||||
})
|
||||
}, [onRepost, onQuote, isReposted, store.shell])
|
||||
}, [onRepost, onQuote, isReposted, openModal])
|
||||
|
||||
return (
|
||||
<TouchableOpacity
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue