All files / applications/go-by-transit/src/view/bookmarks/component/bookmarkSections AddBookmarkSectionControl.tsx

100% Statements 13/13
100% Branches 0/0
100% Functions 6/6
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86                                  2x   2x       2x 2x       15x           7x   7x       7x         2x 2x   2x       24x   24x                                                              
import { Button, Input } from "@wintermuted/ui-react";
import { isEmpty } from "lodash";
import React, { Component } from "react";
import "./AddBookmarkSectionControl.css";
 
interface Props {
  onSectionNameUpdate: (name: string) => void;
  bookmarkSectionName: string;
  createBookmarkSection: () => void;
}
 
interface State {
  bookmarkSectionName: string;
}
 
export default class AddBookmarkSectionControl extends Component<Props, State> {
  constructor(props) {
    super(props);
 
    this.state = {
      bookmarkSectionName: props.bookmarkSectionName
    };
 
    this.onChange = this.onChange.bind(this);
    this.onClickAddBookmark = this.onClickAddBookmark.bind(this);
  }
 
  public componentWillReceiveProps(nextProps: Readonly<Props>): void {
    this.setState({
      bookmarkSectionName: nextProps.bookmarkSectionName
    });
  }
 
  public onChange(e) {
    const name = e.target.value;
 
    this.setState(
      {
        bookmarkSectionName: name
      },
      () => this.props.onSectionNameUpdate(name)
    );
  }
 
  public onClickAddBookmark(e) {
    e.stopPropagation();
    e.preventDefault();
 
    this.props.createBookmarkSection();
  }
 
  public render() {
    const noTextEntered = isEmpty(this.state.bookmarkSectionName);
 
    return (
      <div className="add-bookmark-section-control">
        <form
          className="add-bookmark-input-form"
          onSubmit={this.onClickAddBookmark}
        >
          <div className="add-bookmark-name-input-flex-container">
            <div className="transit-field-row" style={{ marginBottom: "1rem" }}>
              <Input
                type="text"
                aria-label="Bookmark Section Name"
                value={this.state.bookmarkSectionName}
                placeholder="Bookmark Section Name"
                onChange={this.onChange}
                className="add-bookmark-name-input"
              />
              <Button
                id="button-addon2"
                variant="primary"
                type="submit"
                disabled={noTextEntered}
              >
                Create
              </Button>
            </div>
          </div>
        </form>
      </div>
    );
  }
}