|
|
@@ -107,7 +107,22 @@ export const getMenuCollectionsByProductType = (products = []) => {
|
|
107
|
107
|
menuCollections[productType][menuGroup].set(key, {
|
|
108
|
108
|
...collection,
|
|
109
|
109
|
menuGroup,
|
|
|
110
|
+ latestProductUpdatedAt: product?.updatedAt || product?.createdAt || null,
|
|
110
|
111
|
});
|
|
|
112
|
+ } else {
|
|
|
113
|
+ const existingCollection = menuCollections[productType][menuGroup].get(key);
|
|
|
114
|
+ const existingUpdatedAt = existingCollection?.latestProductUpdatedAt
|
|
|
115
|
+ ? Date.parse(existingCollection.latestProductUpdatedAt)
|
|
|
116
|
+ : 0;
|
|
|
117
|
+ const productUpdatedAt = product?.updatedAt || product?.createdAt || null;
|
|
|
118
|
+ const productUpdatedAtTime = productUpdatedAt ? Date.parse(productUpdatedAt) : 0;
|
|
|
119
|
+
|
|
|
120
|
+ if (productUpdatedAtTime > existingUpdatedAt) {
|
|
|
121
|
+ menuCollections[productType][menuGroup].set(key, {
|
|
|
122
|
+ ...existingCollection,
|
|
|
123
|
+ latestProductUpdatedAt: productUpdatedAt,
|
|
|
124
|
+ });
|
|
|
125
|
+ }
|
|
111
|
126
|
}
|
|
112
|
127
|
});
|
|
113
|
128
|
|
|
|
@@ -123,11 +138,19 @@ const mapCollectionToMenuItem = (collection = {}) => ({
|
|
123
|
138
|
collection,
|
|
124
|
139
|
});
|
|
125
|
140
|
|
|
126
|
|
-// Utility function to sort collections by their updatedAt timestamp, with a fallback to title comparison
|
|
|
141
|
+// Utility function to sort collections by their latest product update timestamp, with collection updatedAt and title fallbacks
|
|
127
|
142
|
const sortCollectionsByNewest = (collections = []) => (
|
|
128
|
143
|
[...collections].sort((a, b) => {
|
|
129
|
|
- const aUpdatedAt = a?.updatedAt ? Date.parse(a.updatedAt) : 0;
|
|
130
|
|
- const bUpdatedAt = b?.updatedAt ? Date.parse(b.updatedAt) : 0;
|
|
|
144
|
+ const aUpdatedAt = a?.latestProductUpdatedAt
|
|
|
145
|
+ ? Date.parse(a.latestProductUpdatedAt)
|
|
|
146
|
+ : a?.updatedAt
|
|
|
147
|
+ ? Date.parse(a.updatedAt)
|
|
|
148
|
+ : 0;
|
|
|
149
|
+ const bUpdatedAt = b?.latestProductUpdatedAt
|
|
|
150
|
+ ? Date.parse(b.latestProductUpdatedAt)
|
|
|
151
|
+ : b?.updatedAt
|
|
|
152
|
+ ? Date.parse(b.updatedAt)
|
|
|
153
|
+ : 0;
|
|
131
|
154
|
|
|
132
|
155
|
if (aUpdatedAt !== bUpdatedAt) {
|
|
133
|
156
|
return bUpdatedAt - aUpdatedAt;
|