-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1313 from responsively-org/update-button
Add a notification component
- Loading branch information
Showing
11 changed files
with
174 additions
and
13 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
33 changes: 33 additions & 0 deletions
33
desktop-app/src/renderer/components/Notifications/Notification.tsx
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,33 @@ | ||
import { | ||
IPC_MAIN_CHANNELS, | ||
Notification as NotificationType, | ||
} from 'common/constants'; | ||
import Button from '../Button'; | ||
|
||
const Notification = ({ notification }: { notification: NotificationType }) => { | ||
const handleLinkClick = (url: string) => { | ||
window.electron.ipcRenderer.sendMessage(IPC_MAIN_CHANNELS.OPEN_EXTERNAL, { | ||
url, | ||
}); | ||
}; | ||
|
||
return ( | ||
<div className="mb-2 text-sm text-white"> | ||
<p> {notification.text} </p> | ||
{notification.link && notification.linkText && ( | ||
<Button | ||
isPrimary | ||
title={notification.linkText} | ||
onClick={() => | ||
notification.link && handleLinkClick(notification.link) | ||
} | ||
className="mt-2" | ||
> | ||
{notification.linkText} | ||
</Button> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Notification; |
9 changes: 9 additions & 0 deletions
9
desktop-app/src/renderer/components/Notifications/NotificationEmptyStatus.tsx
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,9 @@ | ||
const NotificationEmptyStatus = () => { | ||
return ( | ||
<div className="mb-2 text-sm text-white"> | ||
<p>You are all caught up! No new notifications at the moment.</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export default NotificationEmptyStatus; |
29 changes: 29 additions & 0 deletions
29
desktop-app/src/renderer/components/Notifications/Notifications.tsx
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,29 @@ | ||
import { useSelector } from 'react-redux'; | ||
import { selectNotifications } from 'renderer/store/features/renderer'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import { Notification as NotificationType } from 'common/constants'; | ||
import Notification from './Notification'; | ||
import NotificationEmptyStatus from './NotificationEmptyStatus'; | ||
|
||
const Notifications = () => { | ||
const notificationsState = useSelector(selectNotifications); | ||
|
||
return ( | ||
<div className="mb-4 max-h-[200px] overflow-y-auto rounded-lg p-1 px-4 shadow-lg dark:bg-slate-900"> | ||
<span className="text-lg">Notifications</span> | ||
<div className="mt-2"> | ||
{(!notificationsState || | ||
(notificationsState && notificationsState?.length === 0)) && ( | ||
<NotificationEmptyStatus /> | ||
)} | ||
{notificationsState && | ||
notificationsState?.length > 0 && | ||
notificationsState?.map((notification: NotificationType) => ( | ||
<Notification key={uuidv4()} notification={notification} /> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Notifications; |
10 changes: 10 additions & 0 deletions
10
desktop-app/src/renderer/components/Notifications/NotificationsBubble.tsx
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,10 @@ | ||
const NotificationsBubble = () => { | ||
return ( | ||
<span className="absolute top-0 right-0 flex h-2 w-2"> | ||
<span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-red-400 opacity-75" /> | ||
<span className="relative inline-flex h-2 w-2 rounded-full bg-red-500" /> | ||
</span> | ||
); | ||
}; | ||
|
||
export default NotificationsBubble; |
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
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
44 changes: 44 additions & 0 deletions
44
desktop-app/src/renderer/components/useLocalStorage/useLocalStorage.tsx
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,44 @@ | ||
import { useState, useEffect } from 'react'; | ||
|
||
function useLocalStorage<T>(key: string, initialValue?: T) { | ||
const [storedValue, setStoredValue] = useState<T | undefined>(() => { | ||
try { | ||
const item = window.localStorage.getItem(key); | ||
return item ? (JSON.parse(item) as T) : undefined; | ||
} catch (error) { | ||
console.error('Error reading from localStorage', error); | ||
return undefined; | ||
} | ||
}); | ||
|
||
useEffect(() => { | ||
if (storedValue === undefined && initialValue !== undefined) { | ||
setStoredValue(initialValue); | ||
window.localStorage.setItem(key, JSON.stringify(initialValue)); | ||
} | ||
}, [initialValue, storedValue, key]); | ||
|
||
const setValue = (value: T | ((val: T | undefined) => T)) => { | ||
try { | ||
const valueToStore = | ||
value instanceof Function ? value(storedValue) : value; | ||
setStoredValue(valueToStore); | ||
window.localStorage.setItem(key, JSON.stringify(valueToStore)); | ||
} catch (error) { | ||
console.error('Error setting localStorage', error); | ||
} | ||
}; | ||
|
||
const removeValue = () => { | ||
try { | ||
window.localStorage.removeItem(key); | ||
setStoredValue(undefined); | ||
} catch (error) { | ||
console.error('Error removing from localStorage', error); | ||
} | ||
}; | ||
|
||
return [storedValue, setValue, removeValue] as const; | ||
} | ||
|
||
export default useLocalStorage; |
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