Skip to content

Commit 8826f87

Browse files
authored
Merge pull request #20 from mmrakt/fix/ui
fix bug and refactor
2 parents 6246970 + 227d975 commit 8826f87

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+6187
-8845
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
name: Create tag if necessary
2121
id: daily-version
2222
- run: yarn
23-
- run: yarn b
23+
- run: yarn build
2424
- name: Update manifest.json
2525
run: |
2626
npx dot-json@1 build/manifest.json version ${{ steps.daily-version.outputs.version }}

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
"pomodoro-timer"
1919
],
2020
"scripts": {
21-
"d": "vite",
22-
"b": "tsc && vite build",
21+
"dev": "vite",
22+
"build": "tsc && vite build",
2323
"preview": "vite preview",
24-
"l": "eslint --fix './src/'",
25-
"t": "jest",
26-
"t:w": "jest --watch",
24+
"lint": "eslint --fix './src/'",
25+
"test": "jest",
26+
"test:watch": "jest --watch",
2727
"prepare": "husky install"
2828
},
2929
"dependencies": {
@@ -71,6 +71,7 @@
7171
"ts-node": "^10.9.1",
7272
"typescript": "*",
7373
"vite": "^4.4.7",
74+
"vite-tsconfig-paths": "^4.2.1",
7475
"zip-folder": "^1.0.0"
7576
},
7677
"husky": {

src/background/Action.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { COLOR } from '../consts/color'
2-
import { Phase } from '../types'
3-
import { action } from '../utils/chrome'
4-
import { getTimeFromSeconds, formatDisplayTime } from '../utils/timeHelper'
1+
import { COLOR } from '@/consts/color'
2+
import { Phase } from '@/types'
3+
import { action } from '@/utils/chrome'
4+
import { getTimeFromSeconds, formatDisplayTime } from '@/utils/timeHelper'
55

6-
const updateSecondsOfBadge = async (reminingSeconds: number): Promise<void> => {
7-
const { seconds, minutes } = getTimeFromSeconds(reminingSeconds)
6+
const updateSecondsOfBadge = async (
7+
remainingSeconds: number
8+
): Promise<void> => {
9+
const { seconds, minutes } = getTimeFromSeconds(remainingSeconds)
810
await action.setBadgeText({
911
text: formatDisplayTime(seconds, minutes)
1012
})

src/background/Notification.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import i18next from 'i18next'
2-
import { Phase } from '../types'
3-
import { notifications } from '../utils/chrome'
2+
import { Phase } from '@/types'
3+
import { notifications } from '@/utils/chrome'
44

55
const createNotificationContent = async (
66
phase: Phase,
77
todayPomodoro: number,
8-
reminingPomodorUntilLongBreak: number
8+
remainingPomodorUntilLongBreak: number
99
): Promise<string[]> => {
1010
let title = ''
1111
let message = ''
@@ -14,13 +14,13 @@ const createNotificationContent = async (
1414
message = i18next
1515
.t('notifications.pomodoro.message')
1616
.replace('%f', String(todayPomodoro))
17-
.replace('%s', String(reminingPomodorUntilLongBreak))
17+
.replace('%s', String(remainingPomodorUntilLongBreak))
1818
} else {
1919
title = i18next.t('notifications.break.title')
2020
message = i18next
2121
.t('notifications.break.message')
2222
.replace('%f', String(todayPomodoro))
23-
.replace('%s', String(reminingPomodorUntilLongBreak))
23+
.replace('%s', String(remainingPomodorUntilLongBreak))
2424
}
2525
return [title, message]
2626
}

src/background/Tab.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { EXPIRE_HTML_PATH } from '../consts'
2-
import { tabs, windows } from '../utils/chrome'
3-
import { EXPIRE_PAGE } from '../consts/index'
1+
import { EXPIRE_HTML_PATH } from '@/consts'
2+
import { tabs, windows } from '@/utils/chrome'
3+
import { EXPIRE_PAGE } from '@/consts/index'
44

55
const openNewTab = (): void => {
66
tabs.create(

src/background/Timer.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import dayjs from 'dayjs'
2-
import { StorageValue, Phase, DailyPomodoro, Message } from '../types'
3-
import { getStorage, runtime, setStorage } from '../utils/chrome'
2+
import { StorageValue, Phase, DailyPomodoro, Message } from '@/types'
3+
import { getStorage, runtime, setStorage } from '@/utils/chrome'
44
import { updateSecondsOfBadge, updateColorOfBadge } from './Action'
55
import { closeTabs, openNewTab } from './Tab'
66
import { createNotificationContent, sendNotification } from './Notification'
7-
import keepAlive from '../utils/keepAliveServiceWorker'
8-
import { FromServiceWorkerMessgeType } from '../utils/message'
9-
import { extractTodayPomodoroCount } from '../utils/pomodoroHelper'
7+
import keepAlive from '@/utils/keepAliveServiceWorker'
8+
import { FromServiceWorkerMessageType } from '@/utils/message'
9+
import { extractTodayPomodoroCount } from '@/utils/pomodoroHelper'
1010

1111
let intervalId = 0
1212

1313
const toggleTimerStatus = async (needSendMessage = false): Promise<void> => {
1414
await keepAlive()
1515

1616
getStorage([
17-
'reminingSeconds',
17+
'remainingSeconds',
1818
'phase',
1919
'isRunning',
2020
'totalPomodoroCountsInSession'
@@ -28,7 +28,7 @@ const toggleTimerStatus = async (needSendMessage = false): Promise<void> => {
2828
}
2929
if (needSendMessage) {
3030
await runtime.sendMessage<Message>({
31-
type: FromServiceWorkerMessgeType.TOGGLE_TIMER_STATUS,
31+
type: FromServiceWorkerMessageType.TOGGLE_TIMER_STATUS,
3232
data: {
3333
toggledTimerStatus: !data.isRunning
3434
}
@@ -53,12 +53,12 @@ const setTickInterval = (isRunning: boolean): void => {
5353
* カウントを減らすか終了させるか判定
5454
*/
5555
const handleCountDown = (): void => {
56-
getStorage(['reminingSeconds']).then(async (data: StorageValue) => {
57-
if (data.reminingSeconds > 0) {
58-
await reduceCount(data.reminingSeconds)
56+
getStorage(['remainingSeconds']).then(async (data: StorageValue) => {
57+
if (data.remainingSeconds > 0) {
58+
await reduceCount(data.remainingSeconds)
5959
}
6060

61-
if (data.reminingSeconds === 1) {
61+
if (data.remainingSeconds === 1) {
6262
const {
6363
phase,
6464
totalPomodoroCountsInSession,
@@ -80,14 +80,14 @@ const handleCountDown = (): void => {
8080
})
8181
}
8282

83-
const reduceCount = async (reminingSeconds: number): Promise<void> => {
83+
const reduceCount = async (remainingSeconds: number): Promise<void> => {
8484
try {
85-
setStorage({ reminingSeconds: reminingSeconds - 1 })
86-
await updateSecondsOfBadge(reminingSeconds - 1)
85+
setStorage({ remainingSeconds: remainingSeconds - 1 })
86+
await updateSecondsOfBadge(remainingSeconds - 1)
8787
await runtime.sendMessage<Message>({
88-
type: FromServiceWorkerMessgeType.REDUCE_COUNT,
88+
type: FromServiceWorkerMessageType.REDUCE_COUNT,
8989
data: {
90-
secs: reminingSeconds - 1
90+
secs: remainingSeconds - 1
9191
}
9292
})
9393
} catch (e) {
@@ -105,7 +105,7 @@ const expire = async (
105105
pomodorosUntilLongBreak: number,
106106
isAutoExpire = true
107107
): Promise<void> => {
108-
let reminingSeconds = 0
108+
let remainingSeconds = 0
109109
let nextPhase: Phase = 'focus'
110110

111111
try {
@@ -114,34 +114,34 @@ const expire = async (
114114
if (phase === 'focus') {
115115
totalPomodoroCountsInSession++
116116
if (totalPomodoroCountsInSession >= pomodorosUntilLongBreak) {
117-
reminingSeconds = await (
117+
remainingSeconds = await (
118118
await getStorage(['longBreakSeconds'])
119119
).longBreakSeconds
120120
totalPomodoroCountsInSession = 0
121121
nextPhase = 'longBreak'
122122
} else {
123-
reminingSeconds = await (
123+
remainingSeconds = await (
124124
await getStorage(['breakSeconds'])
125125
).breakSeconds
126126
nextPhase = 'break'
127127
}
128128
dailyPomodoros = increaseDailyPomodoro(dailyPomodoros)
129129
} else {
130-
reminingSeconds = await (
130+
remainingSeconds = await (
131131
await getStorage(['pomodoroSeconds'])
132132
).pomodoroSeconds
133133
}
134134
const todayTotalPomodoroCount = extractTodayPomodoroCount(dailyPomodoros)
135135

136136
setStorage({
137-
reminingSeconds,
137+
remainingSeconds,
138138
phase: nextPhase,
139139
totalPomodoroCountsInSession,
140140
isRunning: false,
141141
dailyPomodoros,
142142
isTimerStarted: false
143143
})
144-
await updateSecondsOfBadge(reminingSeconds)
144+
await updateSecondsOfBadge(remainingSeconds)
145145
await updateColorOfBadge(nextPhase)
146146

147147
if (isAutoExpire) {
@@ -188,9 +188,9 @@ const expire = async (
188188
setTickInterval(false)
189189
// popup非表示時はここで止まってしまうため最後に実行する
190190
await runtime.sendMessage<Message>({
191-
type: FromServiceWorkerMessgeType.EXPIRE,
191+
type: FromServiceWorkerMessageType.EXPIRE,
192192
data: {
193-
secs: reminingSeconds,
193+
secs: remainingSeconds,
194194
phase: nextPhase,
195195
todayTotalPomodoroCount,
196196
totalPomodoroCountsInSession,

src/background/__tests__/Timer.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import MockDate from 'mockdate'
22
import { chrome } from 'jest-chrome'
3-
// import { DEFAULT_TIMER_SECONDS } from '../../consts/index'
4-
import { expire } from '../Timer'
5-
import { Message } from '../../types/index'
6-
import { FromServiceWorkerMessgeType } from '../../utils/message'
7-
import { COLOR } from '../../consts/color'
3+
// import { DEFAULT_TIMER_SECONDS } from '@/consts/index'
4+
import { expire } from '@/background/Timer'
5+
import { Message } from '@/types/index'
6+
import { FromServiceWorkerMessageType } from '@/utils/message'
7+
import { COLOR } from '@/consts/color'
88

99
describe.skip('Timer', () => {
1010
beforeEach(() => {
@@ -42,7 +42,7 @@ describe.skip('Timer', () => {
4242

4343
it('finish first focus', async () => {
4444
const expectedSetValue = {
45-
reminingSeconds: 0, // TODO: getStorageのPromiseが解決されないままテストが終わる原因調査
45+
remainingSeconds: 0, // TODO: getStorageのPromiseが解決されないままテストが終わる原因調査
4646
phase: 'break',
4747
totalPomodoroCountsInSession: 1,
4848
isRunning: false,
@@ -58,7 +58,7 @@ describe.skip('Timer', () => {
5858
const pomodorosUntilLongBreak = 4
5959
const todayTotalPomodoroCount = 0
6060
const expectedOptions: Message = {
61-
type: FromServiceWorkerMessgeType.EXPIRE,
61+
type: FromServiceWorkerMessageType.EXPIRE,
6262
data: {
6363
secs: 0, // FIXME
6464
phase: expectedSetValue.phase,
@@ -87,7 +87,7 @@ describe.skip('Timer', () => {
8787

8888
it('finish first break', async () => {
8989
const expectedSetValue = {
90-
reminingSeconds: 0, // FIXME
90+
remainingSeconds: 0, // FIXME
9191
phase: 'focus',
9292
totalPomodoroCountsInSession: 1,
9393
isRunning: false,
@@ -103,7 +103,7 @@ describe.skip('Timer', () => {
103103
const pomodorosUntilLongBreak = 4
104104
const todayTotalPomodoroCount = 1
105105
const expectedOptions: Message = {
106-
type: FromServiceWorkerMessgeType.EXPIRE,
106+
type: FromServiceWorkerMessageType.EXPIRE,
107107
data: {
108108
secs: 0, // FIXME
109109
phase: expectedSetValue.phase,
@@ -144,7 +144,7 @@ describe.skip('Timer', () => {
144144

145145
it('start long break', async () => {
146146
const expectedSetValue = {
147-
reminingSeconds: 0, // FIXME
147+
remainingSeconds: 0, // FIXME
148148
phase: 'longBreak',
149149
totalPomodoroCountsInSession: 0,
150150
isRunning: false,
@@ -160,7 +160,7 @@ describe.skip('Timer', () => {
160160
const pomodorosUntilLongBreak = 4
161161
const todayTotalPomodoroCount = 3
162162
const expectedOptions = {
163-
type: FromServiceWorkerMessgeType.EXPIRE,
163+
type: FromServiceWorkerMessageType.EXPIRE,
164164
data: {
165165
secs: 0, // FIEXME
166166
phase: expectedSetValue.phase,
@@ -201,7 +201,7 @@ describe.skip('Timer', () => {
201201
it('長い休憩までのポモドーロ数を実施済みポモドーロ数以下に設定した場合。実施数3 長い休憩までのポモドーロ数4 変更後2', async () => {
202202
const changedPomodorosUntilLongBreak = 2
203203
const expectedSetValue = {
204-
reminingSeconds: 0, // FIXME
204+
remainingSeconds: 0, // FIXME
205205
phase: 'longBreak',
206206
totalPomodoroCountsInSession: 0,
207207
isRunning: false,
@@ -215,7 +215,7 @@ describe.skip('Timer', () => {
215215
]
216216
}
217217
const expectedOptions = {
218-
type: FromServiceWorkerMessgeType.EXPIRE,
218+
type: FromServiceWorkerMessageType.EXPIRE,
219219
data: {
220220
secs: 0, // FIXME
221221
phase: expectedSetValue.phase,

src/background/main.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import { StorageValue, Message } from '../types/index'
2-
import { runtime, getStorage, setStorage, commands } from '../utils/chrome'
3-
import '../utils/i18n'
1+
import { StorageValue, Message } from '@/types/index'
2+
import { runtime, getStorage, setStorage, commands } from '@/utils/chrome'
3+
import '@/utils/i18n'
44
import { closeTabs } from './Tab'
55
import { updateSecondsOfBadge, updateColorOfBadge } from './Action'
66
import { toggleTimerStatus, expire, pauseTimer, resumeTimer } from './Timer'
7-
import { DEFAULT_STORAGE_VALUE } from '../consts/index'
7+
import { DEFAULT_STORAGE_VALUE } from '@/consts/index'
88

99
// installed event
1010
runtime.onInstalled.addListener(async () => {
11-
getStorage(['reminingSeconds']).then((data) => {
12-
if (!data?.reminingSeconds) {
11+
getStorage(['remainingSeconds']).then((data) => {
12+
if (!data?.remainingSeconds) {
1313
setStorage(DEFAULT_STORAGE_VALUE)
1414
}
1515
})
1616

17-
await updateSecondsOfBadge(DEFAULT_STORAGE_VALUE.reminingSeconds)
17+
await updateSecondsOfBadge(DEFAULT_STORAGE_VALUE.remainingSeconds)
1818
await updateColorOfBadge(DEFAULT_STORAGE_VALUE.phase)
1919
})
2020

src/components/common/Break.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useContext } from 'react'
2-
import { COLOR } from '../../consts/color'
2+
import { COLOR } from '@/consts/color'
33
import { twMerge } from 'tailwind-merge'
4-
import { ThemeContext } from '../../providers/ThemeProvider'
4+
import { ThemeContext } from '@/providers/ThemeProvider'
55

66
const BreakIcon: React.FC<{ className?: string }> = ({ className = '' }) => {
77
const { theme } = useContext(ThemeContext)

src/components/common/Circle.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useEffect, useState, useContext } from 'react'
22
import LoadingSpinner from './LoadingSpinner'
3-
import { COLOR } from '../../consts/color'
4-
import { ThemeContext } from '../../providers/ThemeProvider'
3+
import { COLOR } from '@/consts/color'
4+
import { ThemeContext } from '@/providers/ThemeProvider'
55
import { twMerge } from 'tailwind-merge'
66

77
type IProps = {

0 commit comments

Comments
 (0)