Skip to content

Commit

Permalink
Add config file to provide notification URL (#18)
Browse files Browse the repository at this point in the history
* add config

* add dev and prod configs

* Update App.js

* Update README.md

* cong

* Update README.md

* Update package.json
  • Loading branch information
zeusongit authored Aug 15, 2022
1 parent e32aadd commit aeb8d49
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 70 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ If you need to update `npm`, you can make it using `npm`!
cd NotificationCenter
npm install --force

Note:
Make sure that you have correct endpoint set inside `config/.env` file:
You case this URL for dev notifications: https://d2xm4bcf3at21r.cloudfront.net/dynNotifications.json

## Running the project

npm run start
Expand Down
1 change: 1 addition & 0 deletions config/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NOTIFICATION_URL=""
1 change: 1 addition & 0 deletions config/.env.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NOTIFICATION_URL=""
58 changes: 58 additions & 0 deletions package-lock.json

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

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dynamods/notifications-center",
"version": "0.0.10",
"version": "0.0.11",
"description": "Notification center maintained by Dynamo Team@Autodesk",
"author": "Autodesk Inc.",
"license": "MIT",
Expand All @@ -18,7 +18,7 @@
"lint:fix": "eslint src/ tests/ --fix",
"test": "npm run lint:fix && jest",
"start": "webpack serve",
"build": "webpack --config webpack.config.js --mode=development",
"build": "webpack --config webpack.config.js --env dev --mode=development",
"bundle": "webpack --config webpack.config.js --mode=production",
"copy": "cp package.json dist/ && cp README.md dist/",
"production": "npm run bundle && npm run copy"
Expand All @@ -29,15 +29,16 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@filipeop/notifications-panel": "^0.0.2",
"@babel/core": "^7.18.6",
"@babel/preset-env": "^7.18.6",
"@babel/preset-react": "^7.18.6",
"@filipeop/notifications-panel": "^0.0.2",
"@hig/timestamp": "^2.1.0",
"axios": "^0.27.2",
"babel-loader": "^8.2.5",
"compression-webpack-plugin": "^10.0.0",
"css-loader": "^6.7.1",
"dotenv-webpack": "^8.0.0",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.6",
"eslint": "^8.21.0",
Expand Down
56 changes: 28 additions & 28 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,34 @@ import Timestamp from '@hig/timestamp';
function App() {
const [APIData, setAPIData] = useState(false);
useEffect(() => {
axios.get('http://demo9540080.mockable.io/notifications')
.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}>{notifications[i].linkTitle}</a>
</div>
};
notificationData.push(notificationItem);
}

setAPIData(notificationData);
});
window.RequestNotifications = RequestNotifications;
}, []);


const RequestNotifications = (url) => {
axios.get(url)
.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}>{notifications[i].linkTitle}</a>
</div>
};
notificationData.push(notificationItem);
}
setAPIData(notificationData);
});
}
return APIData ?
<NotificationsPanel class="NotificationsFlyout"
heading="Notifications"
Expand All @@ -42,5 +43,4 @@ function App() {
</NotificationsPanel>
: null;
}

export default App;
export default App;
86 changes: 47 additions & 39 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,52 @@
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const Dotenv = require('dotenv-webpack');

module.exports = {
mode: 'development',
entry: {
app: './src/index.js',
},
output: {
path: path.join(__dirname, '/dist/build'),
filename: 'index.bundle.js',
publicPath: '',
clean: true,
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.(scss|css)$/,
exclude: /node_modules/,
use: [
'style-loader',
'css-loader',
'sass-loader'
]
}
]
},
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
module.exports = env => {
return {
mode: 'development',
entry: {
app: './src/index.js',
},
output: {
path: path.join(__dirname, '/dist/build'),
filename: 'index.bundle.js',
publicPath: '',
clean: true,
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.(scss|css)$/,
exclude: /node_modules/,
use: [
'style-loader',
'css-loader',
'sass-loader'
]
}
]
},
}),
],
}
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
},
}),
],
},
plugins: [
new Dotenv({
path: `./config/.env${env.dev ? `.dev` : ''}`
})
]
}
};

0 comments on commit aeb8d49

Please sign in to comment.