Skip to content

Commit

Permalink
feat: disable button when task is in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueBeret committed Feb 26, 2024
1 parent 8843a46 commit 56024c1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/app/dashboard/user/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default function Dashboard() {
const [totalPoint, setTotalPoint] = useState(0)
const [currentRank, setCurrentRank] = useState(0)
const [contributions, setContributions] = useState([])
const [isCalculating, setIsCalculating] = useState(false)

const calculatePoint = async (projects, month) => {
// month is year-mm
Expand All @@ -22,6 +23,8 @@ export default function Dashboard() {
return 0
}

setIsCalculating(true)

let loadingToast = toast.loading("Calculating your handsomeness")

let milestones_byproject = []
Expand Down Expand Up @@ -125,6 +128,7 @@ export default function Dashboard() {
toast.success("Dammn, you're so handsome", {
id: loadingToast
})
setIsCalculating(false)
}

useEffect(() => {
Expand Down Expand Up @@ -169,7 +173,7 @@ export default function Dashboard() {
</div>
</div>
</div>
<UserInput user={user} calculatePoint={calculatePoint} />
<UserInput user={user} calculatePoint={calculatePoint} isCalculating={isCalculating} />
<ContributionsSummary contributions={contributions} total_point={totalPoint} />
</main>
}
Expand Down Expand Up @@ -224,7 +228,7 @@ const ContributionsSummary = ({ contributions, setCurrentPoint, currentPoint, to
</div>
}

const UserInput = ({ user, calculatePoint }) => {
const UserInput = ({ user, calculatePoint, isCalculating }) => {
const [availableProjects, setAvailableProjects] = useState([
{
name: "Project 1",
Expand Down Expand Up @@ -308,7 +312,7 @@ const UserInput = ({ user, calculatePoint }) => {
})}
</div>

<button className="bg-pink-0 text-purple-100 py-2 px-4 rounded-md" onClick={(e) => calculatePoint(projects, month)}>Calculate</button>
<button className="bg-pink-0 text-purple-100 py-2 px-4 rounded-md" disabled={isCalculating} onClick={(e) => calculatePoint(projects, month)}>Calculate</button>
</div>
</div>
}

0 comments on commit 56024c1

Please sign in to comment.