Skip to content

Commit

Permalink
Always show the Add new tab button
Browse files Browse the repository at this point in the history
  • Loading branch information
dave-elkan committed Jul 7, 2021
1 parent 0bc1b49 commit b017d9c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,32 @@ import Button from '@material-ui/core/Button';
import Grid from '@material-ui/core/Grid';
import { addTab, TabSansId } from '../../store/tabsSlice';
import { useDispatch } from 'react-redux';
import { makeStyles } from '@material-ui/core/styles';

const initialTab: TabSansId = {
url: '',
};

const AddInitialTabButton = () => {
const useStyles = makeStyles((theme) => ({
addTabButton: {
margin: theme.spacing(4),
},
}));

const AddTabButton = () => {
const dispatch = useDispatch();
const classes = useStyles();
return (
<Grid container justify="center">
<Grid className={classes.addTabButton} container justify="center">
<Button
variant="contained"
color="primary"
onClick={() => dispatch(addTab(initialTab))}
>
Add Tab
Add new tab
</Button>
</Grid>
);
};

export default AddInitialTabButton;
export default AddTabButton;
5 changes: 5 additions & 0 deletions src/pages/Page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import React from 'react';
import Container from '@material-ui/core/Container';
import { makeStyles } from '@material-ui/core/styles';
import AddTabButton from '../components/form/AddTabButton';

const useStyles = makeStyles((theme) => ({
root: {
padding: theme.spacing(3),
},
addTabButton: {
margin: theme.spacing(4),
},
}));

const Page = ({
Expand All @@ -23,6 +27,7 @@ const Page = ({
<h1>{title}</h1>
<h4>{description}</h4>
{children}
<AddTabButton />
</Container>
);
};
Expand Down
4 changes: 0 additions & 4 deletions src/pages/advanced/AdvancedTabList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@ import Box from '@material-ui/core/Box';
import { Tab } from '../../types';
import AdvancedTabForm from './AdvancedTabForm';
import { TabsStateType } from '../../store/tabsSlice';
import AddInitialTabButton from '../../components/form/AddInitialTabButton';

type PropsType = {
tabs: TabsStateType;
};

const TabList = ({ tabs }: PropsType) => {
const tabsArray = Object.values(tabs);
if (!tabsArray.length) {
return <AddInitialTabButton />;
}

return (
<>
Expand Down

0 comments on commit b017d9c

Please sign in to comment.