Skip to content

Commit

Permalink
Replace easy spots
Browse files Browse the repository at this point in the history
  • Loading branch information
estrattonbailey committed Nov 7, 2023
1 parent a97f680 commit 04fe8ca
Show file tree
Hide file tree
Showing 59 changed files with 277 additions and 220 deletions.
8 changes: 4 additions & 4 deletions src/lib/hooks/useOTAUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as Updates from 'expo-updates'
import {useCallback, useEffect} from 'react'
import {AppState} from 'react-native'
import {useStores} from 'state/index'
import {logger} from '#/logger'
import {useModalControls} from '#/state/modals'

export function useOTAUpdate() {
const store = useStores()
const {openModal} = useModalControls()

// HELPER FUNCTIONS
const showUpdatePopup = useCallback(() => {
store.shell.openModal({
openModal({
name: 'confirm',
title: 'Update Available',
message:
Expand All @@ -20,7 +20,7 @@ export function useOTAUpdate() {
})
},
})
}, [store.shell])
}, [openModal])
const checkForUpdate = useCallback(async () => {
logger.debug('useOTAUpdate: Checking for update...')
try {
Expand Down
12 changes: 0 additions & 12 deletions src/lib/media/alt-text.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/state/models/ui/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ export class ShellUiModel {

openModal() {}

closeModal() {}

openLightbox(lightbox: ProfileImageLightbox | ImagesLightbox) {
this.rootStore.emitNavigation()
this.isLightboxActive = true
Expand Down
8 changes: 4 additions & 4 deletions src/view/com/auth/create/Step2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {usePalette} from 'lib/hooks/usePalette'
import {TextInput} from '../util/TextInput'
import {Policies} from './Policies'
import {ErrorMessage} from 'view/com/util/error/ErrorMessage'
import {useStores} from 'state/index'
import {isWeb} from 'platform/detection'
import {useModalControls} from '#/state/modals'

/** STEP 2: Your account
* @field Invite code or waitlist
Expand All @@ -28,11 +28,11 @@ export const Step2 = observer(function Step2Impl({
model: CreateAccountModel
}) {
const pal = usePalette('default')
const store = useStores()
const {openModal} = useModalControls()

const onPressWaitlist = React.useCallback(() => {
store.shell.openModal({name: 'waitlist'})
}, [store])
openModal({name: 'waitlist'})
}, [openModal])

return (
<View>
Expand Down
8 changes: 5 additions & 3 deletions src/view/com/auth/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {useTheme} from 'lib/ThemeContext'
import {cleanError} from 'lib/strings/errors'
import {isWeb} from 'platform/detection'
import {logger} from '#/logger'
import {useModalControls} from '#/state/modals'

enum Forms {
Login,
Expand Down Expand Up @@ -303,9 +304,10 @@ const LoginForm = ({
const [identifier, setIdentifier] = useState<string>(initialHandle)
const [password, setPassword] = useState<string>('')
const passwordInputRef = useRef<TextInput>(null)
const {openModal} = useModalControls()

const onPressSelectService = () => {
store.shell.openModal({
openModal({
name: 'server-input',
initialService: serviceUrl,
onSelect: setServiceUrl,
Expand Down Expand Up @@ -528,7 +530,6 @@ const LoginForm = ({
}

const ForgotPasswordForm = ({
store,
error,
serviceUrl,
serviceDescription,
Expand All @@ -551,13 +552,14 @@ const ForgotPasswordForm = ({
const [isProcessing, setIsProcessing] = useState<boolean>(false)
const [email, setEmail] = useState<string>('')
const {screen} = useAnalytics()
const {openModal} = useModalControls()

useEffect(() => {
screen('Signin:ForgotPassword')
}, [screen])

const onPressSelectService = () => {
store.shell.openModal({
openModal({
name: 'server-input',
initialService: serviceUrl,
onSelect: setServiceUrl,
Expand Down
11 changes: 6 additions & 5 deletions src/view/com/composer/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import {LabelsBtn} from './labels/LabelsBtn'
import {SelectLangBtn} from './select-language/SelectLangBtn'
import {EmojiPickerButton} from './text-input/web/EmojiPicker.web'
import {insertMentionAt} from 'lib/strings/mention-manip'
import {useModals} from '#/state/modals'
import {useModals, useModalControls} from '#/state/modals'

type Props = ComposerOpts
export const ComposePost = observer(function ComposePost({
Expand All @@ -59,6 +59,7 @@ export const ComposePost = observer(function ComposePost({
mention: initMention,
}: Props) {
const {activeModals} = useModals()
const {openModal, closeModal} = useModalControls()
const {track} = useAnalytics()
const pal = usePalette('default')
const {isDesktop, isMobile} = useWebMediaQueries()
Expand Down Expand Up @@ -111,17 +112,17 @@ export const ComposePost = observer(function ComposePost({
const onPressCancel = useCallback(() => {
if (graphemeLength > 0 || !gallery.isEmpty) {
if (activeModals.some(modal => modal.name === 'confirm')) {
store.shell.closeModal()
closeModal()
}
if (Keyboard) {
Keyboard.dismiss()
}
store.shell.openModal({
openModal({
name: 'confirm',
title: 'Discard draft',
onPressConfirm: onClose,
onPressCancel: () => {
store.shell.closeModal()
closeModal()
},
message: "Are you sure you'd like to discard this draft?",
confirmBtnText: 'Discard',
Expand All @@ -130,7 +131,7 @@ export const ComposePost = observer(function ComposePost({
} else {
onClose()
}
}, [store, activeModals, onClose, graphemeLength, gallery])
}, [openModal, closeModal, activeModals, onClose, graphemeLength, gallery])
// android back button
useEffect(() => {
if (!isAndroid) {
Expand Down
6 changes: 3 additions & 3 deletions src/view/com/composer/labels/LabelsBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import {Keyboard, StyleSheet} from 'react-native'
import {observer} from 'mobx-react-lite'
import {Button} from 'view/com/util/forms/Button'
import {usePalette} from 'lib/hooks/usePalette'
import {useStores} from 'state/index'
import {ShieldExclamation} from 'lib/icons'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {FontAwesomeIconStyle} from '@fortawesome/react-native-fontawesome'
import {isNative} from 'platform/detection'
import {useModalControls} from '#/state/modals'

export const LabelsBtn = observer(function LabelsBtn({
labels,
Expand All @@ -19,7 +19,7 @@ export const LabelsBtn = observer(function LabelsBtn({
onChange: (v: string[]) => void
}) {
const pal = usePalette('default')
const store = useStores()
const {openModal} = useModalControls()

return (
<Button
Expand All @@ -34,7 +34,7 @@ export const LabelsBtn = observer(function LabelsBtn({
Keyboard.dismiss()
}
}
store.shell.openModal({name: 'self-label', labels, hasMedia, onChange})
openModal({name: 'self-label', labels, hasMedia, onChange})
}}>
<ShieldExclamation style={pal.link} size={26} />
{labels.length > 0 ? (
Expand Down
15 changes: 10 additions & 5 deletions src/view/com/composer/photos/Gallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import {s, colors} from 'lib/styles'
import {StyleSheet, TouchableOpacity, View} from 'react-native'
import {Image} from 'expo-image'
import {Text} from 'view/com/util/text/Text'
import {openAltTextModal} from 'lib/media/alt-text'
import {Dimensions} from 'lib/media/types'
import {useStores} from 'state/index'
import {usePalette} from 'lib/hooks/usePalette'
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
import {useModalControls} from '#/state/modals'

const IMAGE_GAP = 8

Expand Down Expand Up @@ -47,9 +46,9 @@ const GalleryInner = observer(function GalleryImpl({
gallery,
containerInfo,
}: GalleryInnerProps) {
const store = useStores()
const pal = usePalette('default')
const {isMobile} = useWebMediaQueries()
const {openModal} = useModalControls()

let side: number

Expand Down Expand Up @@ -117,7 +116,10 @@ const GalleryInner = observer(function GalleryImpl({
accessibilityHint=""
onPress={() => {
Keyboard.dismiss()
openAltTextModal(store, image)
openModal({
name: 'alt-text-image',
image,
})
}}
style={[styles.altTextControl, altTextControlStyle]}>
<Text style={styles.altTextControlLabel} accessible={false}>
Expand Down Expand Up @@ -165,7 +167,10 @@ const GalleryInner = observer(function GalleryImpl({
accessibilityHint=""
onPress={() => {
Keyboard.dismiss()
openAltTextModal(store, image)
openModal({
name: 'alt-text-image',
image,
})
}}
style={styles.altTextHiddenRegion}
/>
Expand Down
6 changes: 4 additions & 2 deletions src/view/com/composer/select-language/SelectLangBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ import {usePalette} from 'lib/hooks/usePalette'
import {useStores} from 'state/index'
import {isNative} from 'platform/detection'
import {codeToLanguageName} from '../../../../locale/helpers'
import {useModalControls} from '#/state/modals'

export const SelectLangBtn = observer(function SelectLangBtn() {
const pal = usePalette('default')
const store = useStores()
const {openModal} = useModalControls()

const onPressMore = useCallback(async () => {
if (isNative) {
if (Keyboard.isVisible()) {
Keyboard.dismiss()
}
}
store.shell.openModal({name: 'post-languages-settings'})
}, [store])
openModal({name: 'post-languages-settings'})
}, [openModal])

const postLanguagesPref = store.preferences.postLanguages
const postLanguagePref = store.preferences.postLanguage
Expand Down
8 changes: 4 additions & 4 deletions src/view/com/feeds/FeedSourceCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {observer} from 'mobx-react-lite'
import {FeedSourceModel} from 'state/models/content/feed-source'
import {useNavigation} from '@react-navigation/native'
import {NavigationProp} from 'lib/routes/types'
import {useStores} from 'state/index'
import {pluralize} from 'lib/strings/helpers'
import {AtUri} from '@atproto/api'
import * as Toast from 'view/com/util/Toast'
import {sanitizeHandle} from 'lib/strings/handles'
import {logger} from '#/logger'
import {useModalControls} from '#/state/modals'

export const FeedSourceCard = observer(function FeedSourceCardImpl({
item,
Expand All @@ -30,13 +30,13 @@ export const FeedSourceCard = observer(function FeedSourceCardImpl({
showDescription?: boolean
showLikes?: boolean
}) {
const store = useStores()
const pal = usePalette('default')
const navigation = useNavigation<NavigationProp>()
const {openModal} = useModalControls()

const onToggleSaved = React.useCallback(async () => {
if (item.isSaved) {
store.shell.openModal({
openModal({
name: 'confirm',
title: 'Remove from my feeds',
message: `Remove ${item.displayName} from my feeds?`,
Expand All @@ -59,7 +59,7 @@ export const FeedSourceCard = observer(function FeedSourceCardImpl({
logger.error('Failed to save feed', {error: e})
}
}
}, [store, item])
}, [openModal, item])

return (
<Pressable
Expand Down
8 changes: 4 additions & 4 deletions src/view/com/lists/ListItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import {Button} from '../util/forms/Button'
import {ListModel} from 'state/models/content/list'
import {useAnalytics} from 'lib/analytics/analytics'
import {usePalette} from 'lib/hooks/usePalette'
import {useStores} from 'state/index'
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
import {s} from 'lib/styles'
import {OnScrollCb} from 'lib/hooks/useOnMainScroll'
import {logger} from '#/logger'
import {useModalControls} from '#/state/modals'

const LOADING_ITEM = {_reactKey: '__loading__'}
const EMPTY_ITEM = {_reactKey: '__empty__'}
Expand Down Expand Up @@ -54,10 +54,10 @@ export const ListItems = observer(function ListItemsImpl({
desktopFixedHeightOffset?: number
}) {
const pal = usePalette('default')
const store = useStores()
const {track} = useAnalytics()
const [isRefreshing, setIsRefreshing] = React.useState(false)
const {isMobile} = useWebMediaQueries()
const {openModal} = useModalControls()

const data = React.useMemo(() => {
let items: any[] = []
Expand Down Expand Up @@ -115,7 +115,7 @@ export const ListItems = observer(function ListItemsImpl({

const onPressEditMembership = React.useCallback(
(profile: AppBskyActorDefs.ProfileViewBasic) => {
store.shell.openModal({
openModal({
name: 'user-add-remove-lists',
subject: profile.did,
displayName: profile.displayName || profile.handle,
Expand All @@ -131,7 +131,7 @@ export const ListItems = observer(function ListItemsImpl({
},
})
},
[store, list],
[openModal, list],
)

// rendering
Expand Down
6 changes: 4 additions & 2 deletions src/view/com/modals/AddAppPasswords.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import Clipboard from '@react-native-clipboard/clipboard'
import * as Toast from '../util/Toast'
import {logger} from '#/logger'
import {useModalControls} from '#/state/modals'

export const snapPoints = ['70%']

Expand Down Expand Up @@ -54,6 +55,7 @@ const shadesOfBlue: string[] = [
export function Component({}: {}) {
const pal = usePalette('default')
const store = useStores()
const {closeModal} = useModalControls()
const [name, setName] = useState(
shadesOfBlue[Math.floor(Math.random() * shadesOfBlue.length)],
)
Expand All @@ -69,8 +71,8 @@ export function Component({}: {}) {
}, [appPassword])

const onDone = React.useCallback(() => {
store.shell.closeModal()
}, [store])
closeModal()
}, [closeModal])

const createAppPassword = async () => {
// if name is all whitespace, we don't allow it
Expand Down
Loading

0 comments on commit 04fe8ca

Please sign in to comment.