         newState[field] = value
         @setState(newState)
 
+    render: () ->
+        admin = @props.me?.admin
+        <div>
+            <Submit submit={@props.currentSubmit} showHeader me={@props.me} copyTest={@copyTest}/>
+            {(not @props.currentSubmit.similar) && <div>
+                <div>
+                    {
+                    if @props.currentSubmit.outcome in ["OK", "AC"]
+                        starsClass = styles.stars
+                    else
+                        starsClass = ""
+                    <div className={starsClass}>
+                        <FontAwesome name="times" key={0} onClick={@setQuality(0)}/>
+                        {(<FontAwesome
+                            name={"star" + (if x <= @props.currentSubmit.quality then "" else "-o")}
+                            key={x}
+                            onClick={@setQuality(x)}/> \
+                            for x in [1..5])}
+                    </div>
+                    }
+                </div>
+                {
+                if @props.bestSubmits.length
+                    <span>
+                        <a href="#" onClick={@toggleBestSubmits}>Хорошие решения</a>
+                        {" = " + @props.bestSubmits.length}
+                        {" " + @props.bestSubmits.map((submit) -> submit.language || "unknown").join(", ")}
+                    </span>
+                }
+                <FieldGroup
+                        id="commentText"
+                        label="Комментарий"
+                        componentClass="textarea"
+                        setField={@setField}
+                        style={{ height: 200 }}
+                        state={@state}/>
+                <FormGroup>
+                    {
+                    bsSize = null
+                    bsCommentSize = null
+                    if not (@props.currentSubmit.outcome in ["OK", "AC", "IG"])
+                        bsSize = "xsmall"
+                    if not @props.result?.activated
+                        bsSize = "xsmall"
+                        bsCommentSize = "xsmall"
+                    <ButtonGroup>
+                        <Button onClick={@accept} bsStyle="success" bsSize={bsSize}>Зачесть</Button>
+                        <Button onClick={@ignore} bsStyle="info" bsSize={bsSize}>Проигнорировать</Button>
+                        <Button onClick={@comment}  bsSize={bsCommentSize}>Прокомментировать</Button>
+                        <Button onClick={@disqualify} bsStyle="danger" bsSize="xsmall">Дисквалифицировать</Button>
+                    </ButtonGroup>
+                    }
+                </FormGroup>
+                <Button onClick={@downloadSubmits} bsSize="xsmall">re-download submits</Button>
+                {
+                admin and @props.currentSubmit and not @props.currentSubmit.similar and <Col xs={12} sm={12} md={12} lg={12}>
+                    <ConnectedProblemCommentsLists problemId={@props.result.fullTable._id} handleCommentClicked={@setComment}/>
+                </Col>
+                }
+                {
+                admin && @state.bestSubmits && <BestSubmits submits={@props.bestSubmits} close={@toggleBestSubmits} stars/>
+                }
+            </div>}
+        </div>
+
+export class SubmitListWithDiff extends React.Component
+    constructor: (props) ->
+        super(props)
+        @state =
+            currentSubmit: if @props.submits then @props.submits[@props.submits.length - 1] else null
+            currentDiff: [undefined, undefined]
+        @setCurrentSubmit = @setCurrentSubmit.bind this
+        @setCurrentDiff = @setCurrentDiff.bind this
+
+    componentDidUpdate: (prevProps, prevState) ->
+        changed = false
+        if prevProps.submits.length != @props.submits.length
+            changed = true
+        else
+            for s, i in prevProps.submits
+                if s._id != @props.submits[i]._id
+                    changed = true
+        if changed
+            @setState
+                currentSubmit: if @props.submits then @props.submits[@props.submits.length - 1] else null
+                currentDiff: [undefined, undefined]
+        else
+            newState =
+                currentSubmit: null
+                currentDiff: @state.currentDiff
+            for submit in @props.submits
+                if submit._id == @state.currentSubmit?._id
+                    newState.currentSubmit = submit
+            if not deepEqual(newState, @state)
+                @setState(newState)
+
     setCurrentSubmit: (submit) ->
         (e) =>
             e.preventDefault()

        @comment = @comment.bind this
        @setField = @setField.bind this
        @setComment = @setComment.bind this
        @setCurrentSubmit = @setCurrentSubmit.bind this
        @setCurrentDiff = @setCurrentDiff.bind this
        @setQuality = @setQuality.bind this
        @toggleBestSubmits = @toggleBestSubmits.bind this
        @downloadSubmits = @downloadSubmits.bind this

            styles.muchUnpaid

    render:  () ->
        <div className={@paidStyle()}>
            {`<SubmitListWithDiff {...this.props} SubmitComponent={SubmitWithActions}/>`}
        </div>

SubmitsAndSimilarMerger = (props) ->
