Skip to content

Commit

Permalink
notification
Browse files Browse the repository at this point in the history
  • Loading branch information
aman44444 committed Jun 17, 2024
1 parent 58cc2da commit 9211e16
Show file tree
Hide file tree
Showing 10 changed files with 245 additions and 98 deletions.
41 changes: 32 additions & 9 deletions src/Components/Input.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React, { useState } from 'react';
import '../Styles/Input.css';
import Output from './Output';
import AlarmClock from './reminder';
import Notification from './Notification';
import AlarmClock from './Reminder';

const Input = () => {
const [task, setTask] = useState("")
const [data, setData] = useState([])
const [alarm, setAlarm] = useState('');

const [notifications, setNotifications] = useState([]);

const onChangeHandler = (e) => setTask(e.target.value);

const taskHandler = (e) => {
Expand All @@ -28,6 +29,14 @@ const Input = () => {
setAlarm(inputAlarmTimeModified);
};

const handleAlarmTrigger = (task) => {
setNotifications([...notifications, task]);
};

const closeNotification = (task) => {
setNotifications(notifications.filter(notif => notif !== task));
};

return (
<>
<div className="form-container">
Expand All @@ -47,14 +56,27 @@ const Input = () => {
</div>
</form>
</div>
<div className="notifications">
{notifications.map((task, index) => (
<Notification key={index} task={task} onClose={() => closeNotification(task)} />
))}
</div>
<div className='container'>
<div className='task-container'>

{data.map((value, index) => (
<div className="task-alarm-pair" key={index}>
<Output id={index} number={index + 1} task={value.task} onSelect={deleteItem} />
<AlarmClock alarmTime={value.alarm} />
</div>
{data.map((value, index) => (
<div className="task-alarm-pair" key={index}>
<Output
id={index}
number={index + 1}
task={value.task}
onSelect={deleteItem} />

<AlarmClock
alarmTime={value.alarm}
task={value.task}
onAlarmTrigger={handleAlarmTrigger}/>
</div>
))}
</div>
</div>
Expand All @@ -63,4 +85,5 @@ const Input = () => {

}

export default Input;
export default Input;

17 changes: 17 additions & 0 deletions src/Components/Notification.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import '../Styles/Notification.css';

const Notification = ({ task, onClose }) => {
return (
<div className="notification">
<div className="notification-content">
<p>{`Alarm for task: ${task}`}</p>
<button onClick={onClose} className="close-btn">Close</button>
</div>
</div>
);
};

export default Notification;


6 changes: 4 additions & 2 deletions src/Components/reminder.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const playAlarmSound = () => {
audio.play();
};

const AlarmClock = ({alarmTime}) => {
const AlarmClock = ({alarmTime, task, onAlarmTrigger}) => {
const [currentTime, setCurrentTime] = useState('');
const [alarmMessage, setAlarmMessage] = useState('');

Expand All @@ -16,9 +16,10 @@ const AlarmClock = ({alarmTime}) => {
setAlarmMessage(alarmTime);
if (currentTime === alarmTime) {
playAlarmSound();
onAlarmTrigger(task);
}
}
},[alarmTime,currentTime]);
},[alarmTime,currentTime, onAlarmTrigger, task]);


useEffect(() => {
Expand All @@ -44,3 +45,4 @@ const AlarmClock = ({alarmTime}) => {

export default AlarmClock;


4 changes: 3 additions & 1 deletion src/Styles/Input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,6 @@
border: 1px solid rgb(197, 190, 190);
width:20%
}
}
}


48 changes: 48 additions & 0 deletions src/Styles/Notification.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
.notification {
position: fixed;
top: 1em;
left: 50%;
transform: translateX(-50%);
background-color: #ffffff;
color: #040404;
border-radius: 15px;
padding: 1em 2em;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
display: flex;
justify-content: space-between;
align-items: center;
z-index: 1000;
animation: slide-down 0.5s ease-in-out;
}

.notification-content {
display: flex;
align-items: center;
justify-content: space-between;
}

.notification p {
margin: 0;
font-size: 1.2em;
}

.close-btn {
background: #000000;
color: white;
border: none;
padding: 0.5em 1em;
border-radius: 5px;
cursor: pointer;
margin-left: 1em;
}

@keyframes slide-down {
from {
opacity: 0;
transform: translate(-50%, -100%);
}
to {
opacity: 1;
transform: translate(-50%, 0);
}
}/*# sourceMappingURL=Notification.css.map */
1 change: 1 addition & 0 deletions src/Styles/Notification.css.map

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

48 changes: 48 additions & 0 deletions src/Styles/Notification.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
.notification {
position: fixed;
top: 1em;
left: 50%;
transform: translateX(-50%);
background-color: #ffffff;
color: #040404;
border-radius: 15px;
padding: 1em 2em;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
display: flex;
justify-content: space-between;
align-items: center;
z-index: 1000;
animation: slide-down 0.5s ease-in-out;
}

.notification-content {
display: flex;
align-items: center;
justify-content: space-between;
}

.notification p {
margin: 0;
font-size: 1.2em;
}

.close-btn {
background: #000000;
color: white;
border: none;
padding: 0.5em 1em;
border-radius: 5px;
cursor: pointer;
margin-left: 1em;
}

@keyframes slide-down {
from {
opacity: 0;
transform: translate(-50%, -100%);
}
to {
opacity: 1;
transform: translate(-50%, 0);
}
}
58 changes: 40 additions & 18 deletions src/Styles/Output.css
Original file line number Diff line number Diff line change
@@ -1,27 +1,49 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

.output-task {
display: flex;
justify-content: space-between;
align-items: center;
background: #f9f9f9;
padding: 1em;
border-radius: 0.5em;
width: 100%;
height: auto;
flex-direction: row;
margin-top: 0.5em;
border-bottom: 1px solid rgb(227, 220, 220);
word-wrap: break-word;
overflow-wrap: break-word;
display: flex;
justify-content: center;
align-items: center;
}
.output-task .task {
width: 80%;
}
.output-task .task p {
font-size: 1.1em;
}
.output-task .task-number {

.delete-btn {
border: none;
height: 1.5em;
width: 2.5em;
border-radius: 1.3em;
background-color: black;
color: white;
}

.task-number {
flex-shrink: 0;
margin-right: 1em;
font-weight: bold;
}
.output-task .task {
flex: 1;
padding-right: 1em;
}
.output-task .delete-btn {
background: red;
color: white;
border: none;
padding: 0.5em 1em;
border-radius: 0.5em;
cursor: pointer;

.notifications {
position: fixed;
top: 1em;
left: 50%;
transform: translateX(-50%);
display: flex;
flex-direction: column;
gap: 1em;
}/*# sourceMappingURL=Output.css.map */
2 changes: 1 addition & 1 deletion src/Styles/Output.css.map

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

Loading

0 comments on commit 9211e16

Please sign in to comment.