Skip to content

Commit

Permalink
feat: adjust login logic
Browse files Browse the repository at this point in the history
  • Loading branch information
liaoliao666 committed Jan 29, 2023
1 parent 74f2a89 commit f95c7ee
Show file tree
Hide file tree
Showing 19 changed files with 322 additions and 138 deletions.
49 changes: 16 additions & 33 deletions App.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { ActionSheetProvider } from '@expo/react-native-action-sheet'
import { focusManager } from '@tanstack/react-query'
import { PersistQueryClientProvider } from '@tanstack/react-query-persist-client'
import { StatusBar } from 'expo-status-bar'
import { Provider, useAtom, useAtomValue } from 'jotai'
import { waitForAll } from 'jotai/utils'
import { Fragment, ReactNode, Suspense, useMemo } from 'react'
import { AppStateStatus, LogBox, Platform } from 'react-native'
import { LogBox } from 'react-native'
import 'react-native-gesture-handler'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import Toast from 'react-native-toast-message'
Expand All @@ -27,47 +26,43 @@ import Navigation from './navigation'
import { useCheckin } from './servicies/member'
import { useNodes } from './servicies/node'
import './utils/dayjsPlugins'
import { enabledNetworkInspect } from './utils/enabledNetworkInspect'
// import { enabledNetworkInspect } from './utils/enabledNetworkInspect'
import { asyncStoragePersister, queryClient } from './utils/query'
import tw from './utils/tw'
import { useAppState } from './utils/useAppState'

LogBox.ignoreLogs([
'Non-serializable values were found in the navigation state',
'Sending',
])

enabledNetworkInspect()
// enabledNetworkInspect()

function onAppStateChange(status: AppStateStatus) {
// React Query already supports in web browser refetch on window focus by default
if (Platform.OS !== 'web') {
focusManager.setFocused(status === 'active')
}
}

export default function AppWithProvider() {
export default function App() {
return (
<ActionSheetProvider>
<Provider unstable_createStore={() => store}>
<PersistQueryClientProvider
client={queryClient}
persistOptions={{ persister: asyncStoragePersister }}
>
<Suspense>
<AppWithJotai>
<App />
</AppWithJotai>
</Suspense>

<StyledToast />
<SafeAreaProvider>
<Suspense>
<AppInitializer>
<Navigation />
<StatusBar />
<GlobalImageViewer />
</AppInitializer>
</Suspense>

<StyledToast />
</SafeAreaProvider>
</PersistQueryClientProvider>
</Provider>
</ActionSheetProvider>
)
}

function AppWithJotai({ children }: { children: ReactNode }) {
function AppInitializer({ children }: { children: ReactNode }) {
const [colorScheme, profile, enabledAutoCheckin, enabledPerformance] =
useAtomValue(
waitForAll([
Expand Down Expand Up @@ -109,18 +104,6 @@ function AppWithJotai({ children }: { children: ReactNode }) {
)
}

function App() {
useAppState(onAppStateChange)

return (
<SafeAreaProvider>
<Navigation />
<StatusBar />
<GlobalImageViewer />
</SafeAreaProvider>
)
}

function GlobalImageViewer() {
const [imageViewer, setImageViewer] = useAtom(imageViewerAtom)
return (
Expand Down
4 changes: 2 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"expo": {
"name": "V2Fun",
"slug": "v2ex",
"version": "1.1.9",
"version": "1.2.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "automatic",
Expand All @@ -19,7 +19,7 @@
"ios": {
"supportsTablet": false,
"bundleIdentifier": "com.liaoliao666.v2ex",
"buildNumber": "1.1.9.9"
"buildNumber": "1.2.0.1"
},
"android": {
"adaptiveIcon": {
Expand Down
7 changes: 3 additions & 4 deletions components/Html/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function Html({
tagsStyles={{
h1: tw`text-body-3 pb-1.5 border-b border-solid border-tint-border`,
h2: tw`text-body-4 pb-1.5 border-b border-solid border-tint-border`,
h3: tw`text-body-4 `,
h3: tw`text-body-4`,
h4: tw`text-body-4`,
h5: tw`text-body-5`,
h6: tw`text-body-6`,
Expand All @@ -153,9 +153,8 @@ function Html({
}

const [, routeName, arg] =
resolvedURI
.slice(baseURL.length)
.match(/\/(\w+)\/([\w|\d|-]+)/) || []
resolvedURI.slice(baseURL.length).match(/\/(\w+)\/(\w+)/) ||
[]

switch (routeName) {
case 't':
Expand Down
9 changes: 7 additions & 2 deletions components/NavBar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useNavigation } from '@react-navigation/native'
import { StatusBarStyle } from 'expo-status-bar'
import { ReactNode, isValidElement } from 'react'
import { Platform, Text, View, ViewStyle } from 'react-native'
import { Platform, PressableProps, Text, View, ViewStyle } from 'react-native'
import { useSafeAreaInsets } from 'react-native-safe-area-context'

import tw from '@/utils/tw'
Expand Down Expand Up @@ -73,7 +73,12 @@ export default function NavBar({
)
}

export function BackButton({ tintColor }: { tintColor?: string }) {
export function BackButton({
tintColor,
}: {
tintColor?: string
onPress?: PressableProps['onPress']
}) {
const { goBack } = useNavigation()

const color = tintColor || (tw`text-tint-primary`.color as string)
Expand Down
4 changes: 3 additions & 1 deletion components/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import StyledImage from '@/components/StyledImage'
import { profileAtom } from '@/jotai/profileAtom'
import { colorSchemeAtom, themeAtom } from '@/jotai/themeAtom'
import { RootStackParamList } from '@/types'
import { clearCookie } from '@/utils/cookie'
import tw from '@/utils/tw'

import Badge from './Badge'
Expand Down Expand Up @@ -164,7 +165,8 @@ function Profile() {
) : (
<TouchableOpacity
style={tw`px-4 py-8 flex-row items-center`}
onPress={() => {
onPress={async () => {
await clearCookie()
navigation.navigate('Login')
}}
>
Expand Down
Loading

0 comments on commit f95c7ee

Please sign in to comment.