From 3c53222f3671e6ef2b2630b2832de6d530c54c38 Mon Sep 17 00:00:00 2001 From: Owen-Krueger Date: Fri, 15 May 2020 22:10:00 -0500 Subject: [PATCH 1/5] Allow disabling spellcheck --- src/main/i18n/translations/en.ts | 1 + .../elements/editor/editor/Editor.tsx | 7 ++-- .../editor/editor/EditorContainer.tsx | 1 + .../pref-overlay/entries-pref/EntriesPref.tsx | 3 ++ .../DisableSpellCheckPref.tsx | 35 +++++++++++++++++++ .../DisableSpellCheckPrefContainer.tsx | 16 +++++++++ src/renderer/files/preferences/preferences.ts | 17 +++++++++ src/renderer/store/app/actionCreators.ts | 19 ++++++++++ src/renderer/store/app/reducer.ts | 9 +++++ src/renderer/store/app/types.ts | 10 ++++++ src/shared/types.ts | 1 + 11 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 src/renderer/components/overlays/pref-overlay/entries-pref/disable-spellcheck-pref/DisableSpellCheckPref.tsx create mode 100644 src/renderer/components/overlays/pref-overlay/entries-pref/disable-spellcheck-pref/DisableSpellCheckPrefContainer.tsx diff --git a/src/main/i18n/translations/en.ts b/src/main/i18n/translations/en.ts index 66e4402c..76c34fd3 100644 --- a/src/main/i18n/translations/en.ts +++ b/src/main/i18n/translations/en.ts @@ -79,6 +79,7 @@ const translationsEn: Translations = { "allow-future-entries": "Allow entries in the future", auto: "Auto", "diary-entries": "Diary entries", + "disable-spellcheck": "Disable spellcheck", "first-day-of-week": "First day of the week", "hide-titles": "Hide titles", no: "No", diff --git a/src/renderer/components/elements/editor/editor/Editor.tsx b/src/renderer/components/elements/editor/editor/Editor.tsx index 36deee92..fda2e690 100644 --- a/src/renderer/components/elements/editor/editor/Editor.tsx +++ b/src/renderer/components/elements/editor/editor/Editor.tsx @@ -31,6 +31,7 @@ const listPlugin = createListPlugin(); const plugins = [listPlugin]; export interface StateProps { + disableSpellCheck: boolean; hideTitles: boolean; dateSelected: Moment; entries: Entries; @@ -164,7 +165,7 @@ export default class Editor extends PureComponent { render = (): ReactNode => { const { dateSelected, textEditorState, titleEditorState } = this.state; - const { hideTitles } = this.props; + const { disableSpellCheck, hideTitles } = this.props; // Detect active inline/block styles const blockType = RichUtils.getCurrentBlockType(textEditorState); @@ -185,7 +186,7 @@ export default class Editor extends PureComponent { onBlur={this.saveEntry} onChange={this.onTitleChange} placeholder={translations["add-a-title"]} - spellCheck + spellCheck={!disableSpellCheck} /> )} @@ -200,7 +201,7 @@ export default class Editor extends PureComponent { }} placeholder={isOl || isUl ? "" : `${translations["write-something"]}…`} plugins={plugins} - spellCheck + spellCheck={!disableSpellCheck} /> diff --git a/src/renderer/components/elements/editor/editor/EditorContainer.tsx b/src/renderer/components/elements/editor/editor/EditorContainer.tsx index 7e4a85b5..814269a1 100644 --- a/src/renderer/components/elements/editor/editor/EditorContainer.tsx +++ b/src/renderer/components/elements/editor/editor/EditorContainer.tsx @@ -6,6 +6,7 @@ import { IndexDate } from "../../../../types"; import Editor, { DispatchProps, StateProps } from "./Editor"; const mapStateToProps = (state: RootState): StateProps => ({ + disableSpellCheck: state.app.disableSpellCheck, hideTitles: state.app.hideTitles, dateSelected: state.diary.dateSelected, entries: state.file.entries, diff --git a/src/renderer/components/overlays/pref-overlay/entries-pref/EntriesPref.tsx b/src/renderer/components/overlays/pref-overlay/entries-pref/EntriesPref.tsx index 922d7153..2d71dd20 100644 --- a/src/renderer/components/overlays/pref-overlay/entries-pref/EntriesPref.tsx +++ b/src/renderer/components/overlays/pref-overlay/entries-pref/EntriesPref.tsx @@ -1,6 +1,7 @@ import React, { ReactElement } from "react"; import { translations } from "../../../../utils/i18n"; +import DisableSpellCheckPrefContainer from "./disable-spellcheck-pref/DisableSpellCheckPrefContainer"; import FutureEntriesPrefContainer from "./future-entries-pref/FutureEntriesPrefContainer"; import HideTitlesPrefContainer from "./hide-titles-pref/HideTitlesPrefContainer"; @@ -15,6 +16,8 @@ export default function EntriesPref(): ReactElement {
+
+ ); diff --git a/src/renderer/components/overlays/pref-overlay/entries-pref/disable-spellcheck-pref/DisableSpellCheckPref.tsx b/src/renderer/components/overlays/pref-overlay/entries-pref/disable-spellcheck-pref/DisableSpellCheckPref.tsx new file mode 100644 index 00000000..b431b684 --- /dev/null +++ b/src/renderer/components/overlays/pref-overlay/entries-pref/disable-spellcheck-pref/DisableSpellCheckPref.tsx @@ -0,0 +1,35 @@ +import React, { ReactElement } from "react"; + +import { translations } from "../../../../../utils/i18n"; + +export interface StateProps { + disableSpellCheck: boolean; +} + +export interface DispatchProps { + updateDisableSpellCheckPref: (disableSpellCheck: boolean) => void; +} + +type Props = StateProps & DispatchProps; + +/** + * Preference fieldset for enabling or disabling spellcheck + */ +export default function DisableSpellCheckPref(props: Props): ReactElement { + const { disableSpellCheck, updateDisableSpellCheckPref } = props; + + const toggleDisableSpellCheck = (): void => updateDisableSpellCheckPref(!disableSpellCheck); + + return ( + + ); +} diff --git a/src/renderer/components/overlays/pref-overlay/entries-pref/disable-spellcheck-pref/DisableSpellCheckPrefContainer.tsx b/src/renderer/components/overlays/pref-overlay/entries-pref/disable-spellcheck-pref/DisableSpellCheckPrefContainer.tsx new file mode 100644 index 00000000..faac1266 --- /dev/null +++ b/src/renderer/components/overlays/pref-overlay/entries-pref/disable-spellcheck-pref/DisableSpellCheckPrefContainer.tsx @@ -0,0 +1,16 @@ +import { connect } from "react-redux"; + +import { updateDisableSpellCheckPref } from "../../../../../store/app/actionCreators"; +import { RootState, ThunkDispatchT } from "../../../../../store/store"; +import DisableSpellCheckPref, { DispatchProps, StateProps } from "./DisableSpellCheckPref"; + +const mapStateToProps = (state: RootState): StateProps => ({ + disableSpellCheck: state.app.disableSpellCheck, +}); + +const mapDispatchToProps = (dispatch: ThunkDispatchT): DispatchProps => ({ + updateDisableSpellCheckPref: (disableSpellCheck: boolean): void => + dispatch(updateDisableSpellCheckPref(disableSpellCheck)), +}); + +export default connect(mapStateToProps, mapDispatchToProps)(DisableSpellCheckPref); diff --git a/src/renderer/files/preferences/preferences.ts b/src/renderer/files/preferences/preferences.ts index 8b6fa67d..0941e057 100644 --- a/src/renderer/files/preferences/preferences.ts +++ b/src/renderer/files/preferences/preferences.ts @@ -9,6 +9,7 @@ import { supportsNativeTheme } from "../../utils/native-theme"; const DEFAULT_ALLOW_FUTURE_ENTRIES = false; const DEFAULT_FIRST_DAY_OF_WEEK = null; // Let the system locale determine the first day of the week const DEFAULT_HIDE_TITLES = false; +const DEFAULT_DISABLE_SPELLCHECK = false; const DEFAULT_THEME_PREF: ThemePref = "light"; const PREF_DIR = remote.app.getPath("userData"); @@ -97,6 +98,22 @@ export function saveHideTitlesPref(hideTitles: boolean): void { setPref("hideTitles", hideTitles); } +// SpellCheck + +/** + * Return the preference for whether spell check should be disabled + */ +export function loadDisableSpellCheckPref(): boolean { + return getPref("disableSpellCheck", DEFAULT_DISABLE_SPELLCHECK) +} + +/** + * Update the preference for disabling spell check + */ +export function saveDisableSpellCheckPref(disableSpellCheck: boolean): void { + setPref("disableSpellCheck", disableSpellCheck); +} + // Theme /** diff --git a/src/renderer/store/app/actionCreators.ts b/src/renderer/store/app/actionCreators.ts index d23fc948..9cc56294 100644 --- a/src/renderer/store/app/actionCreators.ts +++ b/src/renderer/store/app/actionCreators.ts @@ -4,18 +4,21 @@ import { saveFutureEntriesPref, saveHideTitlesPref, saveThemePref, + saveDisableSpellCheckPref, } from "../../files/preferences/preferences"; import { Weekday, Theme, ThemePref } from "../../types"; import { getThemeFromPref } from "../../utils/native-theme"; import { ThunkActionT } from "../store"; import { SET_ALLOW_FUTURE_ENTRIES, + SET_DISABLE_SPELLCHECK, SET_HIDE_TITLES, SET_FIRST_DAY_OF_WEEK, SET_OVERLAY, SET_THEME, SET_THEME_PREF, SetAllowFutureEntriesAction, + SetDisableSpellCheckAction, SetFirstDayOfWeekAction, SetOverlayAction, SetThemeAction, @@ -34,6 +37,15 @@ function setAllowFutureEntries(allowFutureEntries: boolean): SetAllowFutureEntri }; } +function setDisableSpellCheck(disableSpellCheck: boolean): SetDisableSpellCheckAction { + return { + type: SET_DISABLE_SPELLCHECK, + payload: { + disableSpellCheck, + }, + }; +} + function setHideTitles(hideTitles: boolean): SetHideTitlesAction { return { type: SET_HIDE_TITLES, @@ -90,6 +102,13 @@ export function setThemePref(themePref: ThemePref): SetThemePrefAction { // Thunks +export const updateDisableSpellCheckPref = (disableSpellCheck: boolean): ThunkActionT => ( + dispatch, +): void => { + dispatch(setDisableSpellCheck(disableSpellCheck)); + saveDisableSpellCheckPref(disableSpellCheck); +}; + export const updateFutureEntriesPref = (allowFutureEntries: boolean): ThunkActionT => ( dispatch, ): void => { diff --git a/src/renderer/store/app/reducer.ts b/src/renderer/store/app/reducer.ts index e72f2325..9e700843 100644 --- a/src/renderer/store/app/reducer.ts +++ b/src/renderer/store/app/reducer.ts @@ -1,5 +1,6 @@ import { loadFirstDayOfWeekPref, + loadDisableSpellCheckPref, loadFutureEntriesPref, loadThemePref, loadHideTitlesPref, @@ -9,6 +10,7 @@ import { AppAction, AppState, SET_ALLOW_FUTURE_ENTRIES, + SET_DISABLE_SPELLCHECK, SET_FIRST_DAY_OF_WEEK, SET_OVERLAY, SET_THEME, @@ -21,6 +23,7 @@ const theme = getThemeFromPref(themePref); const initialState: AppState = { allowFutureEntries: loadFutureEntriesPref(), + disableSpellCheck: loadDisableSpellCheckPref(), firstDayOfWeek: loadFirstDayOfWeekPref(), hideTitles: loadHideTitlesPref(), overlay: "none", @@ -36,6 +39,12 @@ function appReducer(state = initialState, action: AppAction): AppState { allowFutureEntries: action.payload.allowFutureEntries, }; } + case SET_DISABLE_SPELLCHECK: { + return { + ...state, + disableSpellCheck: action.payload.disableSpellCheck, + }; + } case SET_HIDE_TITLES: { return { ...state, diff --git a/src/renderer/store/app/types.ts b/src/renderer/store/app/types.ts index 314da8e4..0a303edf 100644 --- a/src/renderer/store/app/types.ts +++ b/src/renderer/store/app/types.ts @@ -7,6 +7,7 @@ import { Weekday, Theme, ThemePref } from "../../types"; export interface AppState { allowFutureEntries: boolean; + disableSpellCheck: boolean; firstDayOfWeek: Weekday | null; hideTitles: boolean; overlay: OverlayType; @@ -17,6 +18,7 @@ export interface AppState { // Action types export const SET_ALLOW_FUTURE_ENTRIES = "SET_ALLOW_FUTURE_ENTRIES"; +export const SET_DISABLE_SPELLCHECK = "SET_DISABLE_SPELLCHECK"; export const SET_FIRST_DAY_OF_WEEK = "SET_FIRST_DAY_OF_WEEK"; export const SET_HIDE_TITLES = "SET_HIDE_TITLES"; export const SET_OVERLAY = "SET_OVERLAY"; @@ -32,6 +34,13 @@ export interface SetAllowFutureEntriesAction extends Action { }; } +export interface SetDisableSpellCheckAction extends Action { + type: typeof SET_DISABLE_SPELLCHECK; + payload: { + disableSpellCheck: boolean; + }; +} + export interface SetFirstDayOfWeekAction extends Action { type: typeof SET_FIRST_DAY_OF_WEEK; payload: { @@ -69,6 +78,7 @@ export interface SetThemePrefAction extends Action { export type AppAction = | SetAllowFutureEntriesAction + | SetDisableSpellCheckAction | SetFirstDayOfWeekAction | SetHideTitlesAction | SetOverlayAction diff --git a/src/shared/types.ts b/src/shared/types.ts index f65f4839..b86daa81 100644 --- a/src/shared/types.ts +++ b/src/shared/types.ts @@ -91,6 +91,7 @@ export interface Translations { "allow-future-entries": string; auto: string; "diary-entries": string; + "disable-spellcheck": string; "first-day-of-week": string; "hide-titles": string; no: string; From 746a3dc1e9556d35228034c21c68983a59efc992 Mon Sep 17 00:00:00 2001 From: Owen-Krueger Date: Fri, 15 May 2020 22:18:28 -0500 Subject: [PATCH 2/5] Format fixes --- .../disable-spellcheck-pref/DisableSpellCheckPref.tsx | 4 ++-- src/renderer/files/preferences/preferences.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/renderer/components/overlays/pref-overlay/entries-pref/disable-spellcheck-pref/DisableSpellCheckPref.tsx b/src/renderer/components/overlays/pref-overlay/entries-pref/disable-spellcheck-pref/DisableSpellCheckPref.tsx index b431b684..9b395453 100644 --- a/src/renderer/components/overlays/pref-overlay/entries-pref/disable-spellcheck-pref/DisableSpellCheckPref.tsx +++ b/src/renderer/components/overlays/pref-overlay/entries-pref/disable-spellcheck-pref/DisableSpellCheckPref.tsx @@ -19,7 +19,7 @@ export default function DisableSpellCheckPref(props: Props): ReactElement { const { disableSpellCheck, updateDisableSpellCheckPref } = props; const toggleDisableSpellCheck = (): void => updateDisableSpellCheckPref(!disableSpellCheck); - + return ( diff --git a/src/renderer/files/preferences/preferences.ts b/src/renderer/files/preferences/preferences.ts index 0941e057..90bbbd1f 100644 --- a/src/renderer/files/preferences/preferences.ts +++ b/src/renderer/files/preferences/preferences.ts @@ -104,7 +104,7 @@ export function saveHideTitlesPref(hideTitles: boolean): void { * Return the preference for whether spell check should be disabled */ export function loadDisableSpellCheckPref(): boolean { - return getPref("disableSpellCheck", DEFAULT_DISABLE_SPELLCHECK) + return getPref("disableSpellCheck", DEFAULT_DISABLE_SPELLCHECK); } /** From d8d78529e525990a00299005c93b2241ffd0a27e Mon Sep 17 00:00:00 2001 From: Samuel Meuli Date: Sat, 23 May 2020 17:15:23 +0200 Subject: [PATCH 3/5] Add German translation for "Disable spellcheck" option --- src/main/i18n/translations/de.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/i18n/translations/de.ts b/src/main/i18n/translations/de.ts index 40afef60..7739dd76 100644 --- a/src/main/i18n/translations/de.ts +++ b/src/main/i18n/translations/de.ts @@ -79,6 +79,7 @@ const translationsDe: Partial = { "allow-future-entries": "Einträge in der Zukunft erlauben", auto: "Automatisch", "diary-entries": "Tagebucheinträge", + "disable-spellcheck": "Rechtschreibprüfung deaktivieren", "first-day-of-week": "Erster Wochentag", "hide-titles": "Titel ausblenden", no: "Nein", From 9e0b013852f80b231fcf678daf3c853cbee00cb5 Mon Sep 17 00:00:00 2001 From: Samuel Meuli Date: Sat, 23 May 2020 17:44:16 +0200 Subject: [PATCH 4/5] Rename "Disable spellcheck" to "Enable spellcheck" --- src/main/i18n/translations/de.ts | 2 +- src/main/i18n/translations/en.ts | 2 +- .../elements/editor/editor/Editor.tsx | 8 ++--- .../editor/editor/EditorContainer.tsx | 2 +- .../pref-overlay/entries-pref/EntriesPref.tsx | 4 +-- .../DisableSpellCheckPref.tsx | 35 ------------------- .../DisableSpellCheckPrefContainer.tsx | 16 --------- .../spellcheck-pref/SpellcheckPref.tsx | 35 +++++++++++++++++++ .../SpellcheckPrefContainer.tsx | 16 +++++++++ src/renderer/files/preferences/preferences.ts | 12 +++---- src/renderer/store/app/actionCreators.ts | 18 +++++----- src/renderer/store/app/reducer.ts | 10 +++--- src/renderer/store/app/types.ts | 12 +++---- src/shared/types.ts | 2 +- 14 files changed, 87 insertions(+), 87 deletions(-) delete mode 100644 src/renderer/components/overlays/pref-overlay/entries-pref/disable-spellcheck-pref/DisableSpellCheckPref.tsx delete mode 100644 src/renderer/components/overlays/pref-overlay/entries-pref/disable-spellcheck-pref/DisableSpellCheckPrefContainer.tsx create mode 100644 src/renderer/components/overlays/pref-overlay/entries-pref/spellcheck-pref/SpellcheckPref.tsx create mode 100644 src/renderer/components/overlays/pref-overlay/entries-pref/spellcheck-pref/SpellcheckPrefContainer.tsx diff --git a/src/main/i18n/translations/de.ts b/src/main/i18n/translations/de.ts index 7739dd76..1dbc248b 100644 --- a/src/main/i18n/translations/de.ts +++ b/src/main/i18n/translations/de.ts @@ -79,7 +79,7 @@ const translationsDe: Partial = { "allow-future-entries": "Einträge in der Zukunft erlauben", auto: "Automatisch", "diary-entries": "Tagebucheinträge", - "disable-spellcheck": "Rechtschreibprüfung deaktivieren", + "enable-spellcheck": "Rechtschreibprüfung aktivieren", "first-day-of-week": "Erster Wochentag", "hide-titles": "Titel ausblenden", no: "Nein", diff --git a/src/main/i18n/translations/en.ts b/src/main/i18n/translations/en.ts index 76c34fd3..e8363ee5 100644 --- a/src/main/i18n/translations/en.ts +++ b/src/main/i18n/translations/en.ts @@ -79,7 +79,7 @@ const translationsEn: Translations = { "allow-future-entries": "Allow entries in the future", auto: "Auto", "diary-entries": "Diary entries", - "disable-spellcheck": "Disable spellcheck", + "enable-spellcheck": "Check spelling", "first-day-of-week": "First day of the week", "hide-titles": "Hide titles", no: "No", diff --git a/src/renderer/components/elements/editor/editor/Editor.tsx b/src/renderer/components/elements/editor/editor/Editor.tsx index fda2e690..cc0f09d8 100644 --- a/src/renderer/components/elements/editor/editor/Editor.tsx +++ b/src/renderer/components/elements/editor/editor/Editor.tsx @@ -31,7 +31,7 @@ const listPlugin = createListPlugin(); const plugins = [listPlugin]; export interface StateProps { - disableSpellCheck: boolean; + enableSpellcheck: boolean; hideTitles: boolean; dateSelected: Moment; entries: Entries; @@ -165,7 +165,7 @@ export default class Editor extends PureComponent { render = (): ReactNode => { const { dateSelected, textEditorState, titleEditorState } = this.state; - const { disableSpellCheck, hideTitles } = this.props; + const { enableSpellcheck, hideTitles } = this.props; // Detect active inline/block styles const blockType = RichUtils.getCurrentBlockType(textEditorState); @@ -186,7 +186,7 @@ export default class Editor extends PureComponent { onBlur={this.saveEntry} onChange={this.onTitleChange} placeholder={translations["add-a-title"]} - spellCheck={!disableSpellCheck} + spellCheck={enableSpellcheck} /> )} @@ -201,7 +201,7 @@ export default class Editor extends PureComponent { }} placeholder={isOl || isUl ? "" : `${translations["write-something"]}…`} plugins={plugins} - spellCheck={!disableSpellCheck} + spellCheck={enableSpellcheck} /> diff --git a/src/renderer/components/elements/editor/editor/EditorContainer.tsx b/src/renderer/components/elements/editor/editor/EditorContainer.tsx index 814269a1..d9a98f83 100644 --- a/src/renderer/components/elements/editor/editor/EditorContainer.tsx +++ b/src/renderer/components/elements/editor/editor/EditorContainer.tsx @@ -6,7 +6,7 @@ import { IndexDate } from "../../../../types"; import Editor, { DispatchProps, StateProps } from "./Editor"; const mapStateToProps = (state: RootState): StateProps => ({ - disableSpellCheck: state.app.disableSpellCheck, + enableSpellcheck: state.app.enableSpellcheck, hideTitles: state.app.hideTitles, dateSelected: state.diary.dateSelected, entries: state.file.entries, diff --git a/src/renderer/components/overlays/pref-overlay/entries-pref/EntriesPref.tsx b/src/renderer/components/overlays/pref-overlay/entries-pref/EntriesPref.tsx index 2d71dd20..2d0bbdfa 100644 --- a/src/renderer/components/overlays/pref-overlay/entries-pref/EntriesPref.tsx +++ b/src/renderer/components/overlays/pref-overlay/entries-pref/EntriesPref.tsx @@ -1,9 +1,9 @@ import React, { ReactElement } from "react"; import { translations } from "../../../../utils/i18n"; -import DisableSpellCheckPrefContainer from "./disable-spellcheck-pref/DisableSpellCheckPrefContainer"; import FutureEntriesPrefContainer from "./future-entries-pref/FutureEntriesPrefContainer"; import HideTitlesPrefContainer from "./hide-titles-pref/HideTitlesPrefContainer"; +import SpellcheckPrefContainer from "./spellcheck-pref/SpellcheckPrefContainer"; /** * Preference fieldset for options related to diary entries @@ -17,7 +17,7 @@ export default function EntriesPref(): ReactElement {

- + ); diff --git a/src/renderer/components/overlays/pref-overlay/entries-pref/disable-spellcheck-pref/DisableSpellCheckPref.tsx b/src/renderer/components/overlays/pref-overlay/entries-pref/disable-spellcheck-pref/DisableSpellCheckPref.tsx deleted file mode 100644 index 9b395453..00000000 --- a/src/renderer/components/overlays/pref-overlay/entries-pref/disable-spellcheck-pref/DisableSpellCheckPref.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import React, { ReactElement } from "react"; - -import { translations } from "../../../../../utils/i18n"; - -export interface StateProps { - disableSpellCheck: boolean; -} - -export interface DispatchProps { - updateDisableSpellCheckPref: (disableSpellCheck: boolean) => void; -} - -type Props = StateProps & DispatchProps; - -/** - * Preference fieldset for enabling or disabling spellcheck - */ -export default function DisableSpellCheckPref(props: Props): ReactElement { - const { disableSpellCheck, updateDisableSpellCheckPref } = props; - - const toggleDisableSpellCheck = (): void => updateDisableSpellCheckPref(!disableSpellCheck); - - return ( - - ); -} diff --git a/src/renderer/components/overlays/pref-overlay/entries-pref/disable-spellcheck-pref/DisableSpellCheckPrefContainer.tsx b/src/renderer/components/overlays/pref-overlay/entries-pref/disable-spellcheck-pref/DisableSpellCheckPrefContainer.tsx deleted file mode 100644 index faac1266..00000000 --- a/src/renderer/components/overlays/pref-overlay/entries-pref/disable-spellcheck-pref/DisableSpellCheckPrefContainer.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import { connect } from "react-redux"; - -import { updateDisableSpellCheckPref } from "../../../../../store/app/actionCreators"; -import { RootState, ThunkDispatchT } from "../../../../../store/store"; -import DisableSpellCheckPref, { DispatchProps, StateProps } from "./DisableSpellCheckPref"; - -const mapStateToProps = (state: RootState): StateProps => ({ - disableSpellCheck: state.app.disableSpellCheck, -}); - -const mapDispatchToProps = (dispatch: ThunkDispatchT): DispatchProps => ({ - updateDisableSpellCheckPref: (disableSpellCheck: boolean): void => - dispatch(updateDisableSpellCheckPref(disableSpellCheck)), -}); - -export default connect(mapStateToProps, mapDispatchToProps)(DisableSpellCheckPref); diff --git a/src/renderer/components/overlays/pref-overlay/entries-pref/spellcheck-pref/SpellcheckPref.tsx b/src/renderer/components/overlays/pref-overlay/entries-pref/spellcheck-pref/SpellcheckPref.tsx new file mode 100644 index 00000000..c769a119 --- /dev/null +++ b/src/renderer/components/overlays/pref-overlay/entries-pref/spellcheck-pref/SpellcheckPref.tsx @@ -0,0 +1,35 @@ +import React, { ReactElement } from "react"; + +import { translations } from "../../../../../utils/i18n"; + +export interface StateProps { + enableSpellcheck: boolean; +} + +export interface DispatchProps { + updateSpellcheckPref: (enableSpellcheck: boolean) => void; +} + +type Props = StateProps & DispatchProps; + +/** + * Preference fieldset for enabling or disabling spellcheck + */ +export default function SpellcheckPref(props: Props): ReactElement { + const { enableSpellcheck, updateSpellcheckPref } = props; + + const toggleEnableSpellcheck = (): void => updateSpellcheckPref(!enableSpellcheck); + + return ( + + ); +} diff --git a/src/renderer/components/overlays/pref-overlay/entries-pref/spellcheck-pref/SpellcheckPrefContainer.tsx b/src/renderer/components/overlays/pref-overlay/entries-pref/spellcheck-pref/SpellcheckPrefContainer.tsx new file mode 100644 index 00000000..2150e1fd --- /dev/null +++ b/src/renderer/components/overlays/pref-overlay/entries-pref/spellcheck-pref/SpellcheckPrefContainer.tsx @@ -0,0 +1,16 @@ +import { connect } from "react-redux"; + +import { updateSpellcheckPref } from "../../../../../store/app/actionCreators"; +import { RootState, ThunkDispatchT } from "../../../../../store/store"; +import SpellcheckPref, { DispatchProps, StateProps } from "./SpellcheckPref"; + +const mapStateToProps = (state: RootState): StateProps => ({ + enableSpellcheck: state.app.enableSpellcheck, +}); + +const mapDispatchToProps = (dispatch: ThunkDispatchT): DispatchProps => ({ + updateSpellcheckPref: (enableSpellcheck: boolean): void => + dispatch(updateSpellcheckPref(enableSpellcheck)), +}); + +export default connect(mapStateToProps, mapDispatchToProps)(SpellcheckPref); diff --git a/src/renderer/files/preferences/preferences.ts b/src/renderer/files/preferences/preferences.ts index 90bbbd1f..9026bd10 100644 --- a/src/renderer/files/preferences/preferences.ts +++ b/src/renderer/files/preferences/preferences.ts @@ -9,7 +9,7 @@ import { supportsNativeTheme } from "../../utils/native-theme"; const DEFAULT_ALLOW_FUTURE_ENTRIES = false; const DEFAULT_FIRST_DAY_OF_WEEK = null; // Let the system locale determine the first day of the week const DEFAULT_HIDE_TITLES = false; -const DEFAULT_DISABLE_SPELLCHECK = false; +const DEFAULT_ENABLE_SPELLCHECK = true; const DEFAULT_THEME_PREF: ThemePref = "light"; const PREF_DIR = remote.app.getPath("userData"); @@ -98,20 +98,20 @@ export function saveHideTitlesPref(hideTitles: boolean): void { setPref("hideTitles", hideTitles); } -// SpellCheck +// Spellcheck /** * Return the preference for whether spell check should be disabled */ -export function loadDisableSpellCheckPref(): boolean { - return getPref("disableSpellCheck", DEFAULT_DISABLE_SPELLCHECK); +export function loadSpellcheckPref(): boolean { + return getPref("enableSpellcheck", DEFAULT_ENABLE_SPELLCHECK); } /** * Update the preference for disabling spell check */ -export function saveDisableSpellCheckPref(disableSpellCheck: boolean): void { - setPref("disableSpellCheck", disableSpellCheck); +export function saveSpellcheckPref(enableSpellcheck: boolean): void { + setPref("enableSpellcheck", enableSpellcheck); } // Theme diff --git a/src/renderer/store/app/actionCreators.ts b/src/renderer/store/app/actionCreators.ts index 9cc56294..ef4b6154 100644 --- a/src/renderer/store/app/actionCreators.ts +++ b/src/renderer/store/app/actionCreators.ts @@ -4,21 +4,21 @@ import { saveFutureEntriesPref, saveHideTitlesPref, saveThemePref, - saveDisableSpellCheckPref, + saveSpellcheckPref, } from "../../files/preferences/preferences"; import { Weekday, Theme, ThemePref } from "../../types"; import { getThemeFromPref } from "../../utils/native-theme"; import { ThunkActionT } from "../store"; import { SET_ALLOW_FUTURE_ENTRIES, - SET_DISABLE_SPELLCHECK, + SET_ENABLE_SPELLCHECK, SET_HIDE_TITLES, SET_FIRST_DAY_OF_WEEK, SET_OVERLAY, SET_THEME, SET_THEME_PREF, SetAllowFutureEntriesAction, - SetDisableSpellCheckAction, + SetEnableSpellcheckAction, SetFirstDayOfWeekAction, SetOverlayAction, SetThemeAction, @@ -37,11 +37,11 @@ function setAllowFutureEntries(allowFutureEntries: boolean): SetAllowFutureEntri }; } -function setDisableSpellCheck(disableSpellCheck: boolean): SetDisableSpellCheckAction { +function setEnableSpellcheck(enableSpellcheck: boolean): SetEnableSpellcheckAction { return { - type: SET_DISABLE_SPELLCHECK, + type: SET_ENABLE_SPELLCHECK, payload: { - disableSpellCheck, + enableSpellcheck, }, }; } @@ -102,11 +102,11 @@ export function setThemePref(themePref: ThemePref): SetThemePrefAction { // Thunks -export const updateDisableSpellCheckPref = (disableSpellCheck: boolean): ThunkActionT => ( +export const updateSpellcheckPref = (enableSpellcheck: boolean): ThunkActionT => ( dispatch, ): void => { - dispatch(setDisableSpellCheck(disableSpellCheck)); - saveDisableSpellCheckPref(disableSpellCheck); + dispatch(setEnableSpellcheck(enableSpellcheck)); + saveSpellcheckPref(enableSpellcheck); }; export const updateFutureEntriesPref = (allowFutureEntries: boolean): ThunkActionT => ( diff --git a/src/renderer/store/app/reducer.ts b/src/renderer/store/app/reducer.ts index 9e700843..7a883776 100644 --- a/src/renderer/store/app/reducer.ts +++ b/src/renderer/store/app/reducer.ts @@ -1,6 +1,6 @@ import { loadFirstDayOfWeekPref, - loadDisableSpellCheckPref, + loadSpellcheckPref, loadFutureEntriesPref, loadThemePref, loadHideTitlesPref, @@ -10,7 +10,7 @@ import { AppAction, AppState, SET_ALLOW_FUTURE_ENTRIES, - SET_DISABLE_SPELLCHECK, + SET_ENABLE_SPELLCHECK, SET_FIRST_DAY_OF_WEEK, SET_OVERLAY, SET_THEME, @@ -23,7 +23,7 @@ const theme = getThemeFromPref(themePref); const initialState: AppState = { allowFutureEntries: loadFutureEntriesPref(), - disableSpellCheck: loadDisableSpellCheckPref(), + enableSpellcheck: loadSpellcheckPref(), firstDayOfWeek: loadFirstDayOfWeekPref(), hideTitles: loadHideTitlesPref(), overlay: "none", @@ -39,10 +39,10 @@ function appReducer(state = initialState, action: AppAction): AppState { allowFutureEntries: action.payload.allowFutureEntries, }; } - case SET_DISABLE_SPELLCHECK: { + case SET_ENABLE_SPELLCHECK: { return { ...state, - disableSpellCheck: action.payload.disableSpellCheck, + enableSpellcheck: action.payload.enableSpellcheck, }; } case SET_HIDE_TITLES: { diff --git a/src/renderer/store/app/types.ts b/src/renderer/store/app/types.ts index 0a303edf..5533185d 100644 --- a/src/renderer/store/app/types.ts +++ b/src/renderer/store/app/types.ts @@ -7,7 +7,7 @@ import { Weekday, Theme, ThemePref } from "../../types"; export interface AppState { allowFutureEntries: boolean; - disableSpellCheck: boolean; + enableSpellcheck: boolean; firstDayOfWeek: Weekday | null; hideTitles: boolean; overlay: OverlayType; @@ -18,7 +18,7 @@ export interface AppState { // Action types export const SET_ALLOW_FUTURE_ENTRIES = "SET_ALLOW_FUTURE_ENTRIES"; -export const SET_DISABLE_SPELLCHECK = "SET_DISABLE_SPELLCHECK"; +export const SET_ENABLE_SPELLCHECK = "SET_ENABLE_SPELLCHECK"; export const SET_FIRST_DAY_OF_WEEK = "SET_FIRST_DAY_OF_WEEK"; export const SET_HIDE_TITLES = "SET_HIDE_TITLES"; export const SET_OVERLAY = "SET_OVERLAY"; @@ -34,10 +34,10 @@ export interface SetAllowFutureEntriesAction extends Action { }; } -export interface SetDisableSpellCheckAction extends Action { - type: typeof SET_DISABLE_SPELLCHECK; +export interface SetEnableSpellcheckAction extends Action { + type: typeof SET_ENABLE_SPELLCHECK; payload: { - disableSpellCheck: boolean; + enableSpellcheck: boolean; }; } @@ -78,7 +78,7 @@ export interface SetThemePrefAction extends Action { export type AppAction = | SetAllowFutureEntriesAction - | SetDisableSpellCheckAction + | SetEnableSpellcheckAction | SetFirstDayOfWeekAction | SetHideTitlesAction | SetOverlayAction diff --git a/src/shared/types.ts b/src/shared/types.ts index b86daa81..89721fcd 100644 --- a/src/shared/types.ts +++ b/src/shared/types.ts @@ -91,7 +91,7 @@ export interface Translations { "allow-future-entries": string; auto: string; "diary-entries": string; - "disable-spellcheck": string; + "enable-spellcheck": string; "first-day-of-week": string; "hide-titles": string; no: string; From d889625db610f5f63f23e3c817577b7dc6da9ac7 Mon Sep 17 00:00:00 2001 From: Samuel Meuli Date: Sat, 23 May 2020 17:50:29 +0200 Subject: [PATCH 5/5] Fix documentation comments --- src/renderer/files/preferences/preferences.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/renderer/files/preferences/preferences.ts b/src/renderer/files/preferences/preferences.ts index 9026bd10..a4f2805e 100644 --- a/src/renderer/files/preferences/preferences.ts +++ b/src/renderer/files/preferences/preferences.ts @@ -101,14 +101,14 @@ export function saveHideTitlesPref(hideTitles: boolean): void { // Spellcheck /** - * Return the preference for whether spell check should be disabled + * Return the preference for whether spellcheck should be enabled/disabled */ export function loadSpellcheckPref(): boolean { return getPref("enableSpellcheck", DEFAULT_ENABLE_SPELLCHECK); } /** - * Update the preference for disabling spell check + * Update the preference for enabling/disabling spellcheck */ export function saveSpellcheckPref(enableSpellcheck: boolean): void { setPref("enableSpellcheck", enableSpellcheck);