Skip to content

Commit

Permalink
fix: disable/enable voice assistance in settings tab #108
Browse files Browse the repository at this point in the history
  • Loading branch information
roldanjr committed Jul 30, 2020
1 parent 9ffc844 commit 86aea7c
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 16 deletions.
19 changes: 10 additions & 9 deletions app/src/contexts/CounterContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,26 +235,26 @@ const CounterProvider: React.FC = ({ children }) => {
notification(
"60 Seconds Left for Short Break",
{ body: "Please prepare yourself getting back to work." },
sixtySecondsLeftShortBreak
settings.enableVoiceAssistance && sixtySecondsLeftShortBreak
);
} else if (timer.timerType === LONG_BREAK) {
notification(
"60 Seconds Left for Long Break",
{ body: "Please prepare yourself getting back to work." },
sixtySecondsLeftLongBreak
settings.enableVoiceAssistance && sixtySecondsLeftLongBreak
);
} else if (timer.timerType === SPECIAL_BREAK) {
notification(
"60 Seconds Left for Special Break",
{ body: "Please prepare yourself getting back to work." },
sixtySecondsLeftSpecialBreak
settings.enableVoiceAssistance && sixtySecondsLeftSpecialBreak
);
}
} else if (count === 31 && timer.timerType === STAY_FOCUS) {
notification(
"30 Seconds Left to Work",
{ body: "Please pause all media playing if there's one." },
thirtySecondsLeftToWork
settings.enableVoiceAssistance && thirtySecondsLeftToWork
);
}
}
Expand All @@ -267,7 +267,7 @@ const CounterProvider: React.FC = ({ children }) => {
notification(
"Work Time Finished",
{ body: "It is time to take a short break." },
shortBreakStart
settings.enableVoiceAssistance && shortBreakStart
);

dispatch(setTimerType("SHORT_BREAK"));
Expand All @@ -277,7 +277,7 @@ const CounterProvider: React.FC = ({ children }) => {
notification(
"Session Rounds Completed",
{ body: "It is time to take a long break." },
longBreakStart
settings.enableVoiceAssistance && longBreakStart
);

dispatch(setTimerType("LONG_BREAK"));
Expand All @@ -290,7 +290,7 @@ const CounterProvider: React.FC = ({ children }) => {
notification(
"Short Break Finished",
{ body: "It is time to focus and work again." },
shortBreakFinished
settings.enableVoiceAssistance && shortBreakFinished
);

dispatch(setTimerType("STAY_FOCUS"));
Expand All @@ -307,7 +307,7 @@ const CounterProvider: React.FC = ({ children }) => {
notification(
"Long Break Finished",
{ body: "It is time to focus and work again." },
longBreakFinished
settings.enableVoiceAssistance && longBreakFinished
);

dispatch(setTimerType("STAY_FOCUS"));
Expand All @@ -324,7 +324,7 @@ const CounterProvider: React.FC = ({ children }) => {
notification(
"Special Break Finished",
{ body: "It is time to focus and work again." },
specialBreakFinished
settings.enableVoiceAssistance && specialBreakFinished
);

dispatch(setTimerType("STAY_FOCUS"));
Expand All @@ -346,6 +346,7 @@ const CounterProvider: React.FC = ({ children }) => {
config.sessionRounds,
settings.notificationProperty,
settings.autoStartWorkTime,
settings.enableVoiceAssistance,
]);

useEffect(() => {
Expand Down
12 changes: 7 additions & 5 deletions app/src/hooks/useNotification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ export const useNotification = (
// Making sure that notification sound the same
// in all Operating System

new Audio(bell).play();
if (!constantOptions?.mute) {
new Audio(bell).play();

if (audioSrc && !constantOptions?.mute) {
setTimeout(() => {
new Audio(audioSrc).play();
}, 1500);
if (audioSrc) {
setTimeout(() => {
new Audio(audioSrc).play();
}, 1500);
}
}

if (!notify) return;
Expand Down
13 changes: 11 additions & 2 deletions app/src/routes/Settings/FeatureSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import {
setAutoStartWorkTime,
setMinimizeToTray,
setCloseToTray,
setEnableVoiceAssistance,
} from "store";

import { Toggler, TogglerProps, Collapse, Radio } from "components";
import SettingSection from "./SettingSection";
import { ThemeContext } from "contexts";

import SettingSection from "./SettingSection";

const FeatureSection: React.FC = () => {
const settings: SettingTypes = useSelector(
(state: AppStateTypes) => state.settings
Expand Down Expand Up @@ -102,6 +103,14 @@ const FeatureSection: React.FC = () => {
dispatch(setCloseToTray(!settings.closeToTray));
}, [dispatch, settings.closeToTray]),
},
{
id: "voice-assistance",
label: "Voice Assistance",
checked: settings.enableVoiceAssistance,
onChange: useCallback(() => {
dispatch(setEnableVoiceAssistance(!settings.enableVoiceAssistance));
}, [dispatch, settings.enableVoiceAssistance]),
},
];

const onChangeNotificationProps = useCallback(
Expand Down
10 changes: 10 additions & 0 deletions app/src/store/settings/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
CLOSE_TO_TRAY,
MINIMIZE_TO_TRAY,
AUTO_START_WORK_TIME,
ENABLE_VOICE_ASSISTANCE,
} from "./types";

export const setAlwaysOnTop = (
Expand Down Expand Up @@ -66,6 +67,15 @@ export const setEnableProgressAnimation = (
};
};

export const setEnableVoiceAssistance = (
enableVoiceAssistance: SettingTypes["enableVoiceAssistance"]
): SettingActionTypes => {
return {
type: ENABLE_VOICE_ASSISTANCE,
payload: enableVoiceAssistance,
};
};

export const setUseNativeTitlebar = (
useNativeTitlebar: SettingTypes["useNativeTitlebar"]
): SettingActionTypes => {
Expand Down
7 changes: 7 additions & 0 deletions app/src/store/settings/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
CLOSE_TO_TRAY,
MINIMIZE_TO_TRAY,
AUTO_START_WORK_TIME,
ENABLE_VOICE_ASSISTANCE,
} from "./types";

const defaultSettings: SettingTypes = {
Expand All @@ -22,6 +23,7 @@ const defaultSettings: SettingTypes = {
enableStrictMode: false,
enableDarkTheme: isPreferredDark(),
enableProgressAnimation: true,
enableVoiceAssistance: true,
notificationSoundOn: true,
notificationProperty: "extra",
closeToTray: true,
Expand Down Expand Up @@ -71,6 +73,11 @@ export const settingReducer = (
...state,
enableProgressAnimation: action.payload,
};
case ENABLE_VOICE_ASSISTANCE:
return {
...state,
enableVoiceAssistance: action.payload,
};
case USE_NATIVE_TITLE_BAR:
return {
...state,
Expand Down
2 changes: 2 additions & 0 deletions app/src/store/settings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type SettingTypes = {
enableDarkTheme: boolean;
enableStrictMode: boolean;
enableProgressAnimation: boolean;
enableVoiceAssistance: boolean;
useNativeTitlebar: boolean;
notificationSoundOn: boolean;
closeToTray: boolean;
Expand All @@ -21,6 +22,7 @@ export const ENABLE_FULLSCREEN_BREAK = `${settings} ENABLE_FULLSCREEN_BREAK`;
export const ENABLE_STRICT_MODE = `${settings} ENABLE_STRICT_MODE`;

export const ENABLE_PROGRESS_ANIMATION = `${settings} ENABLE_PROGRESS_ANIMATION`;
export const ENABLE_VOICE_ASSISTANCE = `${settings} ENABLE_VOICE_ASSISTANCE`;

export const USE_NATIVE_TITLE_BAR = `${settings} USE_NATIVE_TITLE_BAR`;
export const ENABLE_AUTO_UPDATES = `${settings} ENABLE_AUTO_UPDATES`;
Expand Down

0 comments on commit 86aea7c

Please sign in to comment.