Skip to content

Commit

Permalink
Merge pull request #23 from orangain/remove-comment
Browse files Browse the repository at this point in the history
Fix #14, Make it possible to remove comment
  • Loading branch information
orangain authored Apr 20, 2020
2 parents 618078d + 23c2d1c commit ed85c19
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 59 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ install:
script:
- docker-compose -f docker-compose.ci.yml build
- docker-compose -f docker-compose.ci.yml run --rm npm_build
- docker-compose -f docker-compose.ci.yml run --rm go_build
- if [ "$TRAVIS_BRANCH" = "master" ] && [ "$TRAVIS_PULL_REQUEST" = "false" ]; then make release; fi
- VERSION_NAME=${TRAVIS_TAG:-master} docker-compose -f docker-compose.ci.yml run --rm go_build
- if [ "$TRAVIS_BRANCH" = "master" ] && [ "$TRAVIS_PULL_REQUEST" = "false" ]; then make pre-release VERSION_NAME=master; fi
- if [ -n "$TRAVIS_TAG" ]; then make release VERSION_NAME=$TRAVIS_TAG RELEASE_NAME=$TRAVIS_TAG; fi
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ cmd/kifu-notebook/bindata.go:
kifu-notebook: cmd/kifu-notebook/bindata.go $(SRCS)
go build -o kifu-notebook ./cmd/kifu-notebook

GOX_OPTS=-osarch "linux/amd64 linux/386 linux/arm darwin/amd64 darwin/386 windows/amd64 windows/386"
VERSION_NAME=master
GOX_OPTS := -osarch "linux/amd64 linux/386 linux/arm darwin/amd64 darwin/386 windows/amd64 windows/386"
VERSION_NAME := master

gox: cmd/kifu-notebook/bindata.go $(SRCS)
gox $(GOX_OPTS) -output "build/cli/${VERSION_NAME}/{{.Dir}}_${VERSION_NAME}_{{.OS}}_{{.Arch}}/{{.Dir}}" ./cmd/kifu-notebook

package: gox
./scripts/package.sh build/cli/${VERSION_NAME} build/archives/${VERSION_NAME}

release:
pre-release:
ghr -u orangain --prerelease --delete --replace pre-release build/archives/${VERSION_NAME}

release:
ghr -u orangain ${RELEASE_NAME} build/archives/${VERSION_NAME}
2 changes: 1 addition & 1 deletion docker-compose.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
build:
context: .
dockerfile: "Dockerfile.go_build"
command: make package
command: make package VERSION_NAME=${VERSION_NAME}
volumes:
- .:/usr/src/kifu-notebook
working_dir: /usr/src/kifu-notebook
32 changes: 2 additions & 30 deletions src/components/CurrentNode.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import * as React from "react";
import { Component } from "react";
import "./CurrentNode.css";
import * as Immutable from "immutable";

import ForkList from "./ForkList";
import { Path, KifuTree } from "../models";

interface CurrentNodeLocalState {
comment?: string;
}

export interface CurrentNodeStateProps {
kifuTree: KifuTree;
}
Expand All @@ -21,43 +16,20 @@ export interface CurrentNodeDispatchProps {
}

export default class CurrentNode extends Component<
CurrentNodeStateProps & CurrentNodeDispatchProps,
CurrentNodeLocalState
CurrentNodeStateProps & CurrentNodeDispatchProps
> {
componentWillMount() {
const { kifuTree } = this.props;
const currentNode = kifuTree.getCurrentNode();
this.setState({ comment: currentNode.comment });
}

componentWillReceiveProps(
nextProps: CurrentNodeStateProps & CurrentNodeDispatchProps
) {
if (
!Immutable.is(
this.props.kifuTree.currentPath,
nextProps.kifuTree.currentPath
)
) {
const { kifuTree } = nextProps;
const currentNode = kifuTree.getCurrentNode();
this.setState({ comment: currentNode.comment });
}
}

onChangeComments(comment: string) {
this.setState({ comment: comment });
this.props.onChangeComments(comment);
}

render() {
const { kifuTree } = this.props;
const { comment } = this.state;
const currentNode = kifuTree.getCurrentNode();
const previousPath = kifuTree.getPreviousPath();
const nextPath = kifuTree.getNextPath();
const previousForkPath = kifuTree.getPreviousForkPath();
const nextForkPath = kifuTree.getNextForkPath();
const comment = currentNode.comment;

return (
<div>
Expand Down
11 changes: 5 additions & 6 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ export class KifuTree extends Record({

updateNode(
path: Path,
nodeUpdater: (node: KifuTreeNode) => KifuTreeNode | Map<string, any>
nodeUpdater: (node: KifuTreeNode) => KifuTreeNode | Map<string, any>,
skipMaintainJumpTargets = false // TODO: Change method or detect automatically
): KifuTree {
const keyPath = pathToKeyPath(path);
const newRootNode = this.rootNode.updateIn(keyPath, (node: KifuTreeNode) =>
nodeUpdater(node)
) as KifuTreeNode;
return (this.set(
"rootNode",
newRootNode
) as KifuTree).maintainJumpTargets();
const newTree = this.set("rootNode", newRootNode) as KifuTree;

return skipMaintainJumpTargets ? newTree : newTree.maintainJumpTargets();
}

updateFork(
Expand Down Expand Up @@ -259,7 +259,6 @@ export interface BoardSetState {

export interface CurrentNodeState {
kifuTree: KifuTree;
latestComment: string;
}

export interface KifuTreeState {
Expand Down
25 changes: 8 additions & 17 deletions src/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const initialState: KifuNotebookState = {
message: "",
autoSaveEnabled: false,
needSave: false,
latestComment: "",
};

export default function kifuTree(
Expand Down Expand Up @@ -80,28 +79,20 @@ export default function kifuTree(
});
}
case CHANGE_COMMENTS: {
const { kifuTree } = state;
const value = action.value;
return Object.assign({}, state, { latestComment: value });
}
case UPDATE_COMMENTS: {
const { kifuTree, latestComment } = state;

if (latestComment === "") {
// This will happen when user leave textarea without changing comment.
return state;
}

const newKifuTree = kifuTree.updateNode(
kifuTree.currentPath,
(node: KifuTreeNode) => {
return node.set("comment", latestComment);
}
return node.set("comment", value);
},
true
);
return Object.assign({}, state, {
kifuTree: newKifuTree,
needSave: true,
latestComment: "",
});
return { ...state, kifuTree: newKifuTree };
}
case UPDATE_COMMENTS: {
return { ...state, needSave: true };
}
case CHANGE_REVERSED: {
const value = action.value;
Expand Down

0 comments on commit ed85c19

Please sign in to comment.