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

Lesson 8 #15

Open
wants to merge 3 commits into
base: lesson-7
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
32 changes: 20 additions & 12 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = {
env: {
AndreyOsipuk marked this conversation as resolved.
Show resolved Hide resolved
browser: true,
node: true,
es6: true,
jest: true,
node: true,
},
extends: [
'prettier',
Expand All @@ -16,6 +16,14 @@ module.exports = {
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
overrides: [
{
files: ['webpack.config.js'],
rules: {
'@typescript-eslint/no-var-requires': ['off'],
},
},
],
parserOptions: {
ecmaFeatures: {
jsx: true,
Expand All @@ -25,24 +33,24 @@ module.exports = {
},
plugins: ['react', 'prettier', 'react-hooks', 'jest'],
rules: {
'react/display-name': 'off',
'linebreak-style': ['error', 'unix'],
'prettier/prettier': [
'error',
{
singleQuote: true,
},
],
'react/prop-types': 0,
'linebreak-style': ['error', 'unix'],
quotes: ['warn', 'single'],
'react/display-name': 'off',
'react/prop-types': 0,
semi: ['warn', 'always'],
},
overrides: [
{
files: ['webpack.config.js'],
rules: {
'@typescript-eslint/no-var-requires': ['off'],
'sort-imports': [
'error',
AndreyOsipuk marked this conversation as resolved.
Show resolved Hide resolved
{
allowSeparatedGroups: true,
memberSyntaxSortOrder: ['all', 'single', 'multiple', 'none'],
},
},
],
],
'sort-keys': ['error'],
},
};
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Web site created using create-react-app" />
<base href="/">

<title>React App</title>
</head>
Expand Down
4 changes: 2 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { FC, useState } from 'react';
import { Provider } from 'react-redux';
import { PersistGate } from 'redux-persist/integration/react';
import { Provider } from 'react-redux';
import React, { FC, useState } from 'react';

import { AppRouter } from './components/AppRouter';
import { ThemeContext, defaultContext } from './utils/ThemeContext';
Expand Down
174 changes: 174 additions & 0 deletions src/assets/svg/gun.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 29 additions & 9 deletions src/components/AppRouter.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import React, { FC, Suspense } from 'react';
import { BrowserRouter, Route, Routes } from 'react-router-dom';
import React, { FC, Suspense } from 'react';

import { AboutWithConnect } from 'src/pages/About';
// import { Chats } from 'src/pages/Chats/Chats';
import { Articles } from 'src/pages/Articles';
import { Chats } from 'src/pages/Chats/Chats';
import { Home } from 'src/pages/Home';
import { Profile } from 'src/pages/Profile';
import { SignIn } from 'src/pages/SignIn';
import { SignUp } from 'src/pages/SignUp';

import { ChatList } from './ChatList';
import { Header } from './Header';
import { PrivateRoute } from './PrivateRoute';
import { PublicRoute } from './PublicRoute';

const Chats = React.lazy(() =>
import('src/pages/Chats/Chats').then((module) => ({
default: module.Chats,
}))
// import { Profile } from 'src/pages/Profile';

const Profile = React.lazy(() =>
Promise.all([
import('src/pages/Profile').then(({ Profile }) => ({
default: Profile,
})),
new Promise((resolve) => setTimeout(resolve, 1000)),
]).then(([moduleExports]) => moduleExports)
);

export const AppRouter: FC = () => (
Expand All @@ -20,14 +30,24 @@ export const AppRouter: FC = () => (
<Routes>
<Route path="/" element={<Header />}>
<Route index element={<Home />} />
<Route path="profile" element={<Profile />} />
<Route
path="profile"
element={<PrivateRoute component={<Profile />} />}
/>

<Route path="chats">
<Route path="chats" element={<PrivateRoute />}>
<Route index element={<ChatList />} />
<Route path=":chatId" element={<Chats />} />
</Route>

<Route path="about" element={<AboutWithConnect />} />
<Route path="articles" element={<Articles />} />

<Route
path="signin"
element={<PublicRoute component={<SignIn />} />}
/>
<Route path="signup" element={<SignUp />} />
</Route>

<Route path="*" element={<h2>404</h2>} />
Expand Down
11 changes: 7 additions & 4 deletions src/components/ChatList.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { FC, useState } from 'react';
import { Link } from 'react-router-dom';
import { ListItem } from '@mui/material';
import React, { FC, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { addChat, deleteChat } from 'src/store/chats/actions';

import { selectChatList } from 'src/store/chats/selectors';
import { addChat, deleteChat } from 'src/store/chats/slice';

export const ChatList: FC = () => {
const [name, setName] = useState('');
Expand All @@ -19,7 +20,7 @@ export const ChatList: FC = () => {
e.preventDefault();

if (name) {
dispatch(addChat(name));
dispatch(addChat({ name }));
setName('');
}
};
Expand All @@ -30,7 +31,9 @@ export const ChatList: FC = () => {
{chatList.map((chat) => (
<ListItem key={chat.id}>
<Link to={`/chats/${chat.name}`}>{chat.name}</Link>
<button onClick={() => dispatch(deleteChat(chat.name))}>x</button>
<button onClick={() => dispatch(deleteChat({ chatId: chat.name }))}>
x
</button>
</ListItem>
))}
</ul>
Expand Down
Loading