heartwood every commit a ring

fix for bug when submitting with "enter" key

7568da2e by domind · 6 years ago

modified components/HotKeysMapping.js
@@ -1,10 +1,22 @@import React, { useState, useContext } from "react";import React, { useContext } from "react";import { useRouter } from "next/router";import { HotKeys, configure } from "react-hotkeys";import { Context } from "../components/context";configure({  ignoreTags: []  ignoreTags: [],  //logLevel: "debug",  /* below is workaround for bug in react-hotkeys   "[BUG] typing a space in <input /> will disable all hotkeys in that <input /> #237"   causing hotkeys to after pressing a whitespace character (space, enter,..)   in one of the per default ignored elements (input, textarea...),   this whitespace character is included in the combination for all further hotkeys.*/  ignoreEventsCondition: keyEvent => {    if (keyEvent.key === "Enter" || keyEvent.key === " ") {      return true;    }    return false;  }});const keyMap = {
@@ -18,7 +30,6 @@ const keyMap = {  LOG_PREVIOUS: "ArrowUp",  LOG_EDIT: "alt+e",  LOG_DELETE_SINGLE: "alt+d"};const HotKeysMapping = props => {
@@ -27,36 +38,42 @@ const HotKeysMapping = props => {  const router = useRouter();  const handlers = {    RESET: event => dispatch({ type: "NEW_TIMER" }),    ADD_LOG: event => dispatch({ type: "ADD_LOG", note: state.note }),    TIMER_PAGE: event => {event.preventDefault(); router.push("/")},    ADD_LOG: event => {      event.preventDefault();      dispatch({ type: "ADD_LOG", note: state.note });    },    TIMER_PAGE: event => {      event.preventDefault();      router.push("/");    },    LOG_PAGE: event => router.push("/log"),    ABOUT_PAGE: event => router.push("/about"),    CLEAR_LOG: event => dispatch({ type: "CLEAR_LOG" }),    LOG_NEXT: event => {      event.preventDefault();      if (state.edit) return;      if (window.location.href.substr(window.location.href.length - 3) == "log")        dispatch({ type: "NEXT_LOG_ITEM" });      dispatch({ type: "TOGGLE_EDITION", edit: false });    },    LOG_PREVIOUS: event => {      event.preventDefault();      if (state.edit) return;      //   if (state.edit) return;      if (window.location.href.substr(window.location.href.length - 3) == "log")        dispatch({ type: "PREVIOUS_LOG_ITEM" });      dispatch({ type: "TOGGLE_EDITION", edit: false });    },    LOG_EDIT: event => {      event.preventDefault();      if (!state.logSelectedEntry) return;      if (window.location.href.substr(window.location.href.length - 3) == "log")        dispatch({ type: "LOG_EDIT", edit: true });        dispatch({ type: "TOGGLE_EDITION", edit: true });    },    LOG_DELETE_SINGLE: event => {      event.preventDefault();      if (!state.logSelectedEntry) return;      if (window.location.href.substr(window.location.href.length - 3) == "log")      dispatch({ type: "REMOVE_LOG" });        dispatch({ type: "REMOVE_LOG" });    }  };  return (
modified components/context.js
@@ -83,7 +83,7 @@ const reducer = (state, action) => {        ]      };      localForage.setItem("context", newState);      toast.success(strings.editedEntry);      // toast.success(strings.editedEntry);      return newState;    case "REMOVE_LOG":      if (action.id !== undefined)
@@ -94,10 +94,13 @@ const reducer = (state, action) => {            state.logSelectedEntry == action.id ? "" : state.logSelectedEntry        };      else {        newState = { ...state,          log: [...state.log.filter(entry => entry.id !== state.logSelectedEntry)],        newState = {          ...state,          log: [            ...state.log.filter(entry => entry.id !== state.logSelectedEntry)          ],          logSelectedEntry: ""         };        };      }      localForage.setItem("context", newState);      toast.error(strings.deletedEntry);
@@ -152,9 +155,10 @@ const reducer = (state, action) => {      newState = { ...state, logSelectedEntry: action.id };      localForage.setItem("context", newState);      return newState;    case "LOG_EDIT":    case "TOGGLE_EDITION":      newState = { ...state, edit: action.edit };      localForage.setItem("context", newState);      action.submited ? toast.success(strings.editedEntry) : "";      return newState;    default:      return state;
modified components/entry.js
@@ -25,7 +25,7 @@ const Entry = ({ entry, removeEntry, isSelected }) => {          })      }    });    dispatch({type:"LOG_EDIT", edit:false});    dispatch({ type: "TOGGLE_EDITION", edit: false, submited: true });  };  const higlight =
@@ -36,7 +36,7 @@ const Entry = ({ entry, removeEntry, isSelected }) => {      : {};  return (    <EntryContainer style={higlight} className={state.edit && "zoom"}>      {(state.edit && isSelected==entry.id) ? (      {state.edit && isSelected == entry.id ? (        <EntryForm onSubmit={handleSubmit(onSubmit)}>          <EntryTime>            {timeString(entry.end - entry.start)}
@@ -45,18 +45,39 @@ const Entry = ({ entry, removeEntry, isSelected }) => {          <EntryNote>            <EntryNoteInput              name="note"              defaultValue={entry.note}              // defaultValue={entry.note || ""}              ref={register}              autoFocus              value={state.log.find(x => x.id == entry.id).note || ""}              onChange={e =>                dispatch({                  type: "EDIT_LOG",                  entry: {                    ...entry,                    note: e.target.value, //data.note,                    tags: e.target.value //data.note                      .split(" ")                      .filter(word => word.startsWith("#"))                      .map(word => {                        return word.toLowerCase();                      })                  }                })              }            />          </EntryNote>          <EntrySubmit type="submit">✔</EntrySubmit>          <EntryRemove type="button" onClick={() =>  dispatch({type:"LOG_EDIT", edit:false})}>          <EntryRemove            type="button"            onClick={() => dispatch({ type: "TOGGLE_EDITION", edit: false })}          >            x          </EntryRemove>        </EntryForm>      ) : (        <>        <          // autoFocus= {(isSelected==entry.id)}        >          <EntryTime>            {timeString(entry.end - entry.start)}            <span>{entry.start.toLocaleTimeString()}</span>
@@ -76,7 +97,7 @@ const Entry = ({ entry, removeEntry, isSelected }) => {          <EntryEdit            onClick={() => {              dispatch({ type: "SELECT_LOG_ITEM", id: entry.id });              dispatch({type:"LOG_EDIT", edit:true})              dispatch({ type: "TOGGLE_EDITION", edit: true });            }}          >            _
modified yarn.lock
@@ -5257,7 +5257,7 @@ prop-types-exact@1.2.0:    object.assign "^4.1.0"    reflect.ownkeys "^0.2.0"prop-types@15.7.2, prop-types@^15.5.4, prop-types@^15.6.2, prop-types@^15.7.2:prop-types@15.7.2, prop-types@^15.5.4, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2:  version "15.7.2"  resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"  integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
@@ -5401,6 +5401,13 @@ react-hook-form@^3.23.18:  resolved "https://registry.yarnpkg.com/react-hook-form/-/react-hook-form-3.29.4.tgz#0d4a6650d3f8035e5f4f6740258ac711e0fc3184"  integrity sha512-NsqXUIHPmiXcb11gY5e4kiJSc0WONXRo28JLuXBL0dJr1vk60W5IwnzBDeT0mb+V3MIjPrV0lFPKo57VnSZAPw==react-hotkeys@^2.0.0:  version "2.0.0"  resolved "https://registry.yarnpkg.com/react-hotkeys/-/react-hotkeys-2.0.0.tgz#a7719c7340cbba888b0e9184f806a9ec0ac2c53f"  integrity sha512-3n3OU8vLX/pfcJrR3xJ1zlww6KS1kEJt0Whxc4FiGV+MJrQ1mYSYI3qS/11d2MJDFm8IhOXMTFQirfu6AVOF6Q==  dependencies:    prop-types "^15.6.1"react-is@16.8.6:  version "16.8.6"  resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16"