Skip to content

Commit 66c4861

Browse files
author
Pascal Wegner
authored
Merge pull request #132 from flextremedev/pwa-package
Pwa package
2 parents e49f53a + 1deace5 commit 66c4861

File tree

11 files changed

+116
-19
lines changed

11 files changed

+116
-19
lines changed

.circleci/config.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ jobs:
1818
steps:
1919
- checkout
2020
- run: yarn install
21-
- run: yarn web-test-coverage
22-
- run: yarn mobile-test-ci
21+
- run: yarn pwa test --runInBand --coverage
2322
- run: yarn core-test-ci
2423
- codecov/upload:
25-
file: packages/web/coverage/*.json
24+
file: packages/pwa/coverage/*.json
2625
workflows:
2726
version: 2
2827
test:

packages/pwa/.eslintrc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
{
2-
"extends": "@flextremedev/eslint-config-react-typescript"
2+
"root": true,
3+
"extends": "@flextremedev/eslint-config-react-typescript",
4+
"rules": {
5+
"@typescript-eslint/explicit-function-return-type": "warn"
6+
},
7+
"overrides": [
8+
{
9+
"files": ["src/pages/**/*.{ts,tsx}"],
10+
"rules": {
11+
"import/no-default-export": "off"
12+
}
13+
}
14+
]
315
}

