This repository was archived by the owner on Apr 10, 2023. It is now read-only.
-
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.
Update Available Notifications (#65)
* fix: clear session on logout * chore: session redo wip * chore: base64 encode session val, only store data we need * feat: wip notifications * feat: allow for dimissing notification/hiding pulse * chore: only render if update available
- Loading branch information
1 parent
6ec4fc3
commit 8ec6676
Showing
5 changed files
with
208 additions
and
30 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,142 @@ | ||
import { Transition } from '@headlessui/react'; | ||
import { | ||
BellIcon, | ||
MegaphoneIcon, | ||
XMarkIcon | ||
} from '@heroicons/react/24/outline'; | ||
import { Fragment, useState } from 'react'; | ||
import { useSessionStorage } from '~/data/hooks/storage'; | ||
import { Info } from '~/types/Meta'; | ||
|
||
type NotificationProps = { | ||
show: boolean; | ||
setShow: (show: boolean) => void; | ||
markSeen: () => void; | ||
info: Info; | ||
}; | ||
|
||
export function Notification(props: NotificationProps) { | ||
const { info, show, setShow, markSeen } = props; | ||
|
||
return ( | ||
<> | ||
<div | ||
aria-live="assertive" | ||
className="pointer-events-none fixed inset-0 z-10 flex items-end px-4 py-6 sm:items-start sm:p-4" | ||
> | ||
<div className="flex w-full flex-col items-center space-y-4 sm:items-end"> | ||
<Transition | ||
show={show} | ||
as={Fragment} | ||
enter="transform ease-out duration-300 transition" | ||
enterFrom="translate-y-2 opacity-0 sm:translate-y-0 sm:translate-x-2" | ||
enterTo="translate-y-0 opacity-100 sm:translate-x-0" | ||
leave="transition ease-in duration-100" | ||
leaveFrom="opacity-100" | ||
leaveTo="opacity-0" | ||
> | ||
<div className="pointer-events-auto w-full max-w-sm overflow-hidden rounded-lg bg-white shadow-lg ring-1 ring-black ring-opacity-5"> | ||
<div className="p-4"> | ||
<div className="flex items-start"> | ||
<div className="flex-shrink-0"> | ||
<MegaphoneIcon | ||
className="h-6 w-6 text-gray-400" | ||
aria-hidden="true" | ||
/> | ||
</div> | ||
<div className="ml-3 w-0 flex-1 pt-0.5"> | ||
<p className="text-sm font-medium text-gray-900"> | ||
Update Available | ||
</p> | ||
<p className="mt-1 text-sm text-gray-500"> | ||
A new version of Flipt is available! | ||
</p> | ||
<div className="mt-3 flex space-x-7 hover:cursor-pointer"> | ||
<a | ||
href={info.latestVersionURL} | ||
target="_blank" | ||
rel="noreferrer" | ||
className="rounded-md bg-white text-sm font-medium text-violet-600 hover:text-violet-500 focus:outline-none" | ||
> | ||
Check It Out | ||
</a> | ||
<a | ||
className="rounded-md bg-white text-sm font-medium text-gray-700 hover:text-gray-500 focus:outline-none" | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
setShow(false); | ||
markSeen(); | ||
}} | ||
> | ||
Dismiss | ||
</a> | ||
</div> | ||
</div> | ||
<div className="ml-4 flex flex-shrink-0"> | ||
<button | ||
type="button" | ||
className="inline-flex rounded-md bg-white text-gray-400 hover:text-gray-500 focus:outline-none" | ||
onClick={() => { | ||
setShow(false); | ||
markSeen(); | ||
}} | ||
> | ||
<span className="sr-only">Close</span> | ||
<XMarkIcon className="h-5 w-5" aria-hidden="true" /> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</Transition> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
type NotificationsProps = { | ||
info: Info; | ||
}; | ||
|
||
export default function Notifications(props: NotificationsProps) { | ||
const { info } = props; | ||
const [show, setShow] = useState(false); | ||
|
||
const [newNotifications, setNewNotification] = useSessionStorage( | ||
'new_notifications', | ||
info.updateAvailable | ||
); | ||
|
||
return ( | ||
<> | ||
<Notification | ||
info={info} | ||
show={show} | ||
setShow={setShow} | ||
markSeen={() => setNewNotification(false)} | ||
/> | ||
|
||
<button | ||
type="button" | ||
className="without-ring relative rounded-full text-violet-100" | ||
> | ||
{newNotifications && ( | ||
<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-white opacity-75"></span> | ||
<span className="relative inline-flex h-2 w-2 rounded-full bg-violet-100"></span> | ||
</span> | ||
)} | ||
<span className="sr-only">View notifications</span> | ||
|
||
<BellIcon | ||
className="h-8 w-6 fill-violet-300 hover:fill-violet-200" | ||
aria-hidden="true" | ||
onClick={() => { | ||
setShow(true); | ||
}} | ||
/> | ||
</button> | ||
</> | ||
); | ||
} |
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