"use babel"; /** @jsx etch.dom */ import git from "../git-cmd"; import Dialog from "./Dialog"; import etch from "etch"; import Notifications from "../Notifications"; export default class SwitchBranchDialog extends Dialog { beforeInitialize() { this.fetch = this.fetch.bind(this); this.branchChange = this.branchChange.bind(this); } initialState(props) { if (!props.root) { throw new Error("Must specify a {root} property"); } let state = { branches: props.branches || [], branch: "", root: props.root, fetching: false, }; state.branch = state.branches.reduce((prev, branch) => (branch.selected ? branch.name : prev), ""); return state; } validate(state) { let error = false; if (!state.branch) { error = true; this.refs.branchInput.classList.add("error"); } if (error) { return; } return [state.branch]; } show() { this.refs.branchInput.focus(); } async fetch() { this.update({ fetching: true }); try { await git.fetch(this.state.root); const branches = await git.branches(this.state.root); this.update({ branches: branches, fetching: false }); } catch (err) { console.log(err); Notifications.addError("Fetch", err); this.update({ fetching: false }); } } branchChange(e) { this.refs.branchInput.classList.remove("error"); this.update({ branch: e.target.value }); } body() { let branchOptions; if (this.state.fetching) { branchOptions = ( ); } else { branchOptions = this.state.branches.map(branch => ( )); } return (