-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move context into a separate folder, add PageContext * utilized exported useAdmin and usePage * Move all components into separate folder * lint * Revert "Move all components into separate folder" This reverts commit f1027f0. * Move Contexts to root
- Loading branch information
Showing
25 changed files
with
609 additions
and
629 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
import { Avatar } from "@material-ui/core"; | ||
import { AdminContext } from "django-bananas"; | ||
import { useAdmin } from "django-bananas"; | ||
import gravatar from "gravatar"; | ||
import React from "react"; | ||
|
||
const Gravatar = ({ props }) => ( | ||
<AdminContext.Consumer> | ||
{context => { | ||
const url = gravatar.url(context.user.email); | ||
return <Avatar src={url} {...props} />; | ||
}} | ||
</AdminContext.Consumer> | ||
); | ||
const Gravatar = ({ props }) => { | ||
const { user } = useAdmin(); | ||
const url = gravatar.url(user.email); | ||
|
||
return <Avatar src={url} {...props} />; | ||
}; | ||
|
||
export default Gravatar; |
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,9 @@ | ||
import { TitleBar, usePage } from "django-bananas"; | ||
import React from "react"; | ||
|
||
const GenericTitleBar = props => { | ||
const { title } = usePage(); | ||
return <TitleBar title={title} back={".."} {...props} />; | ||
}; | ||
|
||
export default GenericTitleBar; |
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 |
---|---|---|
@@ -1,79 +1,66 @@ | ||
import { Button } from "@material-ui/core"; | ||
import { withStyles } from "@material-ui/core/styles"; | ||
import { | ||
AdminContext, | ||
Content, | ||
TitleBar, | ||
ToolBar, | ||
Tools, | ||
} from "django-bananas"; | ||
import { createStyles, makeStyles } from "@material-ui/core/styles"; | ||
import { Content, TitleBar, ToolBar, Tools } from "django-bananas"; | ||
import { AutoField, Form } from "django-bananas/forms"; | ||
import PropTypes from "prop-types"; | ||
import React from "react"; | ||
|
||
const styles = theme => ({ | ||
paper: { | ||
margin: theme.spacing(2), | ||
padding: theme.spacing(2), | ||
}, | ||
formRoot: { | ||
display: "flex", | ||
flexDirection: "column", | ||
flexGrow: 1, | ||
width: "100%", | ||
height: "100%", | ||
backgroundColor: theme.palette.background.paper, | ||
}, | ||
}); | ||
const useStyles = makeStyles( | ||
createStyles(theme => ({ | ||
paper: { | ||
margin: theme.spacing(2), | ||
padding: theme.spacing(2), | ||
}, | ||
formRoot: { | ||
display: "flex", | ||
flexDirection: "column", | ||
flexGrow: 1, | ||
width: "100%", | ||
height: "100%", | ||
backgroundColor: theme.palette.background.paper, | ||
}, | ||
})) | ||
); | ||
|
||
class UserForm extends React.Component { | ||
static contextType = AdminContext; | ||
|
||
render() { | ||
const { | ||
classes, | ||
data: { obj: data }, | ||
} = this.props; | ||
|
||
return ( | ||
<Form | ||
initialValues={data} | ||
route="example.user:form.create" | ||
formProps={{ className: classes.formRoot }} | ||
> | ||
<TitleBar title="Form" back=".." /> | ||
<Content> | ||
<AutoField name="text" /> | ||
<br /> | ||
<AutoField name="date" /> | ||
<br /> | ||
<AutoField name="datetime" /> | ||
<br /> | ||
<AutoField name="boolean" variant="checkbox" /> | ||
<br /> | ||
<AutoField name="boolean" variant="switch" /> | ||
<br /> | ||
<AutoField name="integer" /> | ||
<br /> | ||
<AutoField name="choices" /> | ||
<br /> | ||
<AutoField name="multiple_choices" /> | ||
</Content> | ||
<ToolBar color="paper" justify="end"> | ||
<Tools> | ||
<Button type="submit" variant="contained" color="primary"> | ||
Save | ||
</Button> | ||
</Tools> | ||
</ToolBar> | ||
</Form> | ||
); | ||
} | ||
} | ||
const UserForm = ({ data: { obj: data } }) => { | ||
const classes = useStyles(); | ||
return ( | ||
<Form | ||
initialValues={data} | ||
route="example.user:form.create" | ||
formProps={{ className: classes.formRoot }} | ||
> | ||
<TitleBar title="Form" back=".." /> | ||
<Content> | ||
<AutoField name="text" /> | ||
<br /> | ||
<AutoField name="date" /> | ||
<br /> | ||
<AutoField name="datetime" /> | ||
<br /> | ||
<AutoField name="boolean" variant="checkbox" /> | ||
<br /> | ||
<AutoField name="boolean" variant="switch" /> | ||
<br /> | ||
<AutoField name="integer" /> | ||
<br /> | ||
<AutoField name="choices" /> | ||
<br /> | ||
<AutoField name="multiple_choices" /> | ||
</Content> | ||
<ToolBar color="paper" justify="end"> | ||
<Tools> | ||
<Button type="submit" variant="contained" color="primary"> | ||
Save | ||
</Button> | ||
</Tools> | ||
</ToolBar> | ||
</Form> | ||
); | ||
}; | ||
|
||
UserForm.propTypes = { | ||
classes: PropTypes.object.isRequired, | ||
data: PropTypes.object.isRequired, | ||
}; | ||
|
||
export default withStyles(styles)(UserForm); | ||
export default UserForm; |
Oops, something went wrong.