feat: memo list 下拉刷新
This commit is contained in:
parent
b7962d6bf6
commit
35ccc824f6
@ -3,26 +3,33 @@ import UploaderProgress from "@/components/file-upload/upload-progress/uploader-
|
||||
import AskNavbar from "@/components/layout/ask";
|
||||
import { useUploadManager } from "@/hooks/useUploadManager";
|
||||
import { fetchApi } from "@/lib/server-api-util";
|
||||
import { useAppDispatch, useAppSelector } from "@/store";
|
||||
import { useAppSelector } from "@/store";
|
||||
import { Chat } from "@/types/ask";
|
||||
import { router } from "expo-router";
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { FlatList, Platform, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
|
||||
import { router, useFocusEffect } from "expo-router";
|
||||
import React from 'react';
|
||||
import { FlatList, Platform, RefreshControl, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
|
||||
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
||||
|
||||
const MemoList = () => {
|
||||
const insets = useSafeAreaInsets();
|
||||
const dispatch = useAppDispatch();
|
||||
const uploadSessionStartTime = useAppSelector((state) => state.appState.uploadSessionStartTime);
|
||||
|
||||
// 历史消息
|
||||
const [historyList, setHistoryList] = React.useState<Chat[]>([]);
|
||||
// 刷新状态
|
||||
const [refreshing, setRefreshing] = React.useState(false);
|
||||
|
||||
// 获取历史消息
|
||||
const getHistoryList = async () => {
|
||||
await fetchApi<Chat[]>(`/chats`).then((res) => {
|
||||
setHistoryList(res)
|
||||
})
|
||||
try {
|
||||
setRefreshing(true);
|
||||
const res = await fetchApi<Chat[]>(`/chats`);
|
||||
setHistoryList(res);
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch history:', error);
|
||||
} finally {
|
||||
setRefreshing(false);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取对话历史消息
|
||||
@ -41,9 +48,12 @@ const MemoList = () => {
|
||||
getChatHistory(item.session_id)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
getHistoryList()
|
||||
}, [])
|
||||
useFocusEffect(
|
||||
React.useCallback(() => {
|
||||
getHistoryList()
|
||||
}, [])
|
||||
);
|
||||
|
||||
|
||||
const { progressInfo, uploadSessionStartTime: uploadSessionStartTimeFromHook } = useUploadManager();
|
||||
|
||||
@ -87,6 +97,15 @@ const MemoList = () => {
|
||||
ListHeaderComponent={renderHeader}
|
||||
data={historyList}
|
||||
keyExtractor={(item) => item.session_id}
|
||||
// 下拉刷新
|
||||
refreshControl={
|
||||
<RefreshControl
|
||||
refreshing={refreshing}
|
||||
onRefresh={getHistoryList}
|
||||
colors={['#FFB645']} // Android
|
||||
tintColor="#FFB645" // iOS
|
||||
/>
|
||||
}
|
||||
ItemSeparatorComponent={() => (
|
||||
<View style={styles.separator} />
|
||||
)}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user