Skip to content

Commit

Permalink
feat: Implement useFlagshipUI() in OsReceiveScreen view
Browse files Browse the repository at this point in the history
  • Loading branch information
Ldoppea committed Jan 4, 2024
1 parent 06d8af0 commit 2fc7461
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 27 deletions.
8 changes: 0 additions & 8 deletions src/app/view/OsReceive/OsReceiveScreen.styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ export const osReceiveScreenStyles = {
},
singleFileTitle: { alignSelf: 'center', marginBottom: 24 },
appIcon: { minWidth: 32 },
setFlagshipUI: {
bottomBackground: 'white',
bottomTheme: 'dark',
bottomOverlay: 'transparent',
topBackground: 'white',
topTheme: 'dark',
topOverlay: 'transparent'
},
appName: {
lineHeight: 21
},
Expand Down
47 changes: 41 additions & 6 deletions src/app/view/OsReceive/OsReceiveScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import React from 'react'
import { StyleProp, TextStyle } from 'react-native'
import { SvgXml } from 'react-native-svg'

import { FlagshipUI } from 'cozy-intent'

import { OsReceiveFile } from '/app/domain/osReceive/models/OsReceiveState'
import { AppForUpload } from '/app/domain/osReceive/models/OsReceiveCozyApp'
import { ScreenIndexes, useFlagshipUI } from '/app/view/FlagshipUI'
import { Icon } from '/ui/Icon'
import { Container } from '/ui/Container'
import { Grid } from '/ui/Grid'
Expand Down Expand Up @@ -31,10 +36,40 @@ import { useCozyTheme } from '/ui/CozyTheme/CozyTheme'
import { FileDuotone } from '/ui/Icons/FileDuotone'
import { FileThumbnail } from '/ui/ImageThumbnail'

const defaultFlagshipUI: FlagshipUI = {
bottomTheme: 'dark',
topTheme: 'dark'
}

export const OsReceiveScreen = (): JSX.Element | null => {
const filesToUpload = useFilesToUpload()
const { hasAllFilesQueued } = useFilesQueueStatus()
const appsForUpload = useAppsForUpload()

const hasFilesToUpload = filesToUpload.length > 0
const shouldRender =
(hasFilesToUpload && appsForUpload && appsForUpload.length > 0) ||
hasAllFilesQueued

if (!shouldRender) return null

return (
<OsReceiveScreenView
filesToUpload={filesToUpload}
appsForUpload={appsForUpload}
/>
)
}

interface OsReceiveScreenViewProps {
filesToUpload: OsReceiveFile[]
appsForUpload: AppForUpload[] | undefined
}

export const OsReceiveScreenView = ({
filesToUpload,
appsForUpload
}: OsReceiveScreenViewProps): JSX.Element | null => {
const { t } = useI18n()
const {
selectedOption,
Expand All @@ -45,14 +80,14 @@ export const OsReceiveScreen = (): JSX.Element | null => {
} = useOsReceiveScreenLogic()
const { colors } = useCozyTheme('normal')

const hasFilesToUpload = filesToUpload.length > 0
useFlagshipUI(
'OsReceiveScreen',
ScreenIndexes.OS_RECEIVE_SCREEN,
defaultFlagshipUI
)

const isSingleFile = filesToUpload.length === 1
const isMultipleFiles = filesToUpload.length > 1
const shouldRender =
(hasFilesToUpload && appsForUpload && appsForUpload.length > 0) ||
hasAllFilesQueued

if (!shouldRender) return null

return (
<Container style={osReceiveScreenStyles.page}>
Expand Down
13 changes: 0 additions & 13 deletions src/app/view/OsReceive/hooks/useOsReceiveScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from 'react'

import { generateWebLink, useClient } from 'cozy-client'
import { FlagshipUI } from 'cozy-intent'

import {
useFilesToUpload,
Expand All @@ -23,11 +22,8 @@ import {
import { CozyAppParams } from '/constants/route-types'
import { routes } from '/constants/routes'
import { useDefaultIconParams } from '/libs/functions/openApp'
import { setFlagshipUI } from '/libs/intents/setFlagshipUI'
import { navigate, navigationRef } from '/libs/RootNavigation'

import { osReceiveScreenStyles } from '/app/view/OsReceive/OsReceiveScreen.styles'

export const useOsReceiveScreenLogic = (): {
selectedOption: string | undefined
setSelectedOption: Dispatch<SetStateAction<string | undefined>>
Expand Down Expand Up @@ -108,15 +104,6 @@ export const useOsReceiveScreenLogic = (): {
})
}, [client, appsForUpload, selectedOption, iconParams, osReceiveDispatch])

useEffect(() => {
if (filesToUpload.length > 0) {
void setFlagshipUI(
osReceiveScreenStyles.setFlagshipUI as FlagshipUI,
'OsReceiveScreen'
)
}
}, [filesToUpload, appsForUpload])

useEffect(() => {
const firstEnabledApp = appsForUpload?.find(app => !app.reasonDisabled)

Expand Down

0 comments on commit 2fc7461

Please sign in to comment.