-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Game): Global notification system
This patch brings along a global notification system. When opening items such as treasure chests, you'll now see the results cleaned up within the notification system that was previously utilized in the gathering page.
- Loading branch information
1 parent
aa2f4a9
commit 58a3459
Showing
7 changed files
with
105 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React, { useEffect } from 'react'; | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
import { clearNotificationMessage } from '../features/notifications/notificationSlice'; | ||
import '../styles/notification.css'; | ||
|
||
const Notification = () => { | ||
const notificationMessage = useSelector((state) => state.notifications.message); | ||
const dispatch = useDispatch(); | ||
|
||
useEffect(() => { | ||
if (notificationMessage) { | ||
const timer = setTimeout(() => { | ||
dispatch(clearNotificationMessage()); | ||
}, 3000); | ||
return () => clearTimeout(timer); | ||
} | ||
}, [notificationMessage, dispatch]); | ||
|
||
if (!notificationMessage) return null; | ||
|
||
return ( | ||
<div className="notification"> | ||
{notificationMessage} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Notification; |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
|
||
const notificationSlice = createSlice({ | ||
name: 'notifications', | ||
initialState: { | ||
message: null, | ||
}, | ||
reducers: { | ||
setNotificationMessage: (state, action) => { | ||
state.message = action.payload; | ||
}, | ||
clearNotificationMessage: (state) => { | ||
state.message = null; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { setNotificationMessage, clearNotificationMessage } = notificationSlice.actions; | ||
|
||
export default notificationSlice.reducer; |
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.notification { | ||
position: fixed; | ||
top: 20px; | ||
right: 20px; | ||
padding: 10px; | ||
background-color: #323232; | ||
color: #fff; | ||
border-radius: 5px; | ||
z-index: 1000; | ||
transition: opacity 0.3s ease; | ||
} | ||
|