-
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.
feat: Implement notifications handling (#25)
* feat: Implement ´DirectMessageModal´ component * feat: Abstract logic into ´useUserSearch´ and ´useInvitationLink´ hooks * feat: Implement ´DirectChatRecent´ component * feat: Implement ´DirectMessageModal´ for SidebarActions * fix: Resolve comments of the PR * feat: Implement `useDebounced` hook * feat: More use `useCallback` for `useSidebarActions` * refactor: Convert `SidebarActions` as smart component * refactor: Improve `Modal` component for use `createPortal` * refactor: More use `Modal` component * refactor: Improve modals handling for `SidebarActions` component * feat: Implement `NotificationsModal` and `Notification` components * fix: Fix visual problems for `Modal` * refactor: Resolve PR comments about tailwindcss class * refactor: Remove redundant tailwindcss class * feat: Implement `useNotification` hook * refactor: Resolve PR comments. * refactor: Fix TailwindCss class problems * feat: Implement notifications handling for `useNotifications` hook * feat: Implement `useSidebarModalActiveStore` * fix: Fix visual problems for components. * fix: Fix storybook stories problems * feat: Upgrade `Typography` component * feat: Upgrade `UserProfile` component * refactor: Refactor storybook stories * feat: Implement `useChatInput` for `ChatContainer` component * fix: Fix visual problem for `TextMessage` * feat: Implement `useCachedNotifications` hook * Merge with cristian/upgrade-components * refactor: Remove footer for `Readme.md` * fix: Fix `pre-commit` problems * feat: Implement events handling for notifications * feat: Improve notifications handling * fix: Test eslint actions * Revert "fix: Test eslint actions" This reverts commit 0553f60. * feat: Implement room member events for notifications * feat: Implement mention for notification * feat: Upgrade `saveNotification` for `useCachedNotifications` * fix: Improve code for `NotificationsModal` * feat: Implement power levels event for notifications * feat: Implement deploy-pages for deployment * refactor: Upgrade deploy-pages * feat: Implement deploy from dev for github actions * fix: Resolve PR comments * feat: Implement delete notification action * feat: Implement mark as read for notifications * feat: Implement `markAsReadAllNotifications` function for `useCachedNotifications` * feat: Implement `useNotificationsStateStore` * fix: Fix PR comments * feat: Implement handling directs room for notifications * fix: Fix PR problems * feat: Upgrade local notifications handling * feat: Implement other type of notification handling * feat: Upgrade new notification handling * feat: Upgrade `power levels` event for notifications * feat: Upgrade members event for notifications * refactor: Fix PR comments * fix: Upgrade `saveNotification` function * fix: Resolve PR comments * fix: Use key for lists * refactor: Use yarn for `pre-commit` * fix: Fix prettier problems
- Loading branch information
Showing
29 changed files
with
733 additions
and
259 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,26 @@ | ||
name: Build and Deploy to GitHub Pages | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install Dependencies | ||
run: yarn | ||
|
||
- name: Build Project | ||
run: yarn build | ||
|
||
- name: Deploy to GitHub Pages | ||
uses: peaceiris/actions-gh-pages@v3 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: ./dist |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npx eslint "src/**/*.ts" | ||
npx commitlint --edit "$1" | ||
yarn lint | ||
yarn commitlint --edit |
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
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
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,151 @@ | ||
import useMatrixAction from "@/hooks/matrix/useMatrixAction" | ||
import { | ||
deleteNotificationById, | ||
markAsReadByNotificationId, | ||
} from "@/utils/notifications" | ||
import {stringToColor, timeFormatter} from "@/utils/util" | ||
import {type FC} from "react" | ||
import {IoTime, IoCheckbox, IoTrash} from "react-icons/io5" | ||
import {twMerge} from "tailwind-merge" | ||
import AvatarImage, {AvatarType} from "../Avatar" | ||
import Button, {ButtonColor, ButtonSize, ButtonVariant} from "../Button" | ||
import IconButton from "../IconButton" | ||
import Typography, {TypographyVariant} from "../Typography" | ||
import {type LocalNotificationData} from "./useCachedNotifications" | ||
|
||
export interface NotificationProps extends LocalNotificationData { | ||
onRequestChanges: () => void | ||
hasActions: boolean | ||
} | ||
|
||
const Notification: FC<NotificationProps> = ({ | ||
body, | ||
notificationTime, | ||
hasActions, | ||
senderName, | ||
avatarSenderUrl, | ||
notificationId, | ||
isRead, | ||
onRequestChanges, | ||
}) => { | ||
const onJoinRoom = useMatrixAction(client => { | ||
if (!hasActions) { | ||
return null | ||
} | ||
|
||
void client.joinRoom(notificationId) | ||
deleteNotificationById(notificationId) | ||
onRequestChanges() | ||
}) | ||
|
||
// TODO: Launch `Toast` if you rejected the room invitation. | ||
const onLeaveRoom = useMatrixAction(client => { | ||
if (!hasActions) { | ||
return | ||
} | ||
|
||
void client.leave(notificationId) | ||
deleteNotificationById(notificationId) | ||
onRequestChanges() | ||
}) | ||
|
||
const userComponent = | ||
senderName === undefined ? undefined : ( | ||
<b style={{color: stringToColor(senderName)}}>{senderName}</b> | ||
) | ||
|
||
return ( | ||
<div | ||
className={twMerge( | ||
"flex gap-2 p-2", | ||
!isRead && "rounded-lg bg-slate-100" | ||
)}> | ||
{senderName !== undefined && ( | ||
<div className="size-full max-h-8 max-w-8 overflow-hidden rounded-lg"> | ||
<AvatarImage | ||
isRounded={false} | ||
isLarge={false} | ||
avatarType={AvatarType.Message} | ||
displayName={senderName} | ||
avatarUrl={avatarSenderUrl} | ||
/> | ||
</div> | ||
)} | ||
|
||
<div className="flex flex-col gap-1"> | ||
<div className="flex flex-row"> | ||
<Typography variant={TypographyVariant.P}> | ||
{userComponent} {body} | ||
</Typography> | ||
</div> | ||
|
||
<div className="flex items-center gap-[2px]"> | ||
<IoTime size={13} /> | ||
|
||
<Typography variant={TypographyVariant.P}> | ||
{timeFormatter(notificationTime)} | ||
</Typography> | ||
</div> | ||
|
||
{hasActions && ( | ||
<div className="mt-2 flex flex-row gap-1"> | ||
<Button | ||
label="Accept" | ||
color={ButtonColor.Black} | ||
size={ButtonSize.Small} | ||
onClick={() => { | ||
if (onJoinRoom === null) { | ||
return | ||
} | ||
|
||
void onJoinRoom() | ||
}} | ||
/> | ||
|
||
<Button | ||
label="Decline" | ||
variant={ButtonVariant.TextLink} | ||
color={ButtonColor.Black} | ||
size={ButtonSize.Small} | ||
onClick={() => { | ||
if (onLeaveRoom === null) { | ||
return | ||
} | ||
|
||
void onLeaveRoom() | ||
}} | ||
/> | ||
</div> | ||
)} | ||
</div> | ||
|
||
<div className="ml-auto flex"> | ||
{!isRead && ( | ||
<IconButton | ||
className="size-min" | ||
size={14} | ||
tooltip="Remove notification" | ||
Icon={IoCheckbox} | ||
onClick={() => { | ||
markAsReadByNotificationId(notificationId) | ||
onRequestChanges() | ||
}} | ||
/> | ||
)} | ||
|
||
<IconButton | ||
className="size-min" | ||
size={14} | ||
tooltip="Remove notification" | ||
Icon={IoTrash} | ||
onClick={() => { | ||
deleteNotificationById(notificationId) | ||
onRequestChanges() | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default Notification |
Oops, something went wrong.