-
Notifications
You must be signed in to change notification settings - Fork 7
adding the setNotifications function #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
QilongTang
merged 5 commits into
DynamoDS:master
from
filipeotero:SetNotifications-Function
Aug 24, 2022
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0616cec
adding the setNotifications function
filipeotero 241b176
update package version and notifictions-panel
filipeotero aaa9107
removing console.log and extra import
filipeotero 757380d
using the URL parameter to request the backend
filipeotero 7ebffc5
incrementing version
filipeotero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