-
-
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.
- Loading branch information
1 parent
322e450
commit 835be54
Showing
13 changed files
with
256 additions
and
14 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
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
64 changes: 64 additions & 0 deletions
64
desktop-app/src/renderer/components/useCheckVersion/useCheckVersion.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,64 @@ | ||
import { useState, useEffect } from 'react'; | ||
import { gt } from 'semver'; | ||
|
||
const fetchAssets = async () => { | ||
try { | ||
const response = await fetch( | ||
'https://api.github.com/repos/responsively-org/responsively-app-releases/releases/latest' | ||
); | ||
const data = await response.json(); | ||
return data.tag_name; | ||
} catch (err) { | ||
// eslint-disable-next-line no-console | ||
console.error('Error getting assets', err); | ||
return ''; | ||
} | ||
}; | ||
|
||
const getAppVersion = async () => { | ||
try { | ||
const version = await window.electron.ipcRenderer.invoke('get-app-version'); | ||
return `v${version}`; | ||
} catch (err) { | ||
// eslint-disable-next-line no-console | ||
console.error('Error getting app version', err); | ||
return ''; | ||
} | ||
}; | ||
|
||
const useCheckVersion = () => { | ||
const [isNewVersionAvailable, setIsNewVersionAvailable] = useState< | ||
null | boolean | ||
>(null); | ||
const [latestVersion, setLatestVersion] = useState(''); | ||
const [currentVersion, setCurrentVersion] = useState(''); | ||
|
||
useEffect(() => { | ||
const checkVersion = async () => { | ||
const currentVersionResult = await getAppVersion(); | ||
const latestVersionResult = await fetchAssets(); | ||
|
||
setCurrentVersion(currentVersionResult); | ||
setLatestVersion(latestVersionResult); | ||
|
||
const isNewVersion = | ||
currentVersionResult && | ||
latestVersionResult && | ||
gt(latestVersionResult, currentVersionResult); | ||
|
||
setIsNewVersionAvailable(isNewVersion); | ||
}; | ||
|
||
if (isNewVersionAvailable === null) { | ||
checkVersion(); | ||
} | ||
}, [currentVersion, isNewVersionAvailable, latestVersion]); | ||
|
||
return { | ||
isNewVersionAvailable, | ||
currentVersion, | ||
latestVersion, | ||
}; | ||
}; | ||
|
||
export default useCheckVersion; |
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; |
Oops, something went wrong.