Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 43 additions & 43 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dynamods/notifications-center",
"version": "0.0.13",
"version": "0.0.15",
"description": "Notification center maintained by Dynamo Team@Autodesk",
"author": "Autodesk Inc.",
"license": "MIT",
Expand Down Expand Up @@ -32,7 +32,7 @@
"@babel/core": "^7.18.6",
"@babel/preset-env": "^7.18.6",
"@babel/preset-react": "^7.18.6",
"@filipeop/notifications-panel": "^0.0.2",
"@dynamods/notifications-panel": "^0.0.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

"@hig/timestamp": "^2.1.0",
"axios": "^0.27.2",
"babel-loader": "^8.2.5",
Expand Down
100 changes: 62 additions & 38 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,75 @@
import './App.css';
import axios from 'axios';
import React, { useEffect, useState } from 'react';
import NotificationsPanel from '@filipeop/notifications-panel';
import NotificationsPanel from '@dynamods/notifications-panel';
import Timestamp from '@hig/timestamp';
import axios from 'axios';

function App() {
const [APIData, setAPIData] = useState(false);

const [APIData, setAPIData] = useState({ loaded: false, notifications: [] });


useEffect(() => {
window.RequestNotifications = RequestNotifications;
RequestNotifications();
}, []);

const RequestNotifications = (url) => {
let getURL = url || process.env.NOTIFICATION_URL;
if(getURL){
axios.get(getURL)
.then((response) => {
const notifications = response.data.notifications;
let notificationData = [];
for (let i = 0; i < notifications.length; i++) {
var notificationItem = {
id: notifications[i].id,
featured: true,
unread: true,
image: <img width={40} src={notifications[i].thumbnail}></img>,
message: notifications[i].title,
href: notifications[i].linkTitle,
timestamp: <Timestamp timestamp={notifications[i].created} />,
content: <div>
<b>{notifications[i].title}</b>
<p>{notifications[i].longDescription}</p>
<a href={notifications[i].link} target="_blank">{notifications[i].linkTitle}</a>
</div>
};
notificationData.push(notificationItem);
}
setAPIData(notificationData);
});

if (process.env.NOTIFICATION_URL) {
axios.get(process.env.NOTIFICATION_URL)
.then((response) => {

let notificationsData = parseNotifications(response.data.notifications);
setAPIData(() => {
return {
loaded: true,
notifications: notificationsData
}
});

});
}
else {
window.setNotifications = setNotifications;
}

}, []);

const setNotifications = (notifications) => {
let notificationsData = parseNotifications(notifications);
setAPIData(prevState => {
return {
loaded: true,
notifications: [...prevState.notifications, ...notificationsData]
}
});
}

return APIData ?
<NotificationsPanel class="NotificationsFlyout"
function parseNotifications(notifications) {
let notificationsData = [];
for (let i = 0; i < notifications.length; i++) {
var notificationItem = {
id: notifications[i].id,
featured: true,
unread: true,
image: <img width={40} src={notifications[i].thumbnail}></img>,
message: notifications[i].title,
href: notifications[i].linkTitle,
timestamp: <Timestamp timestamp={notifications[i].created} />,
content: <div>
<b>{notifications[i].title}</b>
<p>{notifications[i].longDescription}</p>
<a href={notifications[i].link} target="_blank">{notifications[i].linkTitle}</a>
</div>
};
notificationsData.push(notificationItem);
}
return notificationsData;
};


return APIData.loaded ?
<NotificationsPanel class="NotificationsFlyout"
heading="Notifications"
indicatorTitle="View application alerts"
notifications={APIData}>
</NotificationsPanel>
: null;
notifications={APIData.notifications}>
</NotificationsPanel>
: null;
}
export default App;