-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
Showing
2 changed files
with
76 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,56 @@ | ||
import { IonItem } from "@ionic/react"; | ||
import { Post } from "@mattermost/types/posts"; | ||
import { User } from "../../api/types"; | ||
import { useMemo } from "react"; | ||
|
||
interface Props { | ||
post: Post; | ||
isMe: boolean; | ||
users: User[]; | ||
prevPost: Post | null; | ||
} | ||
|
||
export default function ChatPost({ post, isMe }: Props) { | ||
export default function ChatPost({ post, isMe, users, prevPost }: Props) { | ||
const { username, message } = useMemo(() => { | ||
let username = post.props.username; | ||
let message = post.message; | ||
for (let user of users) { | ||
if (user.uid === post.props.username) { | ||
username = user.name; | ||
} | ||
message = message.replaceAll(user.uid, user.name); | ||
} | ||
return { username, message }; | ||
}, [users, post]); | ||
|
||
const isSameUserAsPrev = post.user_id === prevPost?.user_id; | ||
|
||
return ( | ||
<IonItem | ||
lines="none" | ||
color="light" | ||
className={`tw-shrink-0 tw-rounded-tl-2xl tw-rounded-tr-2xl ${ | ||
post.is_following ? "" : "tw-mb-2" | ||
} ${ | ||
isMe | ||
? "tw-rounded-bl-2xl tw-float-right tw-ml-8 tw-mr-4" | ||
: "tw-rounded-br-2xl tw-mr-8 tw-ml-4 tw-float-left" | ||
}`} | ||
> | ||
<div className="tw-py-2"> | ||
<div className="tw-font-bold">{post.props.username}</div> | ||
<div>{post.message}</div> | ||
</div> | ||
</IonItem> | ||
<> | ||
{!isSameUserAsPrev ? ( | ||
<div className="tw-sticky tw-top-0 tw-font-bold tw-text-center tw-bg-[#ffffffa0]"> | ||
{username} | ||
</div> | ||
) : null} | ||
{post.type != "" ? ( | ||
<div className="tw-flex tw-justify-center"> | ||
<div className="tw-rounded tw-bg-light tw-max-w-xs tw-text-center tw-p-1 tw-my-2"> | ||
{message} | ||
</div> | ||
</div> | ||
) : ( | ||
<div className={` tw-shrink-0 ${post.is_following ? "" : "tw-mb-2"} `}> | ||
<div | ||
className={`tw-rounded-tl-2xl tw-rounded-tr-2xl tw-bg-light tw-p-2 ${ | ||
isMe | ||
? "tw-rounded-bl-2xl tw-float-right tw-ml-8 tw-mr-4" | ||
: "tw-rounded-br-2xl tw-mr-8 tw-ml-4 tw-float-left" | ||
}`} | ||
> | ||
{message} | ||
</div> | ||
</div> | ||
)} | ||
</> | ||
); | ||
} |
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