Cập nhật API thêm trip (validate)
This commit is contained in:
@@ -37,6 +37,7 @@ export default function diary() {
|
||||
const [isLoadingMore, setIsLoadingMore] = useState(false);
|
||||
const [hasMore, setHasMore] = useState(true);
|
||||
const isInitialLoad = useRef(true);
|
||||
const flatListRef = useRef<FlatList>(null);
|
||||
|
||||
// Body call API things (đang fix cứng)
|
||||
const payloadThings: Model.SearchThingBody = {
|
||||
@@ -198,6 +199,25 @@ export default function diary() {
|
||||
// TODO: Show confirmation dialog and delete trip
|
||||
};
|
||||
|
||||
// Handle sau khi thêm chuyến đi thành công
|
||||
const handleTripAddSuccess = useCallback(() => {
|
||||
// Reset về trang đầu và gọi lại API
|
||||
isInitialLoad.current = true;
|
||||
setAllTrips([]);
|
||||
setHasMore(true);
|
||||
const resetPayload: Model.TripListBody = {
|
||||
...payloadTrips,
|
||||
offset: 0,
|
||||
};
|
||||
setPayloadTrips(resetPayload);
|
||||
getTripsList(resetPayload);
|
||||
|
||||
// Scroll FlatList lên đầu
|
||||
setTimeout(() => {
|
||||
flatListRef.current?.scrollToOffset({ offset: 0, animated: true });
|
||||
}, 100);
|
||||
}, [payloadTrips, getTripsList]);
|
||||
|
||||
// Dynamic styles based on theme
|
||||
const themedStyles = {
|
||||
safeArea: {
|
||||
@@ -304,6 +324,7 @@ export default function diary() {
|
||||
|
||||
{/* Trip List with FlatList */}
|
||||
<FlatList
|
||||
ref={flatListRef}
|
||||
data={allTrips}
|
||||
renderItem={renderTripItem}
|
||||
keyExtractor={keyExtractor}
|
||||
@@ -331,6 +352,7 @@ export default function diary() {
|
||||
<AddTripModal
|
||||
visible={showAddTripModal}
|
||||
onClose={() => setShowAddTripModal(false)}
|
||||
onSuccess={handleTripAddSuccess}
|
||||
/>
|
||||
</SafeAreaView>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user