Skip to content

Commit

Permalink
Merge pull request #1969 from oasisprotocol/ml/app-update-wall-follow-up
Browse files Browse the repository at this point in the history
Move useIonicRequiresUpdate state
  • Loading branch information
lubej authored Jun 7, 2024
2 parents 5d3daa9 + 412f284 commit 812d62e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
1 change: 1 addition & 0 deletions .changelog/1969.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add Android update screen
2 changes: 1 addition & 1 deletion src/app/components/Ionic/components/UpdateGate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const UpdateGate: FC<PropsWithChildren> = ({ children }) => {
const { t } = useTranslation()
const isMobile = useContext(ResponsiveContext) === 'small'
const {
state: { updateAvailability },
requiresUpdateState: { updateAvailability },
checkForUpdateAvailability,
skipUpdate,
} = useContext(IonicContext)
Expand Down
18 changes: 11 additions & 7 deletions src/app/components/Ionic/hooks/useIonicRequiresUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Dispatch, SetStateAction, useEffect } from 'react'
import { IonicProviderState, UpdateAvailability } from '../providers/IonicContext'
import { useEffect, useState } from 'react'
import { IonicRequiresUpdateState, UpdateAvailability } from '../providers/IonicContext'
import { updateAvailable } from '../utils/capacitor-app-update'

export const useIonicRequiresUpdate = (
state: IonicProviderState,
setState: Dispatch<SetStateAction<IonicProviderState>>,
) => {
const ionicRequiresUpdateInitialState: IonicRequiresUpdateState = {
updateAvailability: UpdateAvailability.NOT_INITIALIZED,
error: null,
}

export const useIonicRequiresUpdate = () => {
const [state, setState] = useState<IonicRequiresUpdateState>({ ...ionicRequiresUpdateInitialState })

const checkForUpdateAvailability = async () => {
if (state.updateAvailability === UpdateAvailability.LOADING) {
return
Expand Down Expand Up @@ -35,5 +39,5 @@ export const useIonicRequiresUpdate = (
setState(prevState => ({ ...prevState, updateAvailability: UpdateAvailability.UPDATE_NOT_AVAILABLE }))
}

return { checkForUpdateAvailability, skipUpdate }
return { requiresUpdateState: state, checkForUpdateAvailability, skipUpdate }
}
4 changes: 2 additions & 2 deletions src/app/components/Ionic/providers/IonicContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ export enum UpdateAvailability {
UNKNOWN,
}

export interface IonicProviderState {
export interface IonicRequiresUpdateState {
updateAvailability: UpdateAvailability
error: Error | null
}

export interface IonicProviderContext {
readonly state: IonicProviderState
readonly requiresUpdateState: IonicRequiresUpdateState
checkForUpdateAvailability: () => void
skipUpdate: () => void
}
Expand Down
15 changes: 4 additions & 11 deletions src/app/components/Ionic/providers/IonicProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import { FC, PropsWithChildren, useState } from 'react'
import { FC, PropsWithChildren } from 'react'
import { useIonicBackButtonListener } from '../hooks/useIonicBackButtonListener'
import { useIonicAppStateChangeListener } from '../hooks/useIonicAppStateChangeListener'
import { IonicContext, IonicProviderContext, IonicProviderState, UpdateAvailability } from './IonicContext'
import { IonicContext, IonicProviderContext } from './IonicContext'
import { useIonicRequiresUpdate } from '../hooks/useIonicRequiresUpdate'

const ionicProviderInitialState: IonicProviderState = {
updateAvailability: UpdateAvailability.NOT_INITIALIZED,
error: null,
}

export const IonicContextProvider: FC<PropsWithChildren> = ({ children }) => {
const [state, setState] = useState<IonicProviderState>({ ...ionicProviderInitialState })

const { checkForUpdateAvailability, skipUpdate } = useIonicRequiresUpdate(state, setState)
const { requiresUpdateState, checkForUpdateAvailability, skipUpdate } = useIonicRequiresUpdate()
useIonicAppStateChangeListener()
useIonicBackButtonListener()

const providerState: IonicProviderContext = {
state,
requiresUpdateState,
checkForUpdateAvailability,
skipUpdate,
}
Expand Down

0 comments on commit 812d62e

Please sign in to comment.