/
calculator.js
60 lines (50 loc) · 1.69 KB
/
calculator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import React, { useState, useEffect } from 'react';
const CalculatorPage = () => {
const [followerCount, setFollowerCount] = useState('');
const [avgLikes, setAvgLikes] = useState('');
const [result, setResult] = useState(null);
const handleSubmit = (e) => {
e.preventDefault();
// Calculate the Expertise Fair Price Cap
const expertiseFairPriceCap = Math.round(followerCount * (avgLikes / 2500) + followerCount * 0.01);
// Calculate the Influence Fair Price Cap
const influenceFairPriceCap = Math.round(followerCount * (avgLikes / 4000) + followerCount * 0.006);
// Set the result
setResult({
expertiseFairPriceCap,
influenceFairPriceCap,
});
};
useEffect(() => {
if (result) {
const rangePercentage = (result.expertiseFairPriceCap / result.influenceFairPriceCap) * 100;
const end = Math.round(rangePercentage);
const indicatorEnd = end > 0 ? end : 1;
setResult((prevState) => ({ ...prevState, indicatorEnd }));
}
}, [result]);
return (
<div>
<form onSubmit={handleSubmit}>
<label htmlFor="followerCount">Follower count</label>
<input
type="number"
id="followerCount"
value={followerCount}
onChange={(e) => setFollowerCount(Number(e.target.value))}
required
/>
<label htmlFor="avgLikes">Average likes per tweet</label>
<input
type="number"
id="avgLikes"
value={avgLikes}
onChange={(e) => setAvgLikes(Number(e.target.value))}
required
/>
<button type="submit">Calculate</button>
</form>
</div>
);
};
export default CalculatorPage;