sorting for records in the ui

This commit is contained in:
2026-07-13 21:43:10 +05:30
parent c7cea78f74
commit 3cb086d67b
6 changed files with 134 additions and 15 deletions

View File

@@ -1,6 +1,13 @@
import { create } from 'zustand';
import { persist } from 'zustand/middleware';
// Feed/session sort. '' = backend default order (id DESC on the pending
// feed). One choice drives the whole chain: feed table, session pages,
// dashboard batch numbering and the "continue auditing" start page - they
// must all use the same order or batch N stops matching session page N.
export type FeedSortBy = '' | 'id' | 'date' | 'chainage' | 'latlong';
export type FeedSortDir = 'asc' | 'desc';
export interface FeedTab {
date: string;
isRectificationTab: boolean;
@@ -26,6 +33,8 @@ interface DashboardCache {
filterPlaza: string;
isRectificationEnabled?: boolean;
date?: string;
sortBy?: string;
sortDir?: string;
stats: {
globalTotal: number;
batchTotal: number;
@@ -59,6 +68,8 @@ interface FeedState {
searchAnomalyId: string;
isRectificationEnabled: boolean;
isFeedLoading: boolean;
sortBy: FeedSortBy;
sortDir: FeedSortDir;
// Actions
setTabs: (tabs: FeedTab[]) => void;
@@ -84,6 +95,8 @@ interface FeedState {
setSearchAnomalyId: (id: string) => void;
setIsRectificationEnabled: (val: boolean) => void;
setIsFeedLoading: (val: boolean) => void;
setSortBy: (val: FeedSortBy) => void;
setSortDir: (val: FeedSortDir) => void;
resetStore: () => void;
}
@@ -123,6 +136,8 @@ const initialFeedState = {
searchAnomalyId: '',
isRectificationEnabled: false,
isFeedLoading: false,
sortBy: '' as FeedSortBy,
sortDir: 'asc' as FeedSortDir,
};
export const useFeedStore = create<FeedState>()(
@@ -152,6 +167,8 @@ export const useFeedStore = create<FeedState>()(
setSearchAnomalyId: (searchAnomalyId) => set({ searchAnomalyId }),
setIsRectificationEnabled: (isRectificationEnabled) => set({ isRectificationEnabled }),
setIsFeedLoading: (isFeedLoading) => set({ isFeedLoading }),
setSortBy: (sortBy) => set({ sortBy }),
setSortDir: (sortDir) => set({ sortDir }),
addTab: (tab) => set((state) => ({ tabs: [...state.tabs, tab], selectedTabIndex: state.tabs.length })),
closeTab: (index) => set((state) => {
const newTabs = [...state.tabs];
@@ -180,6 +197,8 @@ export const useFeedStore = create<FeedState>()(
auditStatus: state.auditStatus,
searchAnomalyId: state.searchAnomalyId,
isRectificationEnabled: state.isRectificationEnabled,
sortBy: state.sortBy,
sortDir: state.sortDir,
}),
}
)