Skip to content

Commit

Permalink
Personal Reminder V-1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Raza9798 committed Aug 2, 2024
0 parents commit 072780e
Show file tree
Hide file tree
Showing 23 changed files with 20,905 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REACT_APP_NAME="REMINDER"
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Mohamed Raza

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
23 changes: 23 additions & 0 deletions Provider/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
84 changes: 84 additions & 0 deletions Provider/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const express = require('express');
const moment = require('moment');
const app = express();
const port = 3030;
const cors = require('cors');
const formidable = require('express-formidable');
const notifier = require('node-notifier');

app.use(formidable({
encoding: 'utf-8',
uploadDir: '/storage',
multiples: true
}));
app.use(cors());

const notificationArr = [];
const notificationIntervals = {};

const notify = () => {
notificationArr.forEach(element => {
if (!notificationIntervals[element.title]) {
const intervalId = setInterval(() => {
console.log('Reminder', {
title: element.title,
duration: element.duration,
time: moment().format('hh:mm:ss A')
});

let message = `${element.title} - ${moment().format('hh:mm:ss A')}`;
notifier.notify({
title: 'Reminder',
message: message,
sound: true,
wait: true,
actions: ['Done', 'Cancel']
}, (err, response, metadata) => {
if (err) {
console.error('Notification error:', err);
} else {
if (response === 'activate' && metadata.activationValue === 'Done') {
clearInterval(intervalId);
delete notificationIntervals[element.title];
const index = notificationArr.findIndex(n => n.title === element.title);
if (index > -1) {
notificationArr.splice(index, 1);
}
}
}
});
}, moment.duration(element.duration).asMilliseconds());

notificationIntervals[element.title] = intervalId;
}
});
};

app.get('/', (req, res) => {
const { enable, title, duration } = req.query;

if (enable === 'true') {
if (!notificationArr.some(n => n.title === title)) {
notificationArr.push({ title, duration });
}
notify();
} else {
const index = notificationArr.findIndex(n => n.title === title);
if (index > -1) {
clearInterval(notificationIntervals[title]);
delete notificationIntervals[title];
notificationArr.splice(index, 1);
}
}

if (notificationArr.length === 0) {
console.log('NO NOTIFICATIONS ON QUEUE');
} else {
console.log('NOTIFICATION LIST UPDATE =>', notificationArr);
}
res.sendStatus(200);
});

app.listen(port, () => {
console.log('REMINDER SERVICE STARTED');
});
Loading

0 comments on commit 072780e

Please sign in to comment.