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

Эмодзи (клиентская часть) #34

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions packages/client/src/pages/ForumItemPage/ForumItemPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { forums as previeForums } from '../Forum/components/forumPreviewTable/st
import { TForum, TMessage, messageFormFileds } from './model'
import ForumMessagesList from './components/forumMessagesList/forumMessagesList'
import AddMessageFrame from './components/addMessageFrame/addMessageFrame'
import { useTypedSelector } from '../../redux/store'
import { getUserData } from '../../redux/selectors'

const ForumPage = () => {
const { id } = useParams()
Expand All @@ -18,7 +20,7 @@ const ForumPage = () => {
if (!forum) return <Navigate to="*" />
const { theme, messages }: TForum = forum
const [forumMessages, updateForum] = useState(messages)

const user = useTypedSelector(getUserData)
const callbacks = {
onAddMessage: useCallback(
(e: FormEvent) => {
Expand All @@ -32,7 +34,7 @@ const ForumPage = () => {
const newMesage: TMessage = {
messageId: uuid(),
message,
author: 'Admin',
author: user.login ? user.login : 'Author',
time: new Date(),
}
forum.messages.push(newMesage)
Expand All @@ -52,6 +54,7 @@ const ForumPage = () => {
<AddMessageFrame
inputName={messageFormFileds.message}
onAddMessage={callbacks.onAddMessage}
name={user.login}
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import './styles.scss'
type TAddMessageFrameProps = {
inputName: string
onAddMessage: (e: FormEvent) => void
name: string
}

const AddMessageFrame = ({
inputName,
onAddMessage,
name = 'Admin',
}: TAddMessageFrameProps) => {
const cn = bem('addMessageFrame')

return (
<div className={cn()}>
<div>Admin</div>
<div>{name}</div>
<form onSubmit={onAddMessage} className={cn('form')}>
<label htmlFor={inputName} className={cn('label')}>
<textarea
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { memo } from 'react'
import { memo, useState } from 'react'
import { TMessage } from '../../model'

import bem from 'bem-ts'
import './styles.scss'
import { forums } from '../../../Forum/components/forumPreviewTable/stubs'

const emoji = ['😀', '🤑', '😭', '💩', '❤', '👍']
const ForumMessagesList = ({ messages }: { messages: TMessage[] }) => {
const [selectedEmoji, setSelectedEmoji] = useState('')

const handleEmojiSelect = (emoji: string) => {
setSelectedEmoji(emoji)
}
const cn = bem('forumMessages')
const getTime = (time: Date) => {
return (
Expand All @@ -29,7 +34,26 @@ const ForumMessagesList = ({ messages }: { messages: TMessage[] }) => {
<span>{author}</span>
<span>{getTime(time)}</span>
</div>
{selectedEmoji}
<p>{message}</p>
<div
style={{
display: 'flex',
}}>
{emoji.map(item => (
<div>
<button
key={item}
style={{
width: '30px',
height: '30px',
}}
onClick={() => handleEmojiSelect(`${item}`)}>
{item}
</button>
</div>
))}
</div>
</li>
))}
</ul>
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/pages/Main/MainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const MainPage = () => {
<MainButton to={'start'} text={'Начать игру'} />
<MainButton to={'board'} text={'Таблица лидеров'} />
<MainButton to={'profile'} text={'Профиль'} />
<MainButton to={'forum'} text={'Форум'} />
<Typography
variant={'h2'}
component={'h2'}
Expand Down