Skip to content

Commit

Permalink
fix: error toast but succeed reply
Browse files Browse the repository at this point in the history
  • Loading branch information
liaoliao666 committed Sep 17, 2023
1 parent a39caae commit 8e516a3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
7 changes: 2 additions & 5 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as SplashScreen from 'expo-splash-screen'
import { StatusBar } from 'expo-status-bar'
import { Provider, useAtom, useAtomValue } from 'jotai'
import { waitForAll } from 'jotai/utils'
import { noop } from 'lodash-es'
import { ReactElement, ReactNode, Suspense, useMemo } from 'react'
import { LogBox } from 'react-native'
import 'react-native-gesture-handler'
Expand Down Expand Up @@ -96,13 +95,11 @@ function AppInitializer({ children }: { children: ReactNode }) {

useMemo(() => {
tw.setColorScheme(colorScheme)

// ensure nodes data
queryClient.ensureQueryData(useNodes.getFetchOptions()).catch(noop)

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

useNodes()

useDeviceContext(tw, { withDeviceColorScheme: false })

useCheckin({
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.4.6",
"version": "1.4.7",
"scheme": "v2fun",
"jsEngine": "jsc",
"orientation": "portrait",
Expand All @@ -21,7 +21,7 @@
"ios": {
"supportsTablet": true,
"bundleIdentifier": "com.liaoliao666.v2ex",
"buildNumber": "1.4.6.2"
"buildNumber": "1.4.7.1"
},
"android": {
"adaptiveIcon": {
Expand Down
11 changes: 8 additions & 3 deletions components/topic/ReplyBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,14 @@ const ReplyBox = ({
content: getContent().trim(),
})

blur()
setContent('')
onSuccess()
try {
onSuccess()
setContent('')
blur()
} catch (error) {
// empty
}

Toast.show({
type: 'success',
text1: '发送成功',
Expand Down
4 changes: 2 additions & 2 deletions servicies/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function parseNodeByATag(
export function parseTopicByATag(
$topic: Cheerio<Element>
): Pick<Topic, 'id' | 'title' | 'reply_count'> {
const [id, replies] = $topic.attr('href')!.match(/\d+/g)!.map(Number)
const [id, replies] = $topic.attr('href')?.match(/\d+/g)?.map(Number) || []

return {
id,
Expand Down Expand Up @@ -393,7 +393,7 @@ export function parseRecentTopics($: CheerioAPI) {
avatar: $avatar.attr('src')!,
}
}),
id: $topic.attr('href')!.match(/\d+/g)!.map(Number)[0],
id: $topic.attr('href')?.match(/\d+/g)?.map(Number)[0],
title: $topic.text(),
} as RecentTopic
})
Expand Down
4 changes: 2 additions & 2 deletions servicies/node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { load } from 'cheerio'
import { createSuspenseQuery } from 'react-query-kit'
import { createQuery, createSuspenseQuery } from 'react-query-kit'
import { createMutation, createSuspenseInfiniteQuery } from 'react-query-kit'

import { invoke } from '@/utils/invoke'
Expand All @@ -9,7 +9,7 @@ import { getURLSearchParams } from '@/utils/url'
import { getNextPageParam, parseLastPage, parseTopicItems } from './helper'
import { Node, PageData, Topic } from './types'

export const useNodes = createSuspenseQuery<Node[], void>({
export const useNodes = createQuery<Node[], void>({
primaryKey: 'useNodes',
queryFn: ({ signal }) =>
request.get(`/api/nodes/all.json`, { signal }).then(res => res.data),
Expand Down

0 comments on commit 8e516a3

Please sign in to comment.