packages/pwa/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"dev": "next dev",
77
"build": "next build",
88
"start": "next start",
9-
"test": "jest"
9+
"test": "jest",
10+
"lint": "eslint --quiet ./src/**/*.{ts,tsx}"
1011
},
1112
"dependencies": {
1213
"@interval-timer/core": "*",
@@ -32,6 +33,7 @@
3233
"eslint": "^8.7.0",
3334
"eslint-config-prettier": "^8.3.0",
3435
"eslint-plugin-import": "^2.25.4",
36+
"eslint-plugin-jsx-a11y": "^6.5.1",
3537
"eslint-plugin-prettier": "^4.0.0",
3638
"eslint-plugin-react": "^7.28.0",
3739
"eslint-plugin-react-hooks": "^4.3.0",

packages/pwa/src/__tests__/index.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { fireEvent, screen } from '@testing-library/react';
2+
23
import { MockWorker } from '../__mocks__/Worker';
34
import { expectCountDownFrom } from '../test-utils/expectCountDownFrom';
45
import { makeAdvanceDateNowBy } from '../test-utils/makeAdvanceDateNowBy';
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as React from 'react';
2+
3+
type ArcProps = React.SVGProps<SVGSVGElement> & {
4+
factor: number;
5+
};
6+
7+
export function Arc({ factor, ...restProps }: ArcProps) {
8+
return (
9+
<svg
10+
fill="none"
11+
xmlns="http://www.w3.org/2000/svg"
12+
viewBox="0 0 282 282"
13+
{...restProps}
14+
>
15+
<circle
16+
cx={141}
17+
cy={141}
18+
r={139}
19+
fill="#FBFCFE"
20+
stroke="#CDD9EE"
21+
strokeWidth={4}
22+
/>
23+
<path
24+
d="M280 141a138.998 138.998 0 01-237.288 98.288A139.01 139.01 0 012 141 138.997 138.997 0 01141 2a138.997 138.997 0 01139 139h0z"
25+
stroke="#0057FF"
26+
strokeWidth={4}
27+
className="origin-center -rotate-90"
28+
style={{ strokeDasharray: 877, strokeDashoffset: factor * 877 }}
29+
/>
30+
</svg>
31+
);
32+
}

packages/pwa/src/components/Counter/Counter.tsx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,40 @@
11
import * as React from 'react';
22

33
import { DurationInput } from '../DurationInput/DurationInput';
4+
import { Arc } from '../Arc/Arc';
5+
import { getMinutes, getSeconds } from 'date-fns';
46

57
type CounterProps = {
68
timeLeft: Date;
79
roundsLeft: number;
810
rounds: number;
11+
timeTotal: Date;
912
};
1013

11-
export function Counter({ timeLeft, roundsLeft, rounds }: CounterProps) {
14+
export function Counter({
15+
timeTotal,
16+
timeLeft,
17+
roundsLeft,
18+
rounds,
19+
}: CounterProps) {
20+
const factor =
21+
1 -
22+
(getSeconds(timeLeft) + getMinutes(timeLeft)) /
23+
(getSeconds(timeTotal) + getMinutes(timeTotal));
24+
1225
return (
13-
<div className="flex flex-col items-center">
14-
<div className="flex flex-col items-center mb-20">
26+
<div>
27+
<div className="flex flex-col items-center mb-20 z-[1]">
1528
<span className="text-blue-600 text-lg font-bold">ROUND</span>
1629
<span className="text-4xl" data-testid={'round'}>{`${
1730
rounds - roundsLeft
1831
}/${rounds}`}</span>
1932
</div>
20-
<div className="">
21-
<div className=""></div>
22-
<DurationInput value={timeLeft} readOnly dataTestId={'time-left'} />
33+
<div className="flex flex-col justify-center items-center relative w-72 h-72">
34+
<Arc className="absolute origin-center" factor={factor} />
35+
<div className="z-[1]">
36+
<DurationInput value={timeLeft} readOnly dataTestId={'time-left'} />
37+
</div>
2338
</div>
2439
</div>
2540
);

packages/pwa/src/hooks/useAudio.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const useAudio = (url: string) => {
22
/* istanbul ignore next */
3-
if (typeof window === undefined) {
3+
if (typeof window === 'undefined') {
44
return { audio: undefined };
55
}
66

packages/pwa/src/pages/index.tsx

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,34 @@
1-
import { FormFields } from '../components/FormFields/FormFields';
21
import { timerMachine, timerStates } from '@interval-timer/core';
32
import { useMachine } from '@xstate/react';
43
import * as React from 'react';
4+
import { StateValue } from 'xstate';
5+
56
import { Counter } from '../components/Counter/Counter';
7+
import { FormFields } from '../components/FormFields/FormFields';
68
import { useBeep } from '../hooks/useBeep';
79

10+
const getActiveTimeTotal = ({
11+
breakInterval,
12+
prepareTime,
13+
value,
14+
workInterval,
15+
}: {
16+
value: StateValue;
17+
breakInterval: Date;
18+
workInterval: Date;
19+
prepareTime: Date;
20+
}) => {
21+
if (value === timerStates.WORK) {
22+
return workInterval;
23+
}
24+
25+
if (value === timerStates.BREAK) {
26+
return breakInterval;
27+
}
28+
29+
return prepareTime;
30+
};
31+
832
export default function Home() {
933
const { beepBreak, beepBreakLong, beepWork, beepWorkLong } = useBeep();
1034
const [state, send, service] = useMachine(timerMachine, {
@@ -72,15 +96,21 @@ export default function Home() {
7296
});
7397
};
7498

75-
const { breakInterval, rounds, workInterval, timeLeft, roundsLeft } =
76-
state.context;
99+
const {
100+
breakInterval,
101+
rounds,
102+
workInterval,
103+
timeLeft,
104+
roundsLeft,
105+
prepareTime,
106+
} = state.context;
77107

78108
return (
79109
<>
80110
<header />
81111
<main className="flex-1">
82112
<div className="h-full flex flex-col items-stretch bg-blue-600">
83-
<div className="flex flex-col justify-center flex-1 bg-white rounded-b-3xl">
113+
<div className="flex flex-col justify-center items-center flex-1 bg-white rounded-b-3xl">
84114
{state.value === timerStates.STOPPED ? (
85115
<FormFields
86116
rounds={rounds}
@@ -92,6 +122,12 @@ export default function Home() {
92122
></FormFields>
93123
) : (
94124
<Counter
125+
timeTotal={getActiveTimeTotal({
126+
breakInterval,
127+
prepareTime,
128+
value: state.value,
129+
workInterval,
130+
})}
95131
timeLeft={timeLeft}
96132
roundsLeft={roundsLeft}
97133
rounds={rounds}

packages/pwa/src/test-utils/expectCountDownFrom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const expectCountDownFrom = ({
2929
minutesLeft >= 1 || (firstRound && minutesLeft <= 0);
3030

3131
for (let minutesLeft = minutes; minutesLeft >= toMinutes; minutesLeft--) {
32-
let secondsToCountInMinute = shouldDisplayInitialSeconds(minutesLeft)
32+
const secondsToCountInMinute = shouldDisplayInitialSeconds(minutesLeft)
3333
? seconds
3434
: 59;
3535

packages/pwa/src/test-utils/renderApp.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { render, screen } from '@testing-library/react';
12
import * as React from 'react';
23

3-
import { render, screen } from '@testing-library/react';
44
import Home from '../pages/index';
55

66
export const renderApp = () => {

0 commit comments

Comments
 (0)