Cập nhật thứ tự cảnh báo trong tab cảnh báo, sửa lại reload danh sách chuyến đi ( vuốt lên )
This commit is contained in:
@@ -41,6 +41,7 @@ export default function diary() {
|
||||
const [allTrips, setAllTrips] = useState<any[]>([]);
|
||||
const [isLoadingMore, setIsLoadingMore] = useState(false);
|
||||
const [hasMore, setHasMore] = useState(true);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
const isInitialLoad = useRef(true);
|
||||
const flatListRef = useRef<FlatList>(null);
|
||||
|
||||
@@ -330,8 +331,9 @@ export default function diary() {
|
||||
}, 100);
|
||||
}, [payloadTrips, getTripsList]);
|
||||
|
||||
// Handle reload - gọi lại API
|
||||
const handleReload = useCallback(() => {
|
||||
// Handle refresh - pull-to-refresh
|
||||
const handleRefresh = useCallback(() => {
|
||||
setRefreshing(true);
|
||||
isInitialLoad.current = true;
|
||||
setAllTrips([]);
|
||||
setHasMore(true);
|
||||
@@ -340,12 +342,9 @@ export default function diary() {
|
||||
offset: 0,
|
||||
};
|
||||
setPayloadTrips(resetPayload);
|
||||
getTripsList(resetPayload);
|
||||
|
||||
// Scroll FlatList lên đầu
|
||||
setTimeout(() => {
|
||||
flatListRef.current?.scrollToOffset({ offset: 0, animated: true });
|
||||
}, 100);
|
||||
getTripsList(resetPayload).finally(() => {
|
||||
setRefreshing(false);
|
||||
});
|
||||
}, [payloadTrips, getTripsList]);
|
||||
|
||||
// Dynamic styles based on theme
|
||||
@@ -436,21 +435,6 @@ export default function diary() {
|
||||
<Text style={[styles.titleText, themedStyles.titleText]}>
|
||||
{t("diary.title")}
|
||||
</Text>
|
||||
<TouchableOpacity
|
||||
style={[
|
||||
styles.reloadButton,
|
||||
{ backgroundColor: colors.backgroundSecondary },
|
||||
]}
|
||||
onPress={handleReload}
|
||||
activeOpacity={0.7}
|
||||
disabled={loading}
|
||||
>
|
||||
{loading && allTrips.length === 0 ? (
|
||||
<ActivityIndicator size="small" color={colors.primary} />
|
||||
) : (
|
||||
<Ionicons name="reload" size={20} color={colors.primary} />
|
||||
)}
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
|
||||
{/* Filter & Add Button Row */}
|
||||
@@ -489,6 +473,8 @@ export default function diary() {
|
||||
showsVerticalScrollIndicator={false}
|
||||
onEndReached={handleLoadMore}
|
||||
onEndReachedThreshold={0.5}
|
||||
refreshing={refreshing}
|
||||
onRefresh={handleRefresh}
|
||||
ListFooterComponent={renderFooter}
|
||||
ListEmptyComponent={renderEmpty}
|
||||
removeClippedSubviews={true}
|
||||
@@ -544,13 +530,6 @@ const styles = StyleSheet.create({
|
||||
alignItems: "center",
|
||||
marginBottom: 10,
|
||||
},
|
||||
reloadButton: {
|
||||
width: 36,
|
||||
height: 36,
|
||||
borderRadius: 18,
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
},
|
||||
actionRow: {
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-between",
|
||||
|
||||
@@ -85,11 +85,11 @@ const WarningScreen = () => {
|
||||
const slice = resp.data?.alarms ?? [];
|
||||
|
||||
// Sort alarms by level descending (higher level first: SOS > Danger > Warning > Info)
|
||||
const sortedSlice = [...slice].sort(
|
||||
(a, b) => (b.level ?? 0) - (a.level ?? 0)
|
||||
);
|
||||
|
||||
setAlarms((prev) => (append ? [...prev, ...sortedSlice] : sortedSlice));
|
||||
// When appending, we need to sort the entire combined list, not just the new slice
|
||||
setAlarms((prev) => {
|
||||
const combined = append ? [...prev, ...slice] : slice;
|
||||
return combined.sort((a, b) => (b.level ?? 0) - (a.level ?? 0));
|
||||
});
|
||||
setOffset(nextOffset);
|
||||
setHasMore(nextOffset + PAGE_SIZE < resp.data?.total!);
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user