Skip to content

Commit b774389

Browse files
authored
Merge pull request #557 from rvsia/convertNotToArray
Convert firebase object to array
2 parents 99f0fc7 + 9edc81e commit b774389

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/react-renderer-demo/src/components/notification-panel.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,17 @@ const getNotifications = () => {
4040
const query = `?orderBy="expired-at"&startAt="${new Date().toISOString()}"&limitToFirst=10`;
4141
return fetch(`https://data-driven-forms.firebaseio.com/notifications.json${query}`)
4242
.then((data) => data.json())
43-
.then((data) => (data ? data.filter(Boolean).sort((a, b) => b['created-at'].localeCompare(a['created-at'])) : []));
43+
.then((data) => {
44+
if (typeof data !== 'object') {
45+
return [];
46+
}
47+
48+
if (!Array.isArray(data)) {
49+
data = Object.values(data);
50+
}
51+
52+
return data.filter(Boolean).sort((a, b) => b['created-at'].localeCompare(a['created-at']));
53+
});
4454
};
4555

4656
const createNotificationId = (notification) => `${notification['created-at']}-${notification['expired-at']}`;

0 commit comments

Comments
 (0)