Skip to content
This repository has been archived by the owner on Jul 12, 2021. It is now read-only.

Add option for disabling spellcheck #87

Merged
merged 5 commits into from
May 23, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Allow disabling spellcheck
Owen-Krueger committed May 16, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 3c53222f3671e6ef2b2630b2832de6d530c54c38
1 change: 1 addition & 0 deletions src/main/i18n/translations/en.ts
Original file line number Diff line number Diff line change
@@ -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",
7 changes: 4 additions & 3 deletions src/renderer/components/elements/editor/editor/Editor.tsx
Original file line number Diff line number Diff line change
@@ -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<Props, State> {

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<Props, State> {
onBlur={this.saveEntry}
onChange={this.onTitleChange}
placeholder={translations["add-a-title"]}
spellCheck
spellCheck={!disableSpellCheck}
/>
</div>
)}
@@ -200,7 +201,7 @@ export default class Editor extends PureComponent<Props, State> {
}}
placeholder={isOl || isUl ? "" : `${translations["write-something"]}…`}
plugins={plugins}
spellCheck
spellCheck={!disableSpellCheck}
/>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -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,
Original file line number Diff line number Diff line change
@@ -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 {
<HideTitlesPrefContainer />
<br />
<FutureEntriesPrefContainer />
<br />
<DisableSpellCheckPrefContainer />
</div>
</fieldset>
);
Original file line number Diff line number Diff line change
@@ -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 (
<label htmlFor="checkbox-disable-spellcheck">
<input
type="checkbox"
name="checkbox-disable-spellcheck"
id="checkbox-disable-spellcheck"
checked={disableSpellCheck}
onChange={toggleDisableSpellCheck}
/>
{translations["disable-spellcheck"]}
</label>
);
}
Original file line number Diff line number Diff line change
@@ -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);
17 changes: 17 additions & 0 deletions src/renderer/files/preferences/preferences.ts
Original file line number Diff line number Diff line change
@@ -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

/**
19 changes: 19 additions & 0 deletions src/renderer/store/app/actionCreators.ts
Original file line number Diff line number Diff line change
@@ -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 => {
9 changes: 9 additions & 0 deletions src/renderer/store/app/reducer.ts
Original file line number Diff line number Diff line change
@@ -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,
10 changes: 10 additions & 0 deletions src/renderer/store/app/types.ts
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions src/shared/types.ts
Original file line number Diff line number Diff line change
@@ -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;