diff --git a/frontend/eslint.config.js b/frontend/eslint.config.js
index 4ed310b..73fb307 100644
--- a/frontend/eslint.config.js
+++ b/frontend/eslint.config.js
@@ -15,6 +15,7 @@ export default [
pluginReact.configs.flat.recommended,
{rules:
{semi: "error",
- 'react/react-in-jsx-scope': 'off'},
+ 'react/react-in-jsx-scope': 'off',
+ 'react/prop-types': 'off'},
},
];
diff --git a/frontend/src/components/AddModal.jsx b/frontend/src/components/AddModal.jsx
new file mode 100644
index 0000000..7ecaa08
--- /dev/null
+++ b/frontend/src/components/AddModal.jsx
@@ -0,0 +1,71 @@
+import { useEffect, useRef } from 'react';
+import { useFormik } from 'formik';
+import { Modal, FormGroup, FormControl, Button, Form } from 'react-bootstrap';
+import { useSelector, useDispatch } from 'react-redux';
+import { useTranslation } from 'react-i18next';
+import { useAddChannelMutation } from '../api/chatApi';
+import { selectActiveTab } from '../slices/activeChannelSlice.js';
+
+const AddChannel = ({ onHide }) => {
+ const { t } = useTranslation();
+ const dispatch = useDispatch();
+ const [ addChannel ] = useAddChannelMutation();
+ const modals = useSelector((state) => state.modals);
+ const formControlEl = useRef(null);
+
+ const formik = useFormik({
+ initialValues: {
+ channelName: '',
+ },
+ onSubmit: async (values, ) => {
+ try {
+ const response = await addChannel({name: values.channelName});
+ dispatch(selectActiveTab(response.data));
+ onHide();
+ console.log(modals)
+ } catch (error) {
+ console.log(error);
+ }
+ formik.resetForm();
+ }
+ });
+
+ useEffect(() => {
+ formControlEl.current.focus();
+ }, []);
+
+return (
+ <>
+
+
+
+
+ {t('modal.addButton')}
+
+
+
+
+
+
+ >
+
+ );
+};
+
+export default AddChannel;
\ No newline at end of file
diff --git a/frontend/src/components/ChannelAddButtom.jsx.jsx b/frontend/src/components/ChannelAddButtom.jsx.jsx
index e3ff9ee..a2bb900 100644
--- a/frontend/src/components/ChannelAddButtom.jsx.jsx
+++ b/frontend/src/components/ChannelAddButtom.jsx.jsx
@@ -1,14 +1,11 @@
import { Button } from 'react-bootstrap';
-const ButtonPlus = ({ showModal }) => {
-
- return (
- <>
+const ButtonPlus = ({ showModal, channel }) => (
- >
-
-
);
-};
export default ButtonPlus;
\ No newline at end of file
diff --git a/frontend/src/components/MessageForm.jsx b/frontend/src/components/MessageForm.jsx
index e56d0d1..7d24243 100644
--- a/frontend/src/components/MessageForm.jsx
+++ b/frontend/src/components/MessageForm.jsx
@@ -13,7 +13,6 @@ const MessageForm = ({ activeChannelId, username, addMessage }) => {
onSubmit: async (values, { setFieldValue }) => {
try {
const newMessege = { body: values.body, channelId: activeChannelId, username };
- // console.log(newMessege)
await addMessage(newMessege);
setFieldValue('body', newMessege.body);
formik.resetForm();
diff --git a/frontend/src/components/Modal.jsx b/frontend/src/components/Modal.jsx
deleted file mode 100644
index 2fd6c29..0000000
--- a/frontend/src/components/Modal.jsx
+++ /dev/null
@@ -1,56 +0,0 @@
-import { useEffect, useRef } from 'react';
-import { useFormik } from 'formik';
-import { Modal, FormGroup, FormControl, Button, Form } from 'react-bootstrap';
-import { useSelector } from 'react-redux';
-
-const Component = ({ onHide, show }) => {
- const modals = useSelector((state) => state.modals);
- const formControlEl = useRef(null);
- const formik = useFormik({
- initialValues: {
- taskName: '',
- },
- onSubmit: (values) => {
- modals.type = 'addChannel';
- modals.channel = values.taskName;
- console.log(modals);
- formik.resetForm();
- }
- });
-
- useEffect(() => {
- if (formControlEl.current) {
- formControlEl.current.focus();
- }
- }, []);
-
-return (
-
-
- Add
-
-
-
-
-
- );
-};
-
-export default Component;
\ No newline at end of file
diff --git a/frontend/src/components/RemoveModel.jsx b/frontend/src/components/RemoveModel.jsx
new file mode 100644
index 0000000..3a48fdd
--- /dev/null
+++ b/frontend/src/components/RemoveModel.jsx
@@ -0,0 +1,29 @@
+import { Modal, Button } from 'react-bootstrap';
+import { useTranslation } from 'react-i18next';
+
+const RemoveChannel = ({ onHide }) => {
+ const { t } = useTranslation();
+
+return (
+ <>
+
+
+
+
+ {t('modal.removeChannel')}
+
+
+ {t('modal.removeText')}
+
+
+
+
+
+
+
+ >
+
+ );
+};
+
+export default RemoveChannel;
\ No newline at end of file
diff --git "a/frontend/src/components/\320\241hannels.jsx" "b/frontend/src/components/\320\241hannels.jsx"
index 1761bf7..a9f64e3 100644
--- "a/frontend/src/components/\320\241hannels.jsx"
+++ "b/frontend/src/components/\320\241hannels.jsx"
@@ -1,50 +1,75 @@
-import { Nav, Button } from 'react-bootstrap';
+import { Nav, Button, Dropdown } from 'react-bootstrap';
import { useGetChannelsQuery } from '../api/chatApi.js';
import { useRef } from 'react';
import { useSelector, useDispatch } from 'react-redux';
+import { useTranslation } from 'react-i18next';
import { selectActiveTab, activeChannelSelector } from '../slices/activeChannelSlice.js';
-import { openModal, closeModal } from '../slices/modalsSlice';
-import Component from './Modal';
+import ButtonPlus from './ChannelAddButtom.jsx.jsx';
+import AddChannel from './AddModal.jsx';
+import RemoveChannel from './RemoveModel.jsx';
+import { closeModal, openModal } from '../slices/modalsSlice';
const Channels = () => {
+ const { t } = useTranslation();
const dispatch = useDispatch();
const channelsRef = useRef(null);
-
- const { data: channels = [], refetch } = useGetChannelsQuery();
+
+ const { data: channels = [] } = useGetChannelsQuery();
const activeChannel = useSelector(activeChannelSelector);
- const modals = useSelector((state) => state.modals);
+ const modals = useSelector((state) => state.modals);
- const hideModal = () => dispatch(closeModal());
-
- // const showModal = () => {
- // dispatch(openModal({ type: 'addChannel'}));
- // };
+ const variant = (channel) => channel.id === activeChannel.id ? "secondary" : "";
+ const hideModal = () => dispatch(closeModal());
+ const showModal = (type, channel) => {
+ dispatch(openModal({ type, channel }));
+ };
return (
-
+ <>
+
+
{t('channels.title')}
+
+ {modals.type === 'adding' && ()}
+
+
+ >
);
};
diff --git a/frontend/src/context/AuthProvider.jsx b/frontend/src/context/AuthProvider.jsx
index b291d02..160f71f 100644
--- a/frontend/src/context/AuthProvider.jsx
+++ b/frontend/src/context/AuthProvider.jsx
@@ -3,7 +3,6 @@ import { Navigate } from 'react-router-dom';
import AuthContext from '../context/index.jsx';
import useAuth from '../hooks/index.jsx';
-// eslint-disable-next-line react/prop-types
const AuthProvider = ({ children }) => {
const [loggedIn, setLoggedIn] = useState(!!localStorage.getItem('token'));
@@ -36,7 +35,6 @@ const AuthProvider = ({ children }) => {
);
};
-// eslint-disable-next-line react/prop-types
export const PrivateRoute = ({ children }) => {
const { loggedIn } = useAuth();
diff --git a/frontend/src/init.jsx b/frontend/src/init.jsx
index ed94266..f6cefb9 100644
--- a/frontend/src/init.jsx
+++ b/frontend/src/init.jsx
@@ -42,7 +42,11 @@ const init = async () => {
draft.push({ payload });
}));
});
-
+ socket.on('newChannel', (payload) => {
+ store.dispatch(chatApi.util.updateQueryData('getChannels', undefined, (draft) => {
+ draft.push({ payload });
+ }));
+ });
// socket.on('renameMessage', (payload) => {
// })
diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.js
index 7eb0412..0bff69d 100644
--- a/frontend/src/locales/ru.js
+++ b/frontend/src/locales/ru.js
@@ -1,3 +1,4 @@
+import { Dropdown } from "react-bootstrap";
import Channels from "../components/Сhannels";
export default {
@@ -16,6 +17,18 @@ export default {
},
channels: {
title: 'Каналы',
+ setupChannel: 'Управление каналом',
+ dropdownButtonRemove: 'Удалить',
+ dropdownButtonRename: 'Переименовать',
+ },
+ modal: {
+ name: 'Имя канала',
+ addButton: 'Добавить канал',
+ cancel: 'Отменить',
+ send: 'Отправить',
+ removeChannel: 'Удалить канал',
+ removeText: 'Уверены?',
+ removeButton: 'Удалить',
},
countMessages: {
messages_one: '{{count}} сообщение',
diff --git a/frontend/src/pages/MainPage.jsx b/frontend/src/pages/MainPage.jsx
index 808ed96..a14cb4d 100644
--- a/frontend/src/pages/MainPage.jsx
+++ b/frontend/src/pages/MainPage.jsx
@@ -1,37 +1,26 @@
import { Container, Row, Col, Spinner } from 'react-bootstrap';
import { useTranslation } from 'react-i18next';
-import { useDispatch } from 'react-redux';
import { useGetChannelsQuery } from '../api/chatApi.js';
import Channels from '../components/Сhannels.jsx';
-import ButtonPlus from '../components/ChannelAddButtom.jsx.jsx';
import MessageField from '../components/MessageField.jsx';
-import { openModal } from '../slices/modalsSlice';
-
const MainPage = () => {
const { t } = useTranslation();
- const dispatch = useDispatch();
const { isLoading: isChannelsLoading, error: channelsError } = useGetChannelsQuery();
- const showModal = () => {
- dispatch(openModal({ type: 'addChannel'}));
- };
+
return (
+ {isChannelsLoading && (
+
+ {t('isChannelsLoading')}
+
+ )}
+ {channelsError && (
+ console.log(error.message)
+ )}
-
- {t('channels.title')}
-
-
- {isChannelsLoading && (
-
- {t('isChannelsLoading')}
-
- )}
- {channelsError && (
- console.log(error.message)
- )}
diff --git a/frontend/src/slices/modalsSlice.js b/frontend/src/slices/modalsSlice.js
index 52c3947..11a1681 100644
--- a/frontend/src/slices/modalsSlice.js
+++ b/frontend/src/slices/modalsSlice.js
@@ -20,6 +20,5 @@ const modalsSlice = createSlice({
},
});
-// export const activeChannelSelector = (state) => state.activeChannel.currentChannel;
export const { openModal, closeModal } = modalsSlice.actions;
export default modalsSlice.reducer;
\ No newline at end of file