From b7c5501cc71cc5771c518d89e79592dfc4d39529 Mon Sep 17 00:00:00 2001 From: hv2308 Date: Tue, 14 Jan 2025 23:50:14 +0530 Subject: [PATCH] Added sort order key --- backend/api/models/Training.py | 4 +++- frontend/src/components/TrainingList.js | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/backend/api/models/Training.py b/backend/api/models/Training.py index e9d7c293..9a990de0 100644 --- a/backend/api/models/Training.py +++ b/backend/api/models/Training.py @@ -27,10 +27,12 @@ class Training(Document, Mixin): partner_id = StringField(required=False) mentor_id = ListField(StringField(), required=False) mentee_id = ListField(StringField(), required=False) + sort_order = IntField(required=False, default=0) def __repr__(self): return f"""""" + \n date_submitted: {self.date_submitted} + \n sort_order: {self.sort_order}>""" \ No newline at end of file diff --git a/frontend/src/components/TrainingList.js b/frontend/src/components/TrainingList.js index f0eae06a..5bd627b2 100644 --- a/frontend/src/components/TrainingList.js +++ b/frontend/src/components/TrainingList.js @@ -203,9 +203,9 @@ const TrainingList = (props) => { } else { hub_user_id = user._id.$oid; } - setTrainingData(trains.filter((x) => x.hub_id == hub_user_id)); + setTrainingData(trains.sort((a, b)=> a.sort_order - b.sort_order).filter((x) => x.hub_id == hub_user_id)); } else { - setTrainingData(trains); + setTrainingData(trains.sort((a, b)=> a.sort_order - b.sort_order)); } setLoading(false); setFlag(!flag);