@@ -24,7 +24,10 @@ const FOLDERS = "folders";
2424export const getDepartments = async ( ) => {
2525 const q = query ( collection ( db , DEPARTMENTS ) , orderBy ( "name" ) ) ;
2626 const snapshot = await getDocs ( q ) ;
27- return snapshot . docs . map ( d => ( { id : d . id , ...d . data ( ) } ) ) ;
27+ // Client-side sort with numeric option
28+ return snapshot . docs
29+ . map ( d => ( { id : d . id , ...d . data ( ) } ) )
30+ . sort ( ( a : any , b : any ) => ( a . name || "" ) . localeCompare ( b . name || "" , undefined , { numeric : true } ) ) ;
2831} ;
2932
3033export const createDepartment = ( name : string ) =>
@@ -42,7 +45,7 @@ export const getBatches = async (departmentId: string) => {
4245 // Client-side sort to avoid composite index requirement
4346 return snapshot . docs
4447 . map ( d => ( { id : d . id , ...d . data ( ) } ) )
45- . sort ( ( a : any , b : any ) => ( a . name || "" ) . localeCompare ( b . name || "" ) ) ;
48+ . sort ( ( a : any , b : any ) => ( a . name || "" ) . localeCompare ( b . name || "" , undefined , { numeric : true } ) ) ;
4649} ;
4750
4851export const createBatch = ( departmentId : string , name : string ) =>
@@ -58,7 +61,7 @@ export const getSemesters = async (batchId: string) => {
5861 const q = query ( collection ( db , SEMESTERS ) , where ( "batchId" , "==" , batchId ) ) ;
5962 const snapshot = await getDocs ( q ) ;
6063 // Sort manually or add composite index
61- return snapshot . docs . map ( d => ( { id : d . id , ...d . data ( ) } ) ) . sort ( ( a : any , b : any ) => a . name . localeCompare ( b . name ) ) ;
64+ return snapshot . docs . map ( d => ( { id : d . id , ...d . data ( ) } ) ) . sort ( ( a : any , b : any ) => a . name . localeCompare ( b . name , undefined , { numeric : true } ) ) ;
6265} ;
6366
6467export const createSemester = ( batchId : string , name : string ) =>
@@ -73,7 +76,7 @@ export const deleteSemester = (id: string) => deleteDoc(doc(db, SEMESTERS, id));
7376export const getSubjects = async ( semesterId : string ) => {
7477 const q = query ( collection ( db , SUBJECTS ) , where ( "semesterId" , "==" , semesterId ) ) ;
7578 const snapshot = await getDocs ( q ) ;
76- return snapshot . docs . map ( d => ( { id : d . id , ...d . data ( ) } ) ) . sort ( ( a : any , b : any ) => a . name . localeCompare ( b . name ) ) ;
79+ return snapshot . docs . map ( d => ( { id : d . id , ...d . data ( ) } ) ) . sort ( ( a : any , b : any ) => a . name . localeCompare ( b . name , undefined , { numeric : true } ) ) ;
7780} ;
7881
7982export const createSubject = ( semesterId : string , name : string ) =>
@@ -90,7 +93,7 @@ export const getFolders = async (subjectId: string) => {
9093 const snapshot = await getDocs ( q ) ;
9194 return snapshot . docs
9295 . map ( d => ( { id : d . id , ...d . data ( ) } ) )
93- . sort ( ( a : any , b : any ) => ( a . name || "" ) . localeCompare ( b . name || "" ) ) ;
96+ . sort ( ( a : any , b : any ) => ( a . name || "" ) . localeCompare ( b . name || "" , undefined , { numeric : true } ) ) ;
9497} ;
9598
9699export const createFolder = ( data : any ) =>
0 commit comments