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

fix: #1494 Port AdminButton from gatsby to next.js #1515

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions src/frontend/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"start": "next start"
},
"dependencies": {
"@material-ui/core": "^4.11.2",
"@material-ui/icons": "^4.11.2",
"next": "^10.0.2",
"react": "^16.13.1",
"react-dom": "^16.13.1"
Expand Down
40 changes: 40 additions & 0 deletions src/frontend/next/src/components/AdminButtons/AdminButtons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { useContext } from 'react';
import { makeStyles } from '@material-ui/core/styles';
import { IconButton } from '@material-ui/core';
import FlagIcon from '@material-ui/icons/Flag';
import DeleteIcon from '@material-ui/icons/Delete';
import { UserStateContext } from '../../contexts/User/UserContext';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once #1521 lands (hopefully soon), we can change this to:

import { useUser } from '../UserProvider';


const useStyles = makeStyles(() => ({
iconDiv: {
float: 'right',
},
iconSpan: {
paddingLeft: '10px',
paddingRight: '10px',
},
}));

function AdminButtons() {
const classes = useStyles();
const user = useContext(UserStateContext);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can become:

const user = useUser();


return (
user.isAdmin && (
<div className={classes.iconDiv}>
<span className={classes.iconSpan}>
<IconButton size="small">
<FlagIcon fontSize="large" />
</IconButton>
</span>
<span className={classes.iconSpan}>
<IconButton size="small">
<DeleteIcon fontSize="large" />
</IconButton>
</span>
</div>
)
);
}

export default AdminButtons;
4 changes: 4 additions & 0 deletions src/frontend/next/src/contexts/User/UserContext/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createContext } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this file.


export const UserStateContext = createContext();
export const UserDispatchContext = createContext();