generated from goitacademy/react-homework-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fbfc0cf
commit 97ccb90
Showing
14 changed files
with
176 additions
and
62 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Header, Navigation, NavItem, StyledLink } from './AppBar.styled'; | ||
|
||
export const AppBar = () => { | ||
return ( | ||
<Header> | ||
<Navigation> | ||
<NavItem> | ||
<StyledLink to="/">Home</StyledLink> | ||
</NavItem> | ||
<NavItem> | ||
<StyledLink to="register">Register</StyledLink> | ||
</NavItem> | ||
<NavItem> | ||
<StyledLink to="login">Log In</StyledLink> | ||
</NavItem> | ||
<NavItem> | ||
<StyledLink to="contacts">Contacts</StyledLink> | ||
</NavItem> | ||
</Navigation> | ||
</Header> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import styled from '@emotion/styled'; | ||
import { NavLink } from 'react-router-dom'; | ||
|
||
export const Header = styled.header` | ||
margin-bottom: 20px; | ||
`; | ||
|
||
export const Navigation = styled.ul` | ||
display: flex; | ||
gap: 50px; | ||
`; | ||
|
||
export const NavItem = styled.li``; | ||
|
||
export const StyledLink = styled(NavLink)` | ||
font-size: 20px; | ||
color: #000000; | ||
background-color: #78a1bb; | ||
padding: 8px; | ||
border-radius: 4px; | ||
&.active { | ||
color: #000000; | ||
background-color: #e9af3d; | ||
padding: 8px; | ||
border-radius: 4px; | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useSelector } from 'react-redux'; | ||
import { | ||
selectUser, | ||
selectIsLoggedIn, | ||
selectIsRefreshing, | ||
} from '../redux/auth/selectors'; | ||
|
||
export const useAuth = () => { | ||
const isLoggedIn = useSelector(selectIsLoggedIn); | ||
const isRefreshing = useSelector(selectIsRefreshing); | ||
const user = useSelector(selectUser); | ||
|
||
return { | ||
isLoggedIn, | ||
isRefreshing, | ||
user, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import App from 'components/App'; | ||
import './index.css'; | ||
|
||
import { BrowserRouter } from 'react-router-dom'; | ||
// import { Provider } from 'react-redux'; | ||
// import { store } from './redux/store'; | ||
import { PersistGate } from 'redux-persist/integration/react'; | ||
import { Provider } from 'react-redux'; | ||
import { store, persistor } from './redux/store'; | ||
import './index.css'; | ||
|
||
ReactDOM.createRoot(document.getElementById('root')).render( | ||
<React.StrictMode> | ||
{/* <Provider store={store}> */} | ||
<BrowserRouter basename="/goit-react-hw-08-phonebook"> | ||
<App /> | ||
</BrowserRouter> | ||
{/* </Provider> */} | ||
<Provider store={store}> | ||
<PersistGate loading={null} persistor={persistor}> | ||
<BrowserRouter basename="/goit-react-hw-08-phonebook"> | ||
<App /> | ||
</BrowserRouter> | ||
</PersistGate> | ||
</Provider> | ||
</React.StrictMode> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
|
||
const contactsSlice = createSlice({ | ||
name: 'contacts', | ||
initialState: { contacts: [] }, | ||
reducers: { | ||
deleteContactAction: (state, action) => { | ||
state.contacts = state.contacts.filter(el => el.id !== action.payload); | ||
}, | ||
addContactAction: (state, action) => { | ||
state.contacts = [...state.contacts, action.payload]; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { addContactAction, deleteContactAction } = contactsSlice.actions; | ||
|
||
export const contactsReducer = contactsSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
|
||
const filterSlice = createSlice({ | ||
name: 'filter', | ||
initialState: { | ||
filter: '', | ||
}, | ||
reducers: { | ||
setSearchFilterAction(state, action) { | ||
return { ...state, filter: `${action.payload}` }; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { setSearchFilterAction } = filterSlice.actions; | ||
|
||
export const filterReducer = filterSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { persistReducer } from 'redux-persist'; | ||
import storage from 'redux-persist/lib/storage'; | ||
|
||
import { contactsReducer } from './contactsSlice'; | ||
import { filterReducer } from './filterSlice'; | ||
|
||
const persistConfig = { | ||
key: 'root', | ||
storage, | ||
}; | ||
|
||
const persistedReducer = persistReducer(persistConfig, contactsReducer); | ||
|
||
export const reducer = { | ||
contacts: persistedReducer, | ||
filter: filterReducer, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const getContacts = state => state.contacts.contacts; | ||
export const getFilterValue = state => state.filter.filter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { configureStore } from '@reduxjs/toolkit'; | ||
import { reducer } from './reducer'; | ||
import { | ||
persistStore, | ||
FLUSH, | ||
REHYDRATE, | ||
PAUSE, | ||
PERSIST, | ||
PURGE, | ||
REGISTER, | ||
} from 'redux-persist'; | ||
|
||
export const store = configureStore({ | ||
reducer, | ||
middleware: getDefaultMiddleware => | ||
getDefaultMiddleware({ | ||
serializableCheck: { | ||
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER], | ||
}, | ||
}), | ||
}); | ||
export const persistor = persistStore(store); |