Skip to content

Commit

Permalink
feat: disable cloud service entries if no certain env exist
Browse files Browse the repository at this point in the history
  • Loading branch information
arianrhodsandlot committed Jul 2, 2023
1 parent c4631ac commit 3f7e4e8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 17 deletions.
5 changes: 3 additions & 2 deletions src/core/exposed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ export { exitGame } from './exit-game'
export { getAuthorizeUrl } from './get-authorize-url'
export { getStates } from './get-states'
export { getSystemRoms } from './get-system-roms'
export { peekSystemRoms } from './peek-system-roms'
export { getSystems } from './get-systems'
export { getTokenStorageKey } from './get-token-storage-key'
export { grantLocalPermission } from './grant-local-permission'
export { isCloudServiceEnabled } from './is-cloud-service-enabled'
export { isPreferenceValid } from './is-preference-valid'
export { isUsingLocal } from './is-using-local'
export { isUsingOnedrive } from './is-using-onedrive'
Expand All @@ -22,8 +22,9 @@ export { onCancel } from './on-cancel'
export { onConfirm } from './on-confirm'
export { onPress } from './on-press'
export { pauseGame } from './pause-game'
export { resumeGame } from './resume-game'
export { peekSystemRoms } from './peek-system-roms'
export { restartGame } from './restart-game'
export { resumeGame } from './resume-game'
export { retrieveToken } from './retrieve-token'
export { saveGameState } from './save-game-state'
export { start } from './start'
Expand Down
23 changes: 23 additions & 0 deletions src/core/exposed/is-cloud-service-enabled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function isOnedriveEnabled() {
return Boolean(import.meta.env.VITE_ONEDRIVE_CLIENT_ID)
}

function isGoogleDriveEnabled() {
return (
Boolean(import.meta.env.VITE_GOOGLE_DRIVE_CLIENT_ID) &&
Boolean(import.meta.env.VITE_GOOGLE_DRIVE_CLIENT_SECRET) &&
Boolean(import.meta.env.VITE_GOOGLE_DRIVE_API_KEY)
)
}

type CloudService = 'onedrive' | 'google-drive'

export function isCloudServiceEnabled(cloudService: CloudService) {
if (cloudService === 'onedrive') {
return isOnedriveEnabled()
}
if (cloudService === 'google-drive') {
return isGoogleDriveEnabled()
}
return false
}
41 changes: 26 additions & 15 deletions src/views/components/setup-wizard/get-started.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useAtom } from 'jotai'
import { useEffect } from 'react'
import { isCloudServiceEnabled } from '../../../core'
import { SpatialNavigation } from '../../lib/spatial-navigation'
import { BaseButton } from '../primitives/base-button'
import { BaseDialogContent } from '../primitives/base-dialog-content'
Expand All @@ -8,6 +9,10 @@ import { GoogleDriveButton } from './google-drive-button'
import { LocalButton } from './local-button'
import { OnedriveButton } from './onedrive-button'

const isOnedriveEnabled = isCloudServiceEnabled('onedrive')
const isGoogleDriveEnabled = isCloudServiceEnabled('google-drive')
const isAnyCloudServiceEnabled = isOnedriveEnabled || isGoogleDriveEnabled

export function GetStarted() {
const [isInvalidDialogOpen, setIsInvalidDialogOpenAtom] = useAtom(isInvalidDialogOpenAtom)

Expand All @@ -19,24 +24,30 @@ export function GetStarted() {
<div className='container m-auto max-w-5xl px-10'>
<div className='get-started mt-4 w-full rounded-xl border-2 border-red-600 px-10 py-6'>
<div className='flex flex-col items-center gap-10'>
<div className='flex flex-col'>
<div className='flex items-center justify-center gap-2 text-center font-bold'>
<span className='icon-[mdi--cube-outline] h-6 w-6' />
Select a cloud directory
</div>
<div className='mt-2 flex items-start justify-center text-xs'>
<span className='icon-[mdi--thumb-up] mr-2 mt-1 h-3 w-3' />
<div>Sync your games and progress between multiple devices.</div>
</div>
<div className='mt-4 flex flex-col justify-center gap-4'>
<div className='text-center'>
<OnedriveButton />
{isAnyCloudServiceEnabled ? (
<div className='flex flex-col'>
<div className='flex items-center justify-center gap-2 text-center font-bold'>
<span className='icon-[mdi--cube-outline] h-6 w-6' />
Select a cloud directory
</div>
<div className='mt-2 flex items-start justify-center text-xs'>
<span className='icon-[mdi--thumb-up] mr-2 mt-1 h-3 w-3' />
<div>Sync your games and progress between multiple devices.</div>
</div>
<div className='text-center'>
<GoogleDriveButton />
<div className='mt-4 flex flex-col justify-center gap-4'>
{isOnedriveEnabled ? (
<div className='text-center'>
<OnedriveButton />
</div>
) : null}
{isGoogleDriveEnabled ? (
<div className='text-center'>
<GoogleDriveButton />
</div>
) : null}
</div>
</div>
</div>
) : null}

<div>
<div className='flex items-center justify-center gap-2 text-center font-bold'>
Expand Down

0 comments on commit 3f7e4e8

Please sign in to comment.