-
Notifications
You must be signed in to change notification settings - Fork 5
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
fb52547
commit 8b018cc
Showing
11 changed files
with
355 additions
and
52 deletions.
There are no files selected for viewing
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
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,44 @@ | ||
import React, { useState } from 'react' | ||
import { connect } from 'react-redux' | ||
import { removeTab } from '../../store/tabs' | ||
|
||
import { Link } from 'react-router-dom' | ||
|
||
const Tabs = ({ tabs, removeTab }) => { | ||
if (tabs.length) { | ||
const [active, setActive] = useState(tabs[0].id) | ||
|
||
return ( | ||
<nav className='tabs'> | ||
{tabs.map(tab => { | ||
const handleClick = e => { | ||
window.scrollTo(0, 0) | ||
return setActive(tab.id) | ||
} | ||
|
||
const handleRemove = e => { | ||
e.preventDefault() | ||
return removeTab(tab.id) | ||
} | ||
const isActive = active === tab.id | ||
|
||
return ( | ||
<div key={tab.id} className={['tab-link', isActive && 'tab-link-active'].filter(Boolean).join(' ')}> | ||
<Link | ||
to={tab.path} | ||
onClick={handleClick} | ||
> | ||
{tab.name} | ||
</Link> | ||
<button className='remove-tab-link' onClick={handleRemove}>Remove tab</button> | ||
</div> | ||
) | ||
})} | ||
</nav> | ||
) | ||
} | ||
|
||
return null | ||
} | ||
|
||
export default connect(null, { removeTab })(Tabs) |
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,34 @@ | ||
import uuid from 'uuid/v4' | ||
|
||
export const addTab = (name, path) => dispatch => | ||
dispatch({ | ||
type: 'TABS/ADD', | ||
payload: { name, path } | ||
}) | ||
|
||
export const removeTab = id => dispatch => | ||
dispatch({ | ||
type: 'TABS/REMOVE', | ||
payload: { id } | ||
}) | ||
|
||
export default (state = [], action) => { | ||
switch (action.type) { | ||
case 'TABS/ADD': { | ||
const { name, path } = action.payload | ||
|
||
return [ | ||
...state, | ||
{ name, path, id: uuid() } | ||
] | ||
} | ||
|
||
case 'TABS/REMOVE': { | ||
const { id } = action.payload | ||
return state.filter(tab => tab.id !== id) | ||
} | ||
|
||
default: | ||
return state | ||
} | ||
} |
Oops, something went wrong.