Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement notifications handling #25

Merged
merged 69 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
068b8ba
feat: Implement ´DirectMessageModal´ component
criss8X Mar 20, 2024
807f575
feat: Abstract logic into ´useUserSearch´ and ´useInvitationLink´ hooks
criss8X Mar 21, 2024
936c15a
feat: Implement ´DirectChatRecent´ component
criss8X Mar 21, 2024
d2760c4
feat: Implement ´DirectMessageModal´ for SidebarActions
criss8X Mar 21, 2024
bd926fa
fix: Resolve comments of the PR
criss8X Mar 21, 2024
6531016
feat: Implement `useDebounced` hook
criss8X Mar 22, 2024
9f737fa
feat: More use `useCallback` for `useSidebarActions`
criss8X Mar 22, 2024
c693252
refactor: Convert `SidebarActions` as smart component
criss8X Mar 23, 2024
f38455e
refactor: Improve `Modal` component for use `createPortal`
criss8X Mar 23, 2024
21fd6e4
Merge branch 'dev' into handle-sidebar-actions
criss8X Mar 23, 2024
299a79f
refactor: More use `Modal` component
criss8X Mar 23, 2024
207ee5b
refactor: Improve modals handling for `SidebarActions` component
criss8X Mar 23, 2024
1592310
feat: Implement `NotificationsModal` and `Notification` components
criss8X Mar 23, 2024
9b384bd
fix: Fix visual problems for `Modal`
criss8X Mar 23, 2024
83043cf
refactor: Resolve PR comments about tailwindcss class
criss8X Mar 23, 2024
795372b
refactor: Remove redundant tailwindcss class
criss8X Mar 23, 2024
74cc8c3
feat: Implement `useNotification` hook
criss8X Mar 24, 2024
d4e1b66
refactor: Resolve PR comments.
criss8X Mar 24, 2024
ad36140
refactor: Fix TailwindCss class problems
criss8X Mar 24, 2024
058e07d
feat: Implement notifications handling for `useNotifications` hook
criss8X Mar 25, 2024
53316ce
feat: Implement `useSidebarModalActiveStore`
criss8X Mar 25, 2024
b6b5380
fix: Fix visual problems for components.
criss8X Mar 25, 2024
953f26a
fix: Fix storybook stories problems
criss8X Mar 26, 2024
51752ff
feat: Upgrade `Typography` component
criss8X Mar 26, 2024
bf0da79
feat: Upgrade `UserProfile` component
criss8X Mar 26, 2024
b429002
refactor: Refactor storybook stories
criss8X Mar 26, 2024
887aa81
feat: Implement `useChatInput` for `ChatContainer` component
criss8X Mar 26, 2024
4d25b3e
fix: Fix visual problem for `TextMessage`
criss8X Mar 26, 2024
abd0dda
feat: Implement `useCachedNotifications` hook
criss8X Mar 27, 2024
23f797a
Merge branch 'dev' into cristian/handle-notifications
criss8X Mar 28, 2024
8bda6ac
Merge branch 'master' into cristian/upgrade-components
criss8X Mar 28, 2024
0cc522b
Merge branch 'dev' into cristian/upgrade-components
criss8X Mar 28, 2024
e2c74a4
Merge 'upgrade-components' and handle-notification
criss8X Mar 28, 2024
27b52b9
Merge with cristian/upgrade-components
criss8X Mar 28, 2024
7f83c3b
Merge branch 'dev' into handle-notifications
criss8X Mar 30, 2024
e18f8b0
refactor: Remove footer for `Readme.md`
criss8X Mar 30, 2024
8dbc6f5
fix: Fix `pre-commit` problems
criss8X Mar 30, 2024
1a9e2a5
feat: Implement events handling for notifications
criss8X Mar 30, 2024
24792a8
feat: Improve notifications handling
criss8X Mar 30, 2024
0553f60
fix: Test eslint actions
criss8X Mar 30, 2024
651a8fe
Revert "fix: Test eslint actions"
criss8X Mar 30, 2024
6abb737
Merge branch 'dev' into handle-notifications
criss8X Mar 31, 2024
a39e4b4
feat: Implement room member events for notifications
criss8X Mar 31, 2024
fd0cc54
feat: Implement mention for notification
criss8X Mar 31, 2024
1abd0a8
feat: Upgrade `saveNotification` for `useCachedNotifications`
criss8X Mar 31, 2024
c6c3877
fix: Improve code for `NotificationsModal`
criss8X Mar 31, 2024
54df432
feat: Implement power levels event for notifications
criss8X Mar 31, 2024
4906d16
feat: Implement deploy-pages for deployment
criss8X Apr 1, 2024
4eef530
refactor: Upgrade deploy-pages
criss8X Apr 1, 2024
4d8d081
feat: Implement deploy from dev for github actions
criss8X Apr 1, 2024
ca3b6e6
fix: Resolve PR comments
criss8X Apr 1, 2024
c2c3590
feat: Implement delete notification action
criss8X Apr 2, 2024
ab1375e
feat: Implement mark as read for notifications
criss8X Apr 2, 2024
291ec11
feat: Implement `markAsReadAllNotifications` function for `useCachedN…
criss8X Apr 2, 2024
5ee925c
feat: Implement `useNotificationsStateStore`
criss8X Apr 2, 2024
82ef5d2
fix: Fix PR comments
criss8X Apr 2, 2024
32f30f5
feat: Implement handling directs room for notifications
criss8X Apr 3, 2024
93665d1
fix: Fix PR problems
criss8X Apr 3, 2024
970f606
feat: Upgrade local notifications handling
criss8X Apr 3, 2024
f4147a0
feat: Implement other type of notification handling
criss8X Apr 5, 2024
4205f72
feat: Upgrade new notification handling
criss8X Apr 5, 2024
d3d23f4
feat: Upgrade `power levels` event for notifications
criss8X Apr 6, 2024
ec397a9
feat: Upgrade members event for notifications
criss8X Apr 6, 2024
b702ef1
refactor: Fix PR comments
criss8X Apr 6, 2024
2bbbeae
fix: Upgrade `saveNotification` function
criss8X Apr 6, 2024
528df73
fix: Resolve PR comments
criss8X Apr 6, 2024
d936fd5
fix: Use key for lists
criss8X Apr 6, 2024
596bd5a
refactor: Use yarn for `pre-commit`
criss8X Apr 6, 2024
a21aae8
fix: Fix prettier problems
criss8X Apr 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
]
},
"extends": [
"eslint:recommended",
"plugin:react/jsx-runtime",
"standard-with-typescript",
"eslint-config-prettier",
"plugin:storybook/recommended",
Expand Down Expand Up @@ -82,6 +84,7 @@
],
"promise/always-return": "off",
"unicorn/number-literal-case": "off",
"unicorn/prefer-spread": "off"
"unicorn/prefer-spread": "off",
"react/jsx-key": "error"
}
}
26 changes: 26 additions & 0 deletions .github/workflows/deploy-push-master.yml
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
4 changes: 2 additions & 2 deletions .husky/pre-commit
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
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,3 @@ npm run dev
- [Storybook.js](https://storybook.js.org/): Isolated component development environment

<hr />
<div align="center">
<i>
Please feel free to reach out to me on <a href="https://www.linkedin.com/in/yurixander/">LinkedIn</a> for business inquiries.<br />
Images generated with DALL·E 3, and edited with Figma.<br />
&copy; 2023 Yurixander Ricardo<br /><br />
<img alt="Thumbs up illustration" src="./github/thumbs-up.png" />
</i>
</div>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-no-use-extend-native": "^0.5.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-react": "^7.34.0",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-regexp": "^2.3.0",
"eslint-plugin-sonarjs": "^0.24.0",
Expand Down
2 changes: 1 addition & 1 deletion src/components/ContextMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import type React from "react"
import {useCallback, useEffect, type FC} from "react"
import {create} from "zustand"

Expand Down
4 changes: 3 additions & 1 deletion src/components/IconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type IconButtonProps = {
onClick: () => void
tooltip: string
Icon: IconType
size?: number
color?: string
isDisabled?: boolean
isDotVisible?: boolean
Expand All @@ -19,6 +20,7 @@ const IconButton: FC<IconButtonProps> = ({
color,
isDisabled,
isDotVisible,
size,
className,
}) => {
const isDisabledClass = isDisabled
Expand All @@ -38,7 +40,7 @@ const IconButton: FC<IconButtonProps> = ({
className
)}>
<NotificationDot isVisible={isDotVisible ?? false}>
<Icon style={{color}} size={20} className="text-neutral-300" />
<Icon style={{color}} size={size ?? 20} className="text-neutral-300" />
</NotificationDot>
</div>
)
Expand Down
3 changes: 2 additions & 1 deletion src/components/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {useState, type FC} from "react"
import type React from "react"
import {useState, type FC} from "react"
import IconButton from "./IconButton"
import Label from "./Label"
import {twMerge} from "tailwind-merge"
Expand Down
3 changes: 2 additions & 1 deletion src/components/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {assert} from "@/utils/util"
import React, {type FC} from "react"
import type React from "react"
import {type FC} from "react"
import {createPortal} from "react-dom"
import {twMerge} from "tailwind-merge"

Expand Down
6 changes: 3 additions & 3 deletions src/components/RosterUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import UserProfile, {
} from "./UserProfile"

export enum UserPowerLevel {
Admin,
Moderator,
Member,
Admin = 100,
Moderator = 50,
Member = 0,
}

export type RosterUserProps = {
Expand Down
10 changes: 6 additions & 4 deletions src/components/SidebarActions/DirectMessageModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,13 @@ const DirectMessageModal: FC = () => {

<div className="flex h-full flex-col gap-1 overflow-y-scroll scrollbar-hide">
{results === null
? directChats.map(directChatProps => (
<DirectChatRecent {...directChatProps} />
? directChats.map((directChatProps, index) => (
<DirectChatRecent key={index} {...directChatProps} />
))
: results.map(userProps => (
<div className="w-full cursor-pointer rounded-lg p-2 hover:bg-neutral-200">
: results.map((userProps, index) => (
<div
key={index}
className="w-full cursor-pointer rounded-lg p-2 hover:bg-neutral-200">
<UserProfile {...userProps} />
</div>
))}
Expand Down
151 changes: 151 additions & 0 deletions src/components/SidebarActions/Notification.tsx
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
Loading
Loading