Move /platform/detection vars into /env (#9707)
* Add platform vars to env * Replace /platform/detection with /env
This commit is contained in:
+2
-2
@@ -1,7 +1,7 @@
|
||||
import React from 'react'
|
||||
import {AccessibilityInfo} from 'react-native'
|
||||
|
||||
import {isWeb} from '#/platform/detection'
|
||||
import {IS_WEB} from '#/env'
|
||||
import {PlatformInfo} from '../../modules/expo-bluesky-swiss-army'
|
||||
|
||||
const Context = React.createContext({
|
||||
@@ -58,7 +58,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
*
|
||||
* @see https://github.com/necolas/react-native-web/discussions/2072
|
||||
*/
|
||||
screenReaderEnabled: isWeb ? false : screenReaderEnabled,
|
||||
screenReaderEnabled: IS_WEB ? false : screenReaderEnabled,
|
||||
}
|
||||
}, [reduceMotionEnabled, screenReaderEnabled])
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import React from 'react'
|
||||
|
||||
import {isWeb} from '#/platform/detection'
|
||||
import {type DialogControlRefProps} from '#/components/Dialog'
|
||||
import {Provider as GlobalDialogsProvider} from '#/components/dialogs/Context'
|
||||
import {IS_WEB} from '#/env'
|
||||
import {BottomSheetNativeComponent} from '../../../modules/bottom-sheet'
|
||||
|
||||
interface IDialogContext {
|
||||
@@ -62,7 +62,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
const openDialogs = React.useRef<Set<string>>(new Set())
|
||||
|
||||
const closeAllDialogs = React.useCallback(() => {
|
||||
if (isWeb) {
|
||||
if (IS_WEB) {
|
||||
openDialogs.current.forEach(id => {
|
||||
const dialog = activeDialogs.current.get(id)
|
||||
if (dialog) dialog.current.close()
|
||||
|
||||
@@ -18,7 +18,7 @@ import {openCropper} from '#/lib/media/picker'
|
||||
import {type PickerImage} from '#/lib/media/picker.shared'
|
||||
import {getDataUriSize} from '#/lib/media/util'
|
||||
import {isCancelledError} from '#/lib/strings/errors'
|
||||
import {isNative} from '#/platform/detection'
|
||||
import {IS_NATIVE} from '#/env'
|
||||
|
||||
export type ImageTransformation = {
|
||||
crop?: ActionCrop['crop']
|
||||
@@ -55,7 +55,7 @@ export type ComposerImage =
|
||||
let _imageCacheDirectory: string
|
||||
|
||||
function getImageCacheDirectory(): string | null {
|
||||
if (isNative) {
|
||||
if (IS_NATIVE) {
|
||||
return (_imageCacheDirectory ??= joinPath(cacheDirectory!, 'bsky-composer'))
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ export async function pasteImage(
|
||||
}
|
||||
|
||||
export async function cropImage(img: ComposerImage): Promise<ComposerImage> {
|
||||
if (!isNative) {
|
||||
if (!IS_NATIVE) {
|
||||
return img
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ export async function compressImage(img: ComposerImage): Promise<PickerImage> {
|
||||
}
|
||||
|
||||
async function moveIfNecessary(from: string) {
|
||||
const cacheDir = isNative && getImageCacheDirectory()
|
||||
const cacheDir = IS_NATIVE && getImageCacheDirectory()
|
||||
|
||||
if (cacheDir && from.startsWith(cacheDir)) {
|
||||
const to = joinPath(cacheDir, nanoid(36))
|
||||
@@ -260,7 +260,7 @@ async function moveIfNecessary(from: string) {
|
||||
|
||||
/** Purge files that were created to accomodate image manipulation */
|
||||
export async function purgeTemporaryImageFiles() {
|
||||
const cacheDir = isNative && getImageCacheDirectory()
|
||||
const cacheDir = IS_NATIVE && getImageCacheDirectory()
|
||||
|
||||
if (cacheDir) {
|
||||
await deleteAsync(cacheDir, {idempotent: true})
|
||||
|
||||
@@ -16,7 +16,6 @@ import {
|
||||
isNetworkError,
|
||||
} from '#/lib/strings/errors'
|
||||
import {Logger} from '#/logger'
|
||||
import {isNative} from '#/platform/detection'
|
||||
import {
|
||||
ACTIVE_POLL_INTERVAL,
|
||||
BACKGROUND_POLL_INTERVAL,
|
||||
@@ -37,6 +36,7 @@ import {
|
||||
} from '#/state/messages/convo/types'
|
||||
import {type MessagesEventBus} from '#/state/messages/events/agent'
|
||||
import {type MessagesEventBusError} from '#/state/messages/events/types'
|
||||
import {IS_NATIVE} from '#/env'
|
||||
|
||||
const logger = Logger.create(Logger.Context.ConversationAgent)
|
||||
|
||||
@@ -639,7 +639,7 @@ export class Convo {
|
||||
{
|
||||
cursor: nextCursor,
|
||||
convoId: this.convoId,
|
||||
limit: isNative ? 30 : 60,
|
||||
limit: IS_NATIVE ? 30 : 60,
|
||||
},
|
||||
{headers: DM_SERVICE_HEADERS},
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from 'react'
|
||||
|
||||
import {isWeb} from '#/platform/detection'
|
||||
import * as persisted from '#/state/persisted'
|
||||
import {IS_WEB} from '#/env'
|
||||
|
||||
type StateContext = persisted.Schema['kawaii']
|
||||
|
||||
@@ -30,7 +30,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
React.useEffect(() => {
|
||||
// dumb and stupid but it's web only so just refresh the page if you want to change it
|
||||
|
||||
if (isWeb) {
|
||||
if (IS_WEB) {
|
||||
const kawaii = new URLSearchParams(window.location.search).get('kawaii')
|
||||
switch (kawaii) {
|
||||
case 'true':
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import {useCallback, useMemo, useState} from 'react'
|
||||
import {useQuery, useQueryClient} from '@tanstack/react-query'
|
||||
|
||||
import {isWeb} from '#/platform/detection'
|
||||
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
||||
import {useThreadPreferences} from '#/state/queries/preferences/useThreadPreferences'
|
||||
import {
|
||||
@@ -31,6 +30,7 @@ import * as views from '#/state/queries/usePostThread/views'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {useMergeThreadgateHiddenReplies} from '#/state/threadgate-hidden-replies'
|
||||
import {useBreakpoints} from '#/alf'
|
||||
import {IS_WEB} from '#/env'
|
||||
|
||||
export * from '#/state/queries/usePostThread/context'
|
||||
export {useUpdatePostThreadThreadgateQueryCache} from '#/state/queries/usePostThread/queryCache'
|
||||
@@ -53,7 +53,7 @@ export function usePostThread({anchor}: {anchor?: string}) {
|
||||
const below = useMemo(() => {
|
||||
return view === 'linear'
|
||||
? LINEAR_VIEW_BELOW
|
||||
: isWeb && gtPhone
|
||||
: IS_WEB && gtPhone
|
||||
? TREE_VIEW_BELOW_DESKTOP
|
||||
: TREE_VIEW_BELOW
|
||||
}, [view, gtPhone])
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import React from 'react'
|
||||
import {type AtpSessionEvent, type BskyAgent} from '@atproto/api'
|
||||
|
||||
import {isWeb} from '#/platform/detection'
|
||||
import * as persisted from '#/state/persisted'
|
||||
import {useCloseAllActiveElements} from '#/state/util'
|
||||
import {useGlobalDialogsControlContext} from '#/components/dialogs/Context'
|
||||
import {IS_WEB} from '#/env'
|
||||
import {emitSessionDropped} from '../events'
|
||||
import {
|
||||
agentToSessionAccount,
|
||||
@@ -340,7 +340,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
)
|
||||
|
||||
// @ts-expect-error window type is not declared, debug only
|
||||
if (__DEV__ && isWeb) window.agent = state.currentAgentState.agent
|
||||
if (__DEV__ && IS_WEB) window.agent = state.currentAgentState.agent
|
||||
|
||||
const agent = state.currentAgentState.agent as BskyAppAgent
|
||||
const currentAgentRef = React.useRef(agent)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import React from 'react'
|
||||
|
||||
import {isWeb} from '#/platform/detection'
|
||||
import {useSession} from '#/state/session'
|
||||
import {useActiveStarterPack} from '#/state/shell/starter-pack'
|
||||
import {IS_WEB} from '#/env'
|
||||
|
||||
type State = {
|
||||
showLoggedOut: boolean
|
||||
@@ -55,7 +55,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
const [state, setState] = React.useState<State>({
|
||||
showLoggedOut: shouldShowStarterPack,
|
||||
requestedAccountSwitchTo: shouldShowStarterPack
|
||||
? isWeb
|
||||
? IS_WEB
|
||||
? 'starterpack'
|
||||
: 'new'
|
||||
: undefined,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import {createContext, useCallback, useContext, useState} from 'react'
|
||||
|
||||
import {isWeb} from '#/platform/detection'
|
||||
import {type FeedDescriptor} from '#/state/queries/post-feed'
|
||||
import {useSession} from '#/state/session'
|
||||
import {IS_WEB} from '#/env'
|
||||
import {account} from '#/storage'
|
||||
|
||||
type StateContext = FeedDescriptor | null
|
||||
@@ -14,7 +14,7 @@ const setContext = createContext<SetContext>((_: string) => {})
|
||||
setContext.displayName = 'SelectedFeedSetContext'
|
||||
|
||||
function getInitialFeed(did?: string): FeedDescriptor | null {
|
||||
if (isWeb) {
|
||||
if (IS_WEB) {
|
||||
if (window.location.pathname === '/') {
|
||||
const params = new URLSearchParams(window.location.search)
|
||||
const feedFromUrl = params.get('feed')
|
||||
@@ -49,7 +49,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
const saveState = useCallback(
|
||||
(feed: FeedDescriptor) => {
|
||||
setState(feed)
|
||||
if (isWeb) {
|
||||
if (IS_WEB) {
|
||||
try {
|
||||
sessionStorage.setItem('lastSelectedHomeFeed', feed)
|
||||
} catch {}
|
||||
|
||||
Reference in New Issue
Block a user