Skip to content

Commit 2ce88fc

Browse files
authored
Merge pull request #82 from flextremedev/add-mobile-package
Add mobile package
2 parents 4ddd29a + ec08e39 commit 2ce88fc

33 files changed

+11645
-176
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"typescript.tsdk": "node_modules/typescript/lib"
3+
}

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"scripts": {
99
"core-test": "yarn workspace @interval-timer/core run test",
1010
"core-test-coverage": "yarn workspace @interval-timer/core run test --runInBand --coverage",
11+
"mobile": "yarn workspace @interval-timer/mobile start",
1112
"web": "yarn workspace @interval-timer/web run start",
1213
"web-build": "yarn workspace @interval-timer/web run build",
1314
"web-lint": "yarn workspace @interval-timer/web run lint:fix",
@@ -25,9 +26,16 @@
2526
"eslint-config-prettier": "^7.0.0",
2627
"eslint-plugin-import": "^2.22.1",
2728
"eslint-plugin-prettier": "^3.3.1",
29+
"expo-yarn-workspaces": "^1.3.1",
2830
"husky": "^3.0.5",
2931
"lint-staged": "^9.2.5",
3032
"prettier": "^2.2.1",
3133
"typescript": "^4.2.3"
34+
},
35+
"resolutions": {
36+
"babel-jest": "^26.0.0",
37+
"react": "^17.0.0",
38+
"react-dom": "^17.0.0",
39+
"webpack": "~4.44.0"
3240
}
3341
}

packages/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"@flextremedev/eslint-config-typescript": "^0.1.1"
1313
},
1414
"dependencies": {
15+
"@xstate/react": "^0.8.1",
1516
"xstate": "^4.17.1"
1617
}
1718
}

packages/core/src/hooks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { useTimerMachine } from './useTimerMachine';
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* istanbul ignore file */
2+
/* covered by app integration test */
3+
import { useMachine } from '@xstate/react';
4+
5+
import { timerMachine } from '../machine/timerMachine';
6+
import { timerStates } from '../model/timerStates';
7+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
8+
export const useTimerMachine = () => {
9+
const [state, send, service] = useMachine(timerMachine);
10+
11+
const toggleTimer = (): void => {
12+
if (state.value === timerStates.STOPPED) {
13+
send('START');
14+
} else {
15+
send('STOP');
16+
}
17+
};
18+
19+
const setRounds = (rounds: string): void => {
20+
send({ type: 'SET_ROUNDS', rounds: Number(rounds) });
21+
};
22+
23+
const setWorkInterval = (workInterval: Date): void => {
24+
send({
25+
type: 'SET_WORK_INTERVAL',
26+
workInterval,
27+
});
28+
};
29+
30+
const setBreakInterval = (breakInterval: Date): void => {
31+
send({
32+
type: 'SET_BREAK_INTERVAL',
33+
breakInterval,
34+
});
35+
};
36+
37+
return Object.freeze({
38+
state,
39+
send,
40+
service,
41+
setBreakInterval,
42+
setRounds,
43+
setWorkInterval,
44+
toggleTimer,
45+
});
46+
};

packages/core/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
export { hasOneSecondElapsed } from './utils/hasOneSecondElapsed';
1+
export * from './hooks';
2+
export * from './utils';
23
export { timerMachine } from './machine/timerMachine';
34
export * from './machine/types';
45
export { timerStates } from './model/timerStates';

packages/core/src/machine/timerMachine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* istanbul ignore file */
22
/* covered by app integration test */
3-
import { hasOneSecondElapsed } from '@interval-timer/core';
43
import { getMinutes, getSeconds, subSeconds } from 'date-fns';
54
import { assign, createMachine, send } from 'xstate';
65

76
import { timerStates } from '../model/timerStates';
7+
import { hasOneSecondElapsed } from '../utils';
88

99
import {
1010
SetBreakIntervalEvent,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { toTwoDigitString } from '../toTwoDigitString';
2+
3+
describe('toTwoDigitString()', () => {
4+
it('should return two digit string', () => {
5+
expect(toTwoDigitString(3)).toBe('03');
6+
expect(toTwoDigitString(30)).toBe('30');
7+
});
8+
});

packages/core/src/utils/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { hasOneSecondElapsed } from './hasOneSecondElapsed';
2+
export { toTwoDigitString } from './toTwoDigitString';
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const toTwoDigitString = (value: number): string =>
2+
value < 10 ? `0${value}` : String(value);

0 commit comments

Comments
 (0)