Skip to content

Commit

Permalink
Add anonymous to Puzzle Modal
Browse files Browse the repository at this point in the history
  • Loading branch information
heyrict committed Aug 18, 2018
1 parent 393cca2 commit 713d300
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 14 deletions.
9 changes: 7 additions & 2 deletions react-boilerplate/app/components/PuzzlePanel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* PuzzlePanel
*
*/
/* eslint-disable indent */

import React from 'react';
import PropTypes from 'prop-types';
Expand Down Expand Up @@ -45,7 +46,11 @@ export class PuzzlePanel extends React.Component {
<RoundedPanel my={10}>
<Row mx={10} py={10}>
<UserCol w={[1 / 4, 1 / 6]} px={10}>
<UserLabel user={node.user} break />
<UserLabel
user={node.user}
anonymous={node.anonymous && node.status === 0}
break
/>
{this.props.additional}
</UserCol>
<Box w={[3 / 4, 5 / 6]} px={10}>
Expand Down Expand Up @@ -97,7 +102,7 @@ export class PuzzlePanel extends React.Component {
PuzzlePanel.propTypes = {
node: PropTypes.object.isRequired,
additional: PropTypes.any,
locale: PropTypes.string.isRequired,
locale: PropTypes.string,
};

PuzzlePanel.defaultProps = {
Expand Down
24 changes: 22 additions & 2 deletions react-boilerplate/app/components/UserLabel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ import PropTypes from 'prop-types';
import styled from 'styled-components';
import { connect } from 'react-redux';
import { pushWithLocale, from_global_id as f } from 'common';
import { ImgXs } from 'style-store';
import { ImgXs, ImgMd } from 'style-store';
import { Tooltip } from 'react-tippy';
import { FormattedMessage } from 'react-intl';

import { openDirectChat } from 'containers/Chat/actions';
import UserAwardPopover from 'components/UserAwardPopover';
import chat from 'images/chat.svg';
import home from 'images/home.svg';
import anonymousIcon from 'images/anonymous.png';

import messages from './messages';

const Linked = styled.button`
padding: 3px;
Expand All @@ -25,8 +29,22 @@ const Linked = styled.button`
}
`;

const IconMd = ImgMd.extend`
border: 1px solid #333;
border-radius: 9999px;
`;

function UserLabel(props) {
const { user, break: needBreak, color } = props;
const { user, anonymous, break: needBreak, color } = props;
if (anonymous) {
return (
<span>
<IconMd alt="anonymous" src={anonymousIcon} />
<br />
<FormattedMessage {...messages.anonymous} />
</span>
);
}
const popoverDetail = (
<div>
<button
Expand Down Expand Up @@ -74,6 +92,7 @@ UserLabel.propTypes = {
nickname: PropTypes.string.isRequired,
currentAward: PropTypes.object,
}),
anonymous: PropTypes.bool,
break: PropTypes.bool,
openDirectChat: PropTypes.func.isRequired,
goto: PropTypes.func.isRequired,
Expand All @@ -83,6 +102,7 @@ UserLabel.propTypes = {

UserLabel.defaultProps = {
color: '#23527c',
// anonymous: false,
};

const mapDispatchToProps = (dispatch) => ({
Expand Down
8 changes: 8 additions & 0 deletions react-boilerplate/app/components/UserLabel/messages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineMessages } from 'react-intl';

export default defineMessages({
anonymous: {
id: 'components.UserLabel.anonymous',
defaultMessage: 'Anonymous',
},
});
30 changes: 24 additions & 6 deletions react-boilerplate/app/containers/PuzzleAddForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class PuzzleAddForm extends React.Component {
puzzleTitle: '',
puzzleGenre: 0,
puzzleYami: 0,
puzzleAnonymous: false,
loading: false,
};

Expand All @@ -47,20 +48,28 @@ export class PuzzleAddForm extends React.Component {
// }}}
// {{{ handleChange
handleChange(e) {
const target = e.target;
const { target } = e;
if (target.id === 'formPuzzleAddTitle') {
this.setState({ puzzleTitle: target.value });
} else if (target.id === 'formPuzzleAddGenre') {
this.setState({ puzzleGenre: target.value });
} else if (target.id === 'formPuzzleAddYami') {
this.setState({ puzzleYami: target.value });
} else if (target.id === 'formPuzzleAddAnonymous') {
this.setState({ puzzleAnonymous: target.value });
}
}
// }}}
// {{{ handleSubmit
handleSubmit(e) {
e.preventDefault();
const { loading, puzzleTitle, puzzleGenre, puzzleYami } = this.state;
const {
loading,
puzzleTitle,
puzzleGenre,
puzzleYami,
puzzleAnonymous,
} = this.state;
const puzzleContent =
this.contentTextarea && this.contentTextarea.getContent();
const puzzleSolution =
Expand All @@ -76,6 +85,7 @@ export class PuzzleAddForm extends React.Component {
puzzleYami,
puzzleContent,
puzzleSolution,
puzzleAnonymous,
},
},
})
Expand Down Expand Up @@ -184,6 +194,14 @@ export class PuzzleAddForm extends React.Component {
</Select>
}
/>
<FieldGroup
id="formPuzzleAddAnonymous"
label={<FormattedMessage {...messages.anonymousLabel} />}
Ctl={Input}
type="checkbox"
value={this.state.puzzleAnonymous}
onChange={this.handleChange}
/>
<FieldGroup
id="formPuzzleAddContent"
label={
Expand Down Expand Up @@ -250,7 +268,7 @@ PuzzleAddForm.propTypes = {
const mapStateToProps = createStructuredSelector({
currentUserId: createSelector(
makeSelectUserNavbar(),
(usernav) => usernav.user && usernav.user.userId
(usernav) => usernav.user && usernav.user.userId,
),
});

Expand All @@ -261,7 +279,7 @@ const mapDispatchToProps = (dispatch) => ({

const withConnect = connect(
mapStateToProps,
mapDispatchToProps
mapDispatchToProps,
);

const withMutation = graphql(PuzzleAddFormMutation);
Expand All @@ -286,11 +304,11 @@ const withCurrentUser = graphql(
const { user: currentUser } = data;
return { currentUser };
},
}
},
);

export default compose(
withConnect,
withCurrentUser,
withMutation
withMutation,
)(PuzzleAddForm);
4 changes: 4 additions & 0 deletions react-boilerplate/app/containers/PuzzleAddForm/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ export default defineMessages({
id: 'app.containers.PuzzleAddForm.submitLabel',
defaultMessage: 'Submit',
},
anonymousLabel: {
id: 'app.containers.PuzzleAddForm.anonymousLabel',
defaultMessage: 'Anonymous',
},
});
24 changes: 22 additions & 2 deletions react-boilerplate/app/containers/PuzzleShowPage/Frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { text2md } from 'common';
import { FormattedMessage } from 'react-intl';
import styled from 'styled-components';
import { Box } from 'rebass';
import { PuzzleFrame } from 'style-store';
import { ImgSm, PuzzleFrame } from 'style-store';

import Constrained from 'components/Constrained';
import UserLabel from 'components/UserLabel';
import anonymousIcon from 'images/anonymous.png';

import userLabelMessages from 'components/UserLabel/messages';
import messages from './messages';

const Label = styled.span`
Expand All @@ -28,6 +30,12 @@ const ContentBox = styled(Box)`
font-family: 'Dejavu Sans';
`;

const IconSm = ImgSm.extend`
border: 1px solid #333;
border-radius: 9999px;
margin: 5px;
`;

function Frame(props) {
return (
<Constrained mt={2} mb={2}>
Expand All @@ -37,7 +45,18 @@ function Frame(props) {
dangerouslySetInnerHTML={{ __html: text2md(props.text, props.safe) }}
/>
<br />
{props.user ? (
{props.anonymous && (
<FormattedMessage {...messages.creator}>
{(c) => (
<RightBox>
<Label>{c}:</Label>
<IconSm alt="anonymous" src={anonymousIcon} />
<FormattedMessage {...userLabelMessages.anonymous} />
</RightBox>
)}
</FormattedMessage>
)}
{props.user && !props.anonymous ? (
<FormattedMessage {...messages.creator}>
{(c) => (
<RightBox>
Expand Down Expand Up @@ -76,6 +95,7 @@ function Frame(props) {

Frame.propTypes = {
text: PropTypes.string.isRequired,
anonymous: PropTypes.bool,
user: PropTypes.object,
created: PropTypes.string,
solved: PropTypes.string,
Expand Down
1 change: 1 addition & 0 deletions react-boilerplate/app/containers/PuzzleShowPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ export class PuzzleShowPage extends React.Component {
{(P.status <= 2 || P.user.id === U) && (
<Frame
user={P.user}
anonymous={P.anonymous && P.status === 0}
text={P.content}
created={P.created}
safe={P.contentSafe}
Expand Down
1 change: 1 addition & 0 deletions react-boilerplate/app/graphql/PuzzleActiveList.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const PuzzleActiveList = gql`
title
status
created
anonymous
quesCount
uaquesCount
user {
Expand Down
1 change: 1 addition & 0 deletions react-boilerplate/app/graphql/PuzzlePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const PuzzlePanel = gql`
title
status
created
anonymous
quesCount
uaquesCount
starSet {
Expand Down
1 change: 1 addition & 0 deletions react-boilerplate/app/graphql/PuzzleShow.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const PuzzleShow = gql`
yami
genre
status
anonymous
user {
...UserLabel_user
}
Expand Down
Binary file added react-boilerplate/app/images/anonymous.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion react-boilerplate/app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
"app.containers.ProfilePage.starStaticsCount": "Star Count",
"app.containers.ProfilePage.title": "User Profile",
"app.containers.ProfilePage.trueQuesCount": "True Answer Count",
"app.containers.PuzzleAddForm.anonymousLabel": "Anonymous",
"app.containers.PuzzleAddForm.contentLabel": "Content",
"app.containers.PuzzleAddForm.genreLabel": "Genre",
"app.containers.PuzzleAddForm.solutionLabel": "Solution",
Expand Down Expand Up @@ -233,5 +234,6 @@
"app.containers.UserNavbar.userlist": "User List",
"app.containers.WikiPage.title": "Wiki",
"app.containers.withModel.close": "Close",
"app.containers.withModel.confirm": "Confirm"
"app.containers.withModel.confirm": "Confirm",
"components.UserLabel.anonymous": "Anonymous"
}
4 changes: 3 additions & 1 deletion react-boilerplate/app/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
"app.containers.ProfilePage.starStaticsCount": "スター投票数",
"app.containers.ProfilePage.title": "ユーザープロフィール",
"app.containers.ProfilePage.trueQuesCount": "正解数",
"app.containers.PuzzleAddForm.anonymousLabel": "匿名",
"app.containers.PuzzleAddForm.contentLabel": "問題文",
"app.containers.PuzzleAddForm.genreLabel": "ジャンル",
"app.containers.PuzzleAddForm.solutionLabel": "解説文",
Expand Down Expand Up @@ -233,5 +234,6 @@
"app.containers.UserNavbar.userlist": "ユーザー一覧",
"app.containers.WikiPage.title": "Wiki",
"app.containers.withModel.close": "閉じる",
"app.containers.withModel.confirm": "確認"
"app.containers.withModel.confirm": "確認",
"components.UserLabel.anonymous": "謎の料理人"
}
1 change: 1 addition & 0 deletions sui_hei/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class Puzzle(models.Model):
modified = models.DateTimeField(_('modified'))
status = models.IntegerField(_('status'), default=0)
memo = models.TextField(_('memo'), blank=True)
anonymous = models.BooleanField(_('anonymous'), default=False)

class Meta:
verbose_name = _("Puzzle")
Expand Down
3 changes: 3 additions & 0 deletions sui_hei/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ class Input:
puzzleYami = graphene.Int(required=True)
puzzleContent = graphene.String(required=True)
puzzleSolution = graphene.String(required=True)
puzzleAnonymous = graphene.Boolean(required=True)

@classmethod
def mutate_and_get_payload(cls, root, info, **input):
Expand All @@ -647,6 +648,7 @@ def mutate_and_get_payload(cls, root, info, **input):
yami = input["puzzleYami"]
content = input["puzzleContent"]
solution = input["puzzleSolution"]
anonymous = input["puzzleAnonymous"]

if not title:
raise ValidationError(_("Title cannot be empty!"))
Expand All @@ -666,6 +668,7 @@ def mutate_and_get_payload(cls, root, info, **input):
content_safe=user.credit > MIN_CONTENT_SAFE_CREDIT,
solution=solution,
created=created,
anonymous=anonymous,
modified=created)

# Delete messages in puzzle-[id] channel
Expand Down

0 comments on commit 713d300

Please sign in to comment.