Skip to content

Commit

Permalink
chore(home): fix loading button
Browse files Browse the repository at this point in the history
  • Loading branch information
Ibrahimsyah committed Apr 16, 2024
1 parent 3503b94 commit 62de4a0
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/pages/home/dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ const Dashboard = () => {
})

const mutateState = (actuator_id: number, value: boolean) => {
if (mutationLoading[actuator_id]) {
return
}
const request: DispatchActionRequest = {
actuator_id,
device_id: 1,
Expand Down Expand Up @@ -183,6 +180,7 @@ const Dashboard = () => {
<Box sx={{ display: 'grid', gap: 2, mt: 2, gridTemplateColumns: '1fr 1fr' }}>
{actions.data?.map((action, index) => {
const state = actionStates[index]
const isLoading = state?.isLoading || mutationLoading[action.id]
return <ButtonCard
key={index}
id={index}
Expand All @@ -191,8 +189,8 @@ const Dashboard = () => {
on={state.data?.value || false}
onText={getActionValueText(action.type, true)}
offText={getActionValueText(action.type, false)}
isLoading={state?.isLoading || mutationLoading[action.id]}
onClick={() => mutateState(action.id, !state.data?.value)} />
isLoading={isLoading}
onClick={() => !isLoading ? mutateState(action.id, !state.data?.value) : {}} />
})}
</Box>
}
Expand Down

0 comments on commit 62de4a0

Please sign in to comment.