Skip to content

Commit b4433f7

Browse files
committed
add styles to ChatPage
1 parent 1685016 commit b4433f7

File tree

1 file changed

+128
-20
lines changed

1 file changed

+128
-20
lines changed

frontend/src/Components/ChatPage.jsx

Lines changed: 128 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
1+
import { useState, useEffect } from 'react';
2+
3+
import cn from 'classnames';
4+
import { useFormik } from 'formik';
15
import axios from 'axios';
2-
import { useEffect } from 'react';
6+
import {
7+
Button,
8+
Container,
9+
Col,
10+
ListGroup,
11+
Row,
12+
Form,
13+
InputGroup,
14+
} from 'react-bootstrap';
315
import { useNavigate } from 'react-router-dom';
416
import { useDispatch, useSelector } from 'react-redux';
517

618
import { setChannels, setMessages } from '../features/chat/chatSlice';
719

8-
function ChatPage() {
20+
const ChatPage = () => {
921
const dispatch = useDispatch();
1022
const navigate = useNavigate();
1123
const { channels, messages } = useSelector((state) => state.chat);
24+
const [selected, setSelected] = useState('general');
25+
26+
const formik = useFormik({
27+
initialValues: {
28+
text: '',
29+
},
30+
onSubmit: async (/* values */) => {
31+
// some logic
32+
},
33+
});
1234

1335
useEffect(() => {
1436
const authToken = localStorage.getItem('token');
@@ -44,25 +66,111 @@ function ChatPage() {
4466
}, [dispatch, navigate]);
4567

4668
return (
47-
<div>
48-
<h1>Стили будут завтра ;)</h1>
49-
<h2>Каналы:</h2>
50-
<ul>
51-
{channels.map((channel) => (
52-
<li key={channel.id}>{channel.name}</li>
53-
))}
54-
</ul>
55-
56-
<h2>Сообщения:</h2>
57-
<ul>
58-
{messages.map((message) => (
59-
<li key={message.id}>
60-
{message.username}: {message.body}
61-
</li>
62-
))}
63-
</ul>
69+
<div className="d-flex flex-column h-100">
70+
<Container className="h-100 overflow-hidden my-4 rounded shadow">
71+
<Row className="h-100 bg-white flex-md-row">
72+
<Col
73+
sm={4}
74+
md={2}
75+
className="border-end px-0 bg-light flex-column h-100 d-flex"
76+
>
77+
<div className="d-flex mt-1 justify-content-between mb-2 ps-4 pe-2 p-4">
78+
<b>Каналы</b>
79+
<Button
80+
type="button"
81+
variant="text-primary"
82+
className="p-0 btn-group-vertical"
83+
>
84+
<svg
85+
xmlns="http://www.w3.org/2000/svg"
86+
viewBox="0 0 16 16"
87+
width="20"
88+
height="20"
89+
fill="currentColor"
90+
>
91+
<path d="M14 1a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1zM2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2z"></path>
92+
<path d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4"></path>
93+
</svg>
94+
<span className="visually-hidden">+</span>
95+
</Button>
96+
</div>
97+
<ListGroup
98+
id="channels-box"
99+
className="nav flex-column nav-pills nav-fill px-2 mb-3 overflow-auto h-100 d-block"
100+
>
101+
{channels.map((channel) => (
102+
<ListGroup.Item key={channel.id} className="nav-item v-100">
103+
<Button
104+
onClick={() =>
105+
setSelected((prev) =>
106+
prev !== `${channel.name}` ? `${channel.name}` : prev
107+
)
108+
}
109+
className={cn(
110+
'w-100',
111+
'rounded-0',
112+
'text-start',
113+
'btn-secondary',
114+
{ active: selected === channel.name }
115+
)}
116+
>
117+
<span className="me-1">#</span>
118+
{channel.name}
119+
</Button>
120+
</ListGroup.Item>
121+
))}
122+
</ListGroup>
123+
</Col>
124+
<Col className="p-0 h-100">
125+
<div className="d-flex flex-column h-100">
126+
<div className="bg-light mb-4 p-3 shadow-sm small">
127+
<p className="m-0">
128+
<b># {selected}</b>
129+
</p>
130+
<span className="text-muted">{messages.length} сообщений</span>
131+
</div>
132+
<div
133+
id="messages-box"
134+
className="chat-messages overflow-auto px-5"
135+
></div>
136+
<div className="mt-auto px-5 py-3">
137+
<Form noValidate className="py-1 border rounded-2">
138+
<InputGroup className="has-validation">
139+
<Form.Control
140+
name="body"
141+
placeholder="Введите сообщение..."
142+
aria-label="Новое сообщение"
143+
className="border-0 p-0 ps-2 "
144+
{...formik.getFieldProps('text')}
145+
></Form.Control>
146+
<Button
147+
type="submit"
148+
variant="outline"
149+
className="btn btn-group-vertical"
150+
>
151+
<svg
152+
xmlns="http://www.w3.org/2000/svg"
153+
viewBox="0 0 16 16"
154+
width="20"
155+
height="20"
156+
fill="currentColor"
157+
>
158+
<path
159+
fillRule="evenodd"
160+
d="M15 2a1 1 0 0 0-1-1H2a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1zM0 2a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2zm4.5 5.5a.5.5 0 0 0 0 1h5.793l-2.147 2.146a.5.5 0 0 0 .708.708l3-3a.5.5 0 0 0 0-.708l-3-3a.5.5 0 1 0-.708.708L10.293 7.5z"
161+
></path>
162+
</svg>
163+
<span className="visually-hidden">Отправить</span>
164+
</Button>
165+
</InputGroup>
166+
</Form>
167+
</div>
168+
</div>
169+
</Col>
170+
</Row>
171+
</Container>
64172
</div>
65173
);
66-
}
174+
};
67175

68176
export default ChatPage;

0 commit comments

Comments
 (0)