-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from tainakanchu/develop
- Loading branch information
Showing
11 changed files
with
159 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./useAccuracyColor"; | ||
export * from "./useBpmCalculator"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from "react"; | ||
|
||
/** | ||
* 値の正確度に応じた色を返す | ||
*/ | ||
export const useAccuracyColor = (sd: number): string => { | ||
// 5刻みぐらいで色を変える | ||
const bpmColor = React.useMemo(() => { | ||
if (sd < 30) { | ||
return "text-green-500"; | ||
} else if (sd < 35) { | ||
return "text-green-400"; | ||
} else if (sd < 40) { | ||
return "text-green-300"; | ||
} else if (sd < 45) { | ||
return "text-yellow-200"; | ||
} else if (sd < 50) { | ||
return "text-yellow-100"; | ||
} else if (sd < 55) { | ||
return "text-red-100"; | ||
} else if (sd < 60) { | ||
return "text-red-200"; | ||
} else if (sd < 65) { | ||
return "text-red-300"; | ||
} else if (sd < 70) { | ||
return "text-red-400"; | ||
} else { | ||
return "text-red-500"; | ||
} | ||
}, [sd]); | ||
|
||
return bpmColor; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from "react"; | ||
import { calculateBpm } from "../_utils"; | ||
import { BpmConvertSetting } from "../_types/BpmConvertSetting"; | ||
|
||
/** | ||
* BPMを計算するフック | ||
* | ||
* @param setting BPMを変換する設定 | ||
* @returns BPMを計算するフック | ||
*/ | ||
export const useBpmCalculator = (setting: { | ||
bpmConvertSettings: BpmConvertSetting[]; | ||
}) => { | ||
const [dateList, setDateList] = React.useState<Date[]>([]); | ||
|
||
const handleAddTimeData = React.useCallback(() => { | ||
setDateList((dateList) => [...dateList, new Date()]); | ||
}, []); | ||
|
||
const handleClearTimeData = React.useCallback(() => { | ||
setDateList([]); | ||
}, []); | ||
|
||
const bpm = React.useMemo(() => { | ||
return calculateBpm(dateList); | ||
}, [dateList]); | ||
|
||
const convertedBpmList = React.useMemo(() => { | ||
return setting.bpmConvertSettings.map((setting) => { | ||
const label: string = `${setting.numerator}/${setting.denominator}`; | ||
return { | ||
label, | ||
value: bpm.value | ||
? (bpm.value * setting.numerator) / setting.denominator | ||
: null, | ||
}; | ||
}); | ||
}, [bpm.value, setting]); | ||
|
||
return { | ||
handleAddTimeData, | ||
handleClearTimeData, | ||
bpm, | ||
convertedBpmList, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* BPMを変換する設定 | ||
*/ | ||
export type BpmConvertSetting = { | ||
/** 分子 */ | ||
denominator: number; | ||
/** 分母 */ | ||
numerator: number; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from "./bpmCalculator"; | ||
export * from "./calculateBpm"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters