Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman committed Aug 11, 2024
1 parent 32897ed commit 2e57c7f
Show file tree
Hide file tree
Showing 14 changed files with 167 additions and 193 deletions.
21 changes: 9 additions & 12 deletions frontend/src/Components/Header.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable functional/no-conditional-statements */
/* eslint-disable functional/no-expression-statements */
import { Button } from 'react-bootstrap';
import Container from 'react-bootstrap/Container';
import Navbar from 'react-bootstrap/Navbar';
Expand Down Expand Up @@ -32,27 +30,26 @@ const Header = () => {
const isMenuOpen = useSelector(selectMobileMenuState);

const handleLogout = () => {
dispatch(logout());
navigate('/login');
dispatch(logout()); /* eslint-disable-line */
navigate('/login'); /* eslint-disable-line */
};
const handleMenuClick = () => {
console.log('lol', isMenuOpen);
dispatch(toggleMenu());
dispatch(toggleMenu()); /* eslint-disable-line */
};
const goToGomePage = () => {
navigate('/');
navigate('/'); /* eslint-disable-line */
};

useEffect(() => {
useEffect(() => { /* eslint-disable-line */
const listener = (event) => {
if (isMenuOpen && !event.target.closest('#channelsHolder') && !event.target.closest('#burgerButton')) {
dispatch(toggleMenu());
if (isMenuOpen && !event.target.closest('#channelsHolder') && !event.target.closest('#burgerButton')) { /* eslint-disable-line */
dispatch(toggleMenu()); /* eslint-disable-line */
}
};

document.addEventListener('mousedown', listener);
document.addEventListener('mousedown', listener); /* eslint-disable-line */
return () => {
document.removeEventListener('mousedown', listener);
document.removeEventListener('mousedown', listener); /* eslint-disable-line */
};
}, [dispatch, isMenuOpen]);

Expand Down
14 changes: 6 additions & 8 deletions frontend/src/Components/LoginPage.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable functional/no-conditional-statements */
/* eslint-disable functional/no-expression-statements */
import React, { useState } from 'react';
import axios from 'axios';
import {
Expand All @@ -16,7 +14,7 @@ import MainContainer from './MainContainer';
const sendAuthRequest = async (dispatch, loginValues) => {
const res = await axios.post(routes.loginPath(), loginValues);
const { token, username } = res.data;
dispatch(login({ name: username, token }));
dispatch(login({ name: username, token })); /* eslint-disable-line */
};
const LoginPage = () => {
const { t } = useTranslation();
Expand All @@ -32,12 +30,12 @@ const LoginPage = () => {
},
onSubmit: async (values) => {
try {
await sendAuthRequest(dispatch, values);
navigate('/');
await sendAuthRequest(dispatch, values); /* eslint-disable-line */
navigate('/'); /* eslint-disable-line */
} catch (err) {
f.setSubmitting(false);
if (err.isAxiosError && err.response.status === 401) {
setError(t('internalLoginError'));
f.setSubmitting(false); /* eslint-disable-line */
if (err.isAxiosError && err.response.status === 401) { /* eslint-disable-line */
setError(t('internalLoginError')); /* eslint-disable-line */
} else {
throw err;
}
Expand Down
14 changes: 6 additions & 8 deletions frontend/src/Components/SignupPage.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable functional/no-conditional-statements */
/* eslint-disable functional/no-expression-statements */
import React, { useState } from 'react';
import axios from 'axios';
import {
Expand All @@ -17,7 +15,7 @@ import MainContainer from './MainContainer';
const sendAuthRequest = async (dispatch, loginValues) => {
const res = await axios.post(routes.signUpPath(), loginValues);
const { token, username } = res.data;
dispatch(login({ name: username, token }));
dispatch(login({ name: username, token })); /* eslint-disable-line */
};

const SignupPage = () => {
Expand Down Expand Up @@ -53,12 +51,12 @@ const SignupPage = () => {
validateOnBlur: true,
onSubmit: async (values) => {
try {
await sendAuthRequest(dispatch, values);
navigate('/');
await sendAuthRequest(dispatch, values); /* eslint-disable-line */
navigate('/'); /* eslint-disable-line */
} catch (err) {
f.setSubmitting(false);
if (err.isAxiosError && err.response.status === 409) {
setError(t('uniqueUsernameSignupError'));
f.setSubmitting(false); /* eslint-disable-line */
if (err.isAxiosError && err.response.status === 409) { /* eslint-disable-line */
setError(t('uniqueUsernameSignupError')); /* eslint-disable-line */
} else {
throw err;
}
Expand Down
76 changes: 36 additions & 40 deletions frontend/src/Components/mainPage/Channels.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-disable functional/no-let */
/* eslint-disable functional/no-conditional-statements */
/* eslint-disable functional/no-expression-statements */
/* eslint-disable no-unused-expressions */
/* eslint-disable no-param-reassign */
/* eslint-disable no-use-before-define */
Expand Down Expand Up @@ -66,12 +63,12 @@ const ChannelModal = ({

const f = useFormik({
onSubmit: (values) => {
setLoading(true);
setLoading(true); /* eslint-disable-line */
// eslint-disable-next-line no-unused-expressions
action.name === 'remove' ? action.handler(token) : action.handler(token, values.channelName);
handleCloseModal();
values.channelName = '';
setLoading(false);
action.name === 'remove' ? action.handler(token) : action.handler(token, values.channelName); /* eslint-disable-line */
handleCloseModal(); /* eslint-disable-line */
values.channelName = ''; /* eslint-disable-line */
setLoading(false); /* eslint-disable-line */
},
initialValues: {
channelName: '',
Expand All @@ -81,9 +78,9 @@ const ChannelModal = ({
validateOnBlur: false,
});

useEffect(() => {
setTimeout(() => {
modalRef.current ? modalRef.current.focus() : modalRef.current;
useEffect(() => { /* eslint-disable-line */
setTimeout(() => { /* eslint-disable-line */
modalRef.current ? modalRef.current.focus() : modalRef.current; /* eslint-disable-line */
}, 1);
}, []);

Expand Down Expand Up @@ -145,39 +142,38 @@ const Channels = ({ filter }) => {
const dispatch = useDispatch();

const handleOpenModal = (name, channelId) => {
let description;
let handler;
let description; /* eslint-disable-line */
let handler; /* eslint-disable-line */
switch (name) {
case 'rename':
description = t('channelRenameDescription');
handler = renameChannelHandler(channelId);
case 'rename': /* eslint-disable-line */
description = t('channelRenameDescription'); /* eslint-disable-line */
handler = renameChannelHandler(channelId); /* eslint-disable-line */
break;
case 'remove':
description = t('channelRemoveDescription');
handler = removeChannelHandler(channelId);
case 'remove': /* eslint-disable-line */
description = t('channelRemoveDescription'); /* eslint-disable-line */
handler = removeChannelHandler(channelId); /* eslint-disable-line */
break;
case 'create':
description = t('channelCreateDescription');
handler = createChannelHandler;
case 'create': /* eslint-disable-line */
description = t('channelCreateDescription'); /* eslint-disable-line */
handler = createChannelHandler; /* eslint-disable-line */
break;
}
setModalAction({
setModalAction({ /* eslint-disable-line */
name,
description,
handler,
});
setShowModal(true);
setShowModal(true); /* eslint-disable-line */
};

const handleCloseModal = () => {
setShowModal(false);
setModalAction(null);
setShowModal(false); /* eslint-disable-line */
setModalAction(null); /* eslint-disable-line */
};

const handleChangeChannel = (id) => () => {
dispatch(setCurrentChannelId(+id));
dispatch(toggleMenu());
console.log(id);
dispatch(setCurrentChannelId(+id)); /* eslint-disable-line */
dispatch(toggleMenu()); /* eslint-disable-line */
};

const channelList = channels.map((channel) => (
Expand All @@ -201,11 +197,11 @@ const Channels = ({ filter }) => {
Authorization: `Bearer ${token}`,
},
});
channelCreatedNotify();
dispatch(setCurrentChannelId(+res.data.id));
channelCreatedNotify(); /* eslint-disable-line */
dispatch(setCurrentChannelId(+res.data.id)); /* eslint-disable-line */
return res.data;
} catch (error) {
networkErrorNotify();
networkErrorNotify(); /* eslint-disable-line */
throw error;
}
};
Expand All @@ -217,34 +213,34 @@ const Channels = ({ filter }) => {
Authorization: `Bearer ${token}`,
},
});
channelRenamedNotify();
dispatch(setCurrentChannelId(+res.data.id));
channelRenamedNotify(); /* eslint-disable-line */
dispatch(setCurrentChannelId(+res.data.id)); /* eslint-disable-line */
return res.data;
} catch (error) {
networkErrorNotify();
networkErrorNotify(); /* eslint-disable-line */
throw error;
}
};

const removeChannelHandler = (channelId) => async (token) => {
try {
await axios.delete(routes.channelPath(channelId), {
await axios.delete(routes.channelPath(channelId), { /* eslint-disable-line */
headers: {
Authorization: `Bearer ${token}`,
},
});
const thisChannelMessagesIds = messages
.filter((m) => +m.channelId === +channelId).map((m) => m.id);
thisChannelMessagesIds.map(async (messageId) => {
await axios.delete(routes.messagePath(messageId), {
thisChannelMessagesIds.map(async (messageId) => { /* eslint-disable-line */
await axios.delete(routes.messagePath(messageId), { /* eslint-disable-line */
headers: {
Authorization: `Bearer ${token}`,
},
});
});
channelRemovedNotify();
channelRemovedNotify(); /* eslint-disable-line */
} catch (error) {
networkErrorNotify();
networkErrorNotify(); /* eslint-disable-line */
throw error;
}
};
Expand Down
30 changes: 14 additions & 16 deletions frontend/src/Components/mainPage/MainPage.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable functional/no-conditional-statements */
/* eslint-disable functional/no-expression-statements */
import { useEffect, useState } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { useNavigate } from 'react-router-dom';
Expand All @@ -21,7 +19,7 @@ const fetchChannels = async (token, dispatch) => {
Authorization: `Bearer ${token}`,
},
});
dispatch(setChannelsList(res.data));
dispatch(setChannelsList(res.data)); /* eslint-disable-line */
return res.data;
};

Expand All @@ -31,7 +29,7 @@ const fetchMessages = async (token, dispatch) => {
Authorization: `Bearer ${token}`,
},
});
dispatch(setMessages(res.data));
dispatch(setMessages(res.data)); /* eslint-disable-line */
return res.data;
};

Expand All @@ -41,23 +39,23 @@ const MainPage = () => {
const dispatch = useDispatch();
const navigate = useNavigate();
const filter = LeoProfanity;
filter.add(filter.getDictionary('en'));
filter.add(filter.getDictionary('ru'));
filter.add(filter.getDictionary('en')); /* eslint-disable-line */
filter.add(filter.getDictionary('ru')); /* eslint-disable-line */

useEffect(() => {
useEffect(() => { /* eslint-disable-line */
const loadPageData = async () => {
setLoading(true);
setLoading(true); /* eslint-disable-line */
const userString = localStorage.getItem('user');
if (!userString) {
navigate('login');
} else {
await fetchChannels(currentUser.token, dispatch);
await fetchMessages(currentUser.token, dispatch);
subscribeToSocketEvents();
setLoading(false);
if (!userString) { /* eslint-disable-line */
navigate('login'); /* eslint-disable-line */
} else { /* eslint-disable-line */
await fetchChannels(currentUser.token, dispatch); /* eslint-disable-line */
await fetchMessages(currentUser.token, dispatch); /* eslint-disable-line */
subscribeToSocketEvents(); /* eslint-disable-line */
setLoading(false); /* eslint-disable-line */
}
};
loadPageData();
loadPageData(); /* eslint-disable-line */
}, [currentUser, dispatch, navigate]);

return (
Expand Down
19 changes: 9 additions & 10 deletions frontend/src/Components/mainPage/Message.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable functional/no-expression-statements */
import React, { useState } from 'react';
import { Form, Modal, Button } from 'react-bootstrap';
import { BsPencilFill, BsTrash2Fill } from 'react-icons/bs';
Expand Down Expand Up @@ -32,8 +31,8 @@ const MessageRemoveModal = ({
removeMessageHandler, showModal, handleCloseModal, t, token,
}) => {
const handleSubmit = async () => {
removeMessageHandler(token);
handleCloseModal();
removeMessageHandler(token); /* eslint-disable-line */
handleCloseModal(); /* eslint-disable-line */
};

return (
Expand Down Expand Up @@ -75,7 +74,7 @@ const Message = ({
const networkErrorNotify = () => toast.error(t('networkError'));

const handleCloseModal = () => {
setShowModal(false);
setShowModal(false); /* eslint-disable-line */
};

const editMessageHandler = async (messageId, token, messageBody) => {
Expand All @@ -85,10 +84,10 @@ const Message = ({
Authorization: `Bearer ${token}`,
},
});
messageEditedNotify();
messageEditedNotify(); /* eslint-disable-line */
return res.data;
} catch (error) {
networkErrorNotify();
networkErrorNotify(); /* eslint-disable-line */
throw error;
}
};
Expand All @@ -100,18 +99,18 @@ const Message = ({
Authorization: `Bearer ${token}`,
},
});
messageRemovedNotify();
messageRemovedNotify(); /* eslint-disable-line */
return res.data;
} catch (error) {
networkErrorNotify();
networkErrorNotify(); /* eslint-disable-line */
throw error;
}
};

const f = useFormik({
onSubmit: (values) => {
editMessageHandler(id, currentUser.token, values.editedMessage);
setIsEditing(false);
editMessageHandler(id, currentUser.token, values.editedMessage); /* eslint-disable-line */
setIsEditing(false); /* eslint-disable-line */
},
initialValues: {
editedMessage: body,
Expand Down
Loading

0 comments on commit 2e57c7f

Please sign in to comment.