Skip to content

Commit

Permalink
feat: ui & logo optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
liaoliao666 committed May 23, 2023
1 parent 55a7b37 commit 6718c8c
Show file tree
Hide file tree
Showing 20 changed files with 106 additions and 90 deletions.
4 changes: 2 additions & 2 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import './utils/dayjsPlugins'
import {
asyncStoragePersister,
queryClient,
resetInfiniteQueriesWithHugeData,
removeUnnecessaryPages,
} from './utils/query'
import tw from './utils/tw'

Expand Down Expand Up @@ -62,7 +62,7 @@ function App() {
persister: asyncStoragePersister,
}}
onSuccess={() => {
resetInfiniteQueriesWithHugeData()
removeUnnecessaryPages()
isReadyNavigation.then(SplashScreen.hideAsync)
}}
>
Expand Down
Binary file modified assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion components/StyledImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ function CustomImage({ style, source, onLoad, onError, ...props }: ImageProps) {
const hasPassedSize = isStyle(style) && hasSize(style)

const isMiniImage =
isStyle(size) && hasSize(size) ? size.width < 50 && size.height < 50 : false
isStyle(size) && hasSize(size)
? size.width < 100 && size.height < 100
: false

return (
<FastImage
Expand Down
4 changes: 2 additions & 2 deletions navigation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,13 @@ const Drawer = createDrawerNavigator()
function DrawerNavigator() {
return (
<Drawer.Navigator
initialRouteName="HomeScreen"
initialRouteName="Home"
drawerContent={() => <Profile />}
screenOptions={{
headerShown: false,
}}
>
<Drawer.Screen name="HomeScreen" component={HomeScreen} />
<Drawer.Screen name="Home" component={HomeScreen} />
</Drawer.Navigator>
)
}
6 changes: 2 additions & 4 deletions navigation/navigationRef.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
createNavigationContainerRef,
} from '@react-navigation/native'
import { NativeStackNavigationProp } from '@react-navigation/native-stack'
import { isFunction } from 'lodash-es'

import { RootStackParamList } from '../types'

Expand Down Expand Up @@ -33,8 +32,7 @@ export function getNavigation() {
return navigation
}

export function getCurrentRouteName(): string {
export function getCurrentRouteName(): keyof RootStackParamList {
// @ts-ignore
const getCurrentRoute: any = getNavigation()?.getCurrentRoute
return isFunction(getCurrentRoute) ? getCurrentRoute()?.name : undefined
return getNavigation()?.getCurrentRoute?.()?.name
}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@react-navigation/native": "^6.0.13",
"@react-navigation/native-stack": "^6.9.1",
"@tanstack/query-async-storage-persister": "^5.0.0-alpha.19",
"@tanstack/react-query": "^5.0.0-alpha.19",
"@tanstack/react-query": "^5.0.0-alpha.35",
"@tanstack/react-query-persist-client": "^5.0.0-alpha.19",
"@types/spark-md5": "^3.0.2",
"axios": "^0.27.2",
Expand All @@ -30,15 +30,15 @@
"expo-blur": "~12.2.2",
"expo-clipboard": "~4.1.2",
"expo-constants": "~14.2.1",
"expo-dev-client": "~2.1.6",
"expo-dev-client": "~2.2.1",
"expo-device": "~5.2.1",
"expo-file-system": "~15.2.2",
"expo-font": "~11.1.1",
"expo-image-picker": "~14.1.1",
"expo-linking": "~4.0.1",
"expo-media-library": "~15.2.3",
"expo-sharing": "~11.2.2",
"expo-splash-screen": "~0.18.1",
"expo-splash-screen": "~0.18.2",
"expo-status-bar": "~1.4.4",
"expo-updates": "~0.16.4",
"highlight.js": "^11.6.0",
Expand All @@ -50,7 +50,7 @@
"react-dom": "18.2.0",
"react-error-boundary": "^3.1.4",
"react-hook-form": "^7.39.4",
"react-native": "0.71.7",
"react-native": "0.71.8",
"react-native-bouncy-checkbox": "^3.0.6",
"react-native-drag-sort": "^2.4.4",
"react-native-fast-image": "^8.6.3",
Expand All @@ -66,7 +66,7 @@
"react-native-toast-message": "^2.1.6",
"react-native-webview": "11.26.0",
"react-native-youtube-iframe": "^2.2.2",
"react-query-kit": "^1.4.4",
"react-query-kit": "^1.4.5",
"rn-placeholder": "^3.0.3",
"spark-md5": "^3.0.2",
"twrnc": "^3.6.0",
Expand Down
13 changes: 7 additions & 6 deletions screens/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ import { fontScaleAtom, getFontSize } from '@/jotai/fontSacleAtom'
import { homeTabIndexAtom, homeTabsAtom } from '@/jotai/homeTabsAtom'
import { profileAtom } from '@/jotai/profileAtom'
import { colorSchemeAtom } from '@/jotai/themeAtom'
import { getCurrentRouteName } from '@/navigation/navigationRef'
import { useRecentTopics, useTabTopics } from '@/servicies/topic'
import { Topic } from '@/servicies/types'
import { RootStackParamList } from '@/types'
import { isSignined } from '@/utils/authentication'
import { queryClient, resetInfiniteQueriesWithHugeData } from '@/utils/query'
import { queryClient, removeUnnecessaryPages } from '@/utils/query'
import tw from '@/utils/tw'
import { useRefreshByUser } from '@/utils/useRefreshByUser'

Expand Down Expand Up @@ -124,7 +125,7 @@ function HomeScreen() {
errorResetMap[tab]?.()
} else if (query?.getObserversCount() && query?.isStale()) {
if (tab === 'recent') {
resetInfiniteQueriesWithHugeData(useRecentTopics.getKey())
removeUnnecessaryPages(useRecentTopics.getKey())
}
queryClient.refetchQueries({ queryKey: activeKey })
}
Expand Down Expand Up @@ -203,13 +204,13 @@ function HomeScreen() {
onPress={() => {
navigation.navigate('SortTabs')
}}
style={tw`h-full flex-row items-center justify-center z-50 bg-body-1`}
style={tw`h-full flex-row items-center justify-center z-50`}
>
<Feather
name="menu"
size={17}
color={tw.color(`text-tint-secondary`)}
style={tw`-mt-1 pr-4 pl-1`}
style={tw`pr-4 pl-2`}
/>
</TouchableOpacity>
</View>
Expand Down Expand Up @@ -238,7 +239,7 @@ function RecentTopics({
isFetching,
} = useRecentTopics({
suspense: true,
refetchOnWindowFocus: isActive,
refetchOnWindowFocus: () => isActive && getCurrentRouteName() === 'Home',
})

const { isRefetchingByUser, refetchByUser } = useRefreshByUser(refetch)
Expand Down Expand Up @@ -303,7 +304,7 @@ function TabTopics({
const { data, refetch, isFetching } = useTabTopics({
variables: { tab },
suspense: true,
refetchOnWindowFocus: isActive,
refetchOnWindowFocus: () => isActive && getCurrentRouteName() === 'Home',
})

const { isRefetchingByUser, refetchByUser } = useRefreshByUser(refetch)
Expand Down
8 changes: 4 additions & 4 deletions screens/MemberDetailScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ import {
import { Member, Reply, Topic } from '@/servicies/types'
import { RootStackParamList } from '@/types'
import { isMe, isSignined } from '@/utils/authentication'
import { queryClient, resetInfiniteQueriesWithHugeData } from '@/utils/query'
import { queryClient, removeUnnecessaryPages } from '@/utils/query'
import tw from '@/utils/tw'
import { useRefreshByUser } from '@/utils/useRefreshByUser'

const TAB_BAR_HEIGHT = 40
const TAB_BAR_HEIGHT = 53
const TOP_BAR_BG_CLS = `bg-[rgb(51,51,68)]`
const TAB_VIEW_MARGIN_TOP = -2

Expand All @@ -88,10 +88,10 @@ function MemberDetailScreen() {
const { params } = useRoute<RouteProp<RootStackParamList, 'MemberDetail'>>()

useMemo(() => {
resetInfiniteQueriesWithHugeData(
removeUnnecessaryPages(
useMemberTopics.getKey({ username: params.username })
)
resetInfiniteQueriesWithHugeData(
removeUnnecessaryPages(
useMemberReplies.getKey({ username: params.username })
)
queryClient.prefetchInfiniteQuery({
Expand Down
15 changes: 3 additions & 12 deletions screens/MyFollowingScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from 'react-native'
import { SafeAreaView } from 'react-native-safe-area-context'
import { TabBar, TabView } from 'react-native-tab-view'
import { inferData } from 'react-query-kit'

import Empty from '@/components/Empty'
import NavBar, { useNavBarHeight } from '@/components/NavBar'
Expand All @@ -31,7 +30,7 @@ import { getFontSize } from '@/jotai/fontSacleAtom'
import { colorSchemeAtom } from '@/jotai/themeAtom'
import { useMemberTopics, useMyFollowing } from '@/servicies/member'
import { Topic } from '@/servicies/types'
import { queryClient, resetInfiniteQueriesWithHugeData } from '@/utils/query'
import { removeUnnecessaryPages } from '@/utils/query'
import tw from '@/utils/tw'
import { useRefreshByUser } from '@/utils/useRefreshByUser'

Expand Down Expand Up @@ -83,16 +82,8 @@ const MemoMemberTopics = withQuerySuspense(memo(MemberTopics), {

function MyFollowingScreen() {
useMemo(() => {
resetInfiniteQueriesWithHugeData(useMyFollowing.getKey())
queryClient
.getQueryData<inferData<typeof useMyFollowing>>(useMyFollowing.getKey())
?.pages?.[0]?.following.forEach(member => {
resetInfiniteQueriesWithHugeData(
useMemberTopics.getKey({
username: member.username,
})
)
})
removeUnnecessaryPages(useMyFollowing.getKey())
removeUnnecessaryPages(useMemberTopics.getKey())
}, [])

const { data } = useMyFollowing({
Expand Down
4 changes: 2 additions & 2 deletions screens/MyTopicsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import TopicItem from '@/components/topic/TopicItem'
import { colorSchemeAtom } from '@/jotai/themeAtom'
import { useMyTopics } from '@/servicies/topic'
import { Topic } from '@/servicies/types'
import { resetInfiniteQueriesWithHugeData } from '@/utils/query'
import { removeUnnecessaryPages } from '@/utils/query'
import tw from '@/utils/tw'
import { useRefreshByUser } from '@/utils/useRefreshByUser'

Expand All @@ -40,7 +40,7 @@ export default withQuerySuspense(MyTopicsScreen, {

function MyTopicsScreen() {
useMemo(() => {
resetInfiniteQueriesWithHugeData(useMyTopics.getKey())
removeUnnecessaryPages(useMyTopics.getKey())
}, [])

const {
Expand Down
6 changes: 2 additions & 4 deletions screens/NodeTopicsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { useLikeNode, useNodeTopics, useNodes } from '@/servicies/node'
import { Topic } from '@/servicies/types'
import { RootStackParamList } from '@/types'
import { isSignined } from '@/utils/authentication'
import { queryClient, resetInfiniteQueriesWithHugeData } from '@/utils/query'
import { queryClient, removeUnnecessaryPages } from '@/utils/query'
import tw from '@/utils/tw'
import { useRefreshByUser } from '@/utils/useRefreshByUser'

Expand Down Expand Up @@ -67,9 +67,7 @@ function NodeTopicsScreen() {
const { params } = useRoute<RouteProp<RootStackParamList, 'NodeTopics'>>()

useMemo(() => {
resetInfiniteQueriesWithHugeData(
useNodeTopics.getKey({ name: params.name })
)
removeUnnecessaryPages(useNodeTopics.getKey({ name: params.name }))
}, [params.name])

const { data, refetch, hasNextPage, fetchNextPage, isFetchingNextPage } =
Expand Down
4 changes: 2 additions & 2 deletions screens/NotificationsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { Notice } from '@/servicies/types'
import { RootStackParamList } from '@/types'
import { isSignined } from '@/utils/authentication'
import { confirm } from '@/utils/confirm'
import { queryClient, resetInfiniteQueriesWithHugeData } from '@/utils/query'
import { queryClient, removeUnnecessaryPages } from '@/utils/query'
import tw from '@/utils/tw'
import { useRefreshByUser } from '@/utils/useRefreshByUser'

Expand All @@ -52,7 +52,7 @@ export default withQuerySuspense(NotificationsScreen, {

function NotificationsScreen() {
useMemo(() => {
resetInfiniteQueriesWithHugeData(useNotifications.getKey())
removeUnnecessaryPages(useNotifications.getKey())
}, [])

const {
Expand Down
1 change: 0 additions & 1 deletion screens/RelatedRepliesScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ export default function RelatedRepliesScreen() {
: tw`text-tint-secondary font-medium`
)}
numberOfLines={1}
ellipsizeMode="clip"
>
{route.title}
</Text>
Expand Down
4 changes: 2 additions & 2 deletions screens/SearchScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { useSov2ex } from '@/servicies/sov2ex'
import { useTopicDetail } from '@/servicies/topic'
import { Member, Node, Sov2exResult } from '@/servicies/types'
import { RootStackParamList } from '@/types'
import { resetInfiniteQueriesWithHugeData } from '@/utils/query'
import { removeUnnecessaryPages } from '@/utils/query'
import tw from '@/utils/tw'
import { useRefreshByUser } from '@/utils/useRefreshByUser'

Expand Down Expand Up @@ -202,7 +202,7 @@ function SoV2exList({
)

useMemo(() => {
resetInfiniteQueriesWithHugeData(useSov2ex.getKey(variables))
removeUnnecessaryPages(useSov2ex.getKey(variables))
}, [variables])

const { data, refetch, hasNextPage, fetchNextPage, isFetchingNextPage } =
Expand Down
4 changes: 2 additions & 2 deletions screens/TopicDetailScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { useTopicDetail } from '@/servicies/topic'
import { Reply } from '@/servicies/types'
import { RootStackParamList } from '@/types'
import { isMe } from '@/utils/authentication'
import { resetInfiniteQueriesWithHugeData } from '@/utils/query'
import { removeUnnecessaryPages } from '@/utils/query'
import tw from '@/utils/tw'
import { useRefreshByUser } from '@/utils/useRefreshByUser'

Expand Down Expand Up @@ -61,7 +61,7 @@ function TopicDetailScreen() {
const { params } = useRoute<RouteProp<RootStackParamList, 'TopicDetail'>>()

useMemo(() => {
resetInfiniteQueriesWithHugeData(useTopicDetail.getKey({ id: params.id }))
removeUnnecessaryPages(useTopicDetail.getKey({ id: params.id }))
}, [params.id])

const {
Expand Down
2 changes: 1 addition & 1 deletion store.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"info": {
"zh-Hans": {
"title": "v2ex-native"
"title": "v2fun"
}
},
"advisory": {
Expand Down
1 change: 1 addition & 0 deletions types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ declare module 'axios' {

export type RootStackParamList = {
Root: undefined
Home: undefined
SortTabs: undefined
NotFound: undefined
MyNodes: undefined
Expand Down
2 changes: 1 addition & 1 deletion utils/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ AppState.addEventListener('change', status => {
}
})

export function resetInfiniteQueriesWithHugeData(queryKey?: unknown[]) {
export function removeUnnecessaryPages(queryKey?: unknown[]) {
queryClient
.getQueryCache()
.findAll({ queryKey })
Expand Down
7 changes: 6 additions & 1 deletion utils/request/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ request.interceptors.response.use(
},
error => {
handle503Error(error)
if (error instanceof Error && error.message.includes(`403`)) {
const err = new Error('请检查你的代理设置')
err.name = '请求失败'
return Promise.reject(err)
}
return Promise.reject(error)
}
)
Expand Down Expand Up @@ -72,7 +77,7 @@ function updateStoreWithData(data: any) {

store.set(profileAtom, prev => {
if (
getCurrentRouteName() !== 'HomeScreen' &&
getCurrentRouteName() !== 'Home' &&
store.get(enabledMsgPushAtom) &&
newProfile.my_notification !== prev?.my_notification &&
isInteger(newProfile.my_notification) &&
Expand Down
Loading

0 comments on commit 6718c8c

Please sign in to comment.