Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add modal state provider, replace usage except methods #1833

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/App.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as Toast from 'view/com/util/Toast'
import {queryClient} from 'lib/react-query'
import {TestCtrls} from 'view/com/testing/TestCtrls'
import {Provider as ShellStateProvider} from 'state/shell'
import {Provider as ModalStateProvider} from 'state/modals'
import {Provider as MutedThreadsProvider} from 'state/muted-threads'
import {Provider as InvitesStateProvider} from 'state/invites'
import {Provider as PrefsStateProvider} from 'state/preferences'
Expand Down Expand Up @@ -84,7 +85,9 @@ function App() {
<PrefsStateProvider>
<MutedThreadsProvider>
<InvitesStateProvider>
<InnerApp />
<ModalStateProvider>
<InnerApp />
</ModalStateProvider>
</InvitesStateProvider>
</MutedThreadsProvider>
</PrefsStateProvider>
Expand Down
5 changes: 4 additions & 1 deletion src/App.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {ToastContainer} from 'view/com/util/Toast.web'
import {ThemeProvider} from 'lib/ThemeContext'
import {queryClient} from 'lib/react-query'
import {Provider as ShellStateProvider} from 'state/shell'
import {Provider as ModalStateProvider} from 'state/modals'
import {Provider as MutedThreadsProvider} from 'state/muted-threads'
import {Provider as InvitesStateProvider} from 'state/invites'
import {Provider as PrefsStateProvider} from 'state/preferences'
Expand Down Expand Up @@ -74,7 +75,9 @@ function App() {
<PrefsStateProvider>
<MutedThreadsProvider>
<InvitesStateProvider>
<InnerApp />
<ModalStateProvider>
<InnerApp />
</ModalStateProvider>
</InvitesStateProvider>
</MutedThreadsProvider>
</PrefsStateProvider>
Expand Down
5 changes: 4 additions & 1 deletion src/lib/hooks/useAccountSwitcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {AccountData} from 'state/models/session'
import {reset as resetNavigation} from '../../Navigation'
import * as Toast from 'view/com/util/Toast'
import {useSetDrawerOpen} from '#/state/shell/drawer-open'
import {useModalControls} from '#/state/modals'

export function useAccountSwitcher(): [
boolean,
Expand All @@ -16,6 +17,7 @@ export function useAccountSwitcher(): [
const {track} = useAnalytics()
const store = useStores()
const setDrawerOpen = useSetDrawerOpen()
const {closeModal} = useModalControls()
const [isSwitching, setIsSwitching] = useState(false)
const navigation = useNavigation<NavigationProp>()

Expand All @@ -25,6 +27,7 @@ export function useAccountSwitcher(): [
setIsSwitching(true)
const success = await store.session.resumeSession(acct)
setDrawerOpen(false)
closeModal()
store.shell.closeAllActiveElements()
if (success) {
resetNavigation()
Expand All @@ -36,7 +39,7 @@ export function useAccountSwitcher(): [
store.session.clear()
}
},
[track, setIsSwitching, navigation, store, setDrawerOpen],
[track, setIsSwitching, navigation, store, setDrawerOpen, closeModal],
)

return [isSwitching, setIsSwitching, onPressSwitchAccount]
Expand Down
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.

5 changes: 3 additions & 2 deletions src/lib/media/picker.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {CameraOpts, CropperOptions} from './types'
import {RootStoreModel} from 'state/index'
import {Image as RNImage} from 'react-native-image-crop-picker'
export {openPicker} from './picker.shared'
import {unstable__openModal} from '#/state/modals'

export async function openCamera(
_store: RootStoreModel,
Expand All @@ -14,12 +15,12 @@ export async function openCamera(
}

export async function openCropper(
store: RootStoreModel,
_store: RootStoreModel,
opts: CropperOptions,
): Promise<RNImage> {
// TODO handle more opts
return new Promise((resolve, reject) => {
store.shell.openModal({
unstable__openModal({
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this hacky global I'd need to pass through 2 mobx models and into this file 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the only reason the store model was being passed to these methods was for that. I'm fine with this hack but we should also ditch that param at some point (can be later)

name: 'crop-image',
uri: opts.path,
onSelect: (img?: RNImage) => {
Expand Down
Loading