mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 12:13:25 +00:00
add loading states to buttons
This commit is contained in:
@@ -96,7 +96,11 @@ export default function Page() {
|
|||||||
flexDirection="column"
|
flexDirection="column"
|
||||||
gap="$4"
|
gap="$4"
|
||||||
>
|
>
|
||||||
<MWButton type="purple" onPress={() => mutation.mutate()}>
|
<MWButton
|
||||||
|
type="purple"
|
||||||
|
onPress={() => mutation.mutate()}
|
||||||
|
isLoading={mutation.isPending}
|
||||||
|
>
|
||||||
Login
|
Login
|
||||||
</MWButton>
|
</MWButton>
|
||||||
{mutation.isError && (
|
{mutation.isError && (
|
||||||
|
@@ -95,7 +95,11 @@ export default function Page() {
|
|||||||
</Paragraph>
|
</Paragraph>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<MWButton type="purple" onPress={() => mutation.mutate()}>
|
<MWButton
|
||||||
|
type="purple"
|
||||||
|
onPress={() => mutation.mutate()}
|
||||||
|
isLoading={mutation.isPending}
|
||||||
|
>
|
||||||
Create account
|
Create account
|
||||||
</MWButton>
|
</MWButton>
|
||||||
</MWCard.Footer>
|
</MWCard.Footer>
|
||||||
|
@@ -94,14 +94,15 @@ export function AccountInformation() {
|
|||||||
<MWInput
|
<MWInput
|
||||||
type="authentication"
|
type="authentication"
|
||||||
value={decryptedName}
|
value={decryptedName}
|
||||||
minWidth={"80%"}
|
alignSelf="flex-start"
|
||||||
maxWidth={"80%"}
|
width="$14"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<MWButton
|
<MWButton
|
||||||
type="danger"
|
type="danger"
|
||||||
width={"50%"}
|
|
||||||
onPress={() => logoutMutation.mutate()}
|
onPress={() => logoutMutation.mutate()}
|
||||||
|
alignSelf="flex-start"
|
||||||
|
isLoading={logoutMutation.isPending}
|
||||||
>
|
>
|
||||||
Logout
|
Logout
|
||||||
</MWButton>
|
</MWButton>
|
||||||
@@ -133,6 +134,7 @@ export function AccountInformation() {
|
|||||||
{!device.current && (
|
{!device.current && (
|
||||||
<MWButton
|
<MWButton
|
||||||
type="danger"
|
type="danger"
|
||||||
|
isLoading={removeSessionMutation.isPending}
|
||||||
onPress={() => removeSessionMutation.mutate(device.id)}
|
onPress={() => removeSessionMutation.mutate(device.id)}
|
||||||
>
|
>
|
||||||
Remove
|
Remove
|
||||||
|
@@ -75,7 +75,12 @@ export function DeleteAccountAlert() {
|
|||||||
asChild
|
asChild
|
||||||
onPress={() => deleteAccountMutation.mutate()}
|
onPress={() => deleteAccountMutation.mutate()}
|
||||||
>
|
>
|
||||||
<MWButton type="purple">I am sure</MWButton>
|
<MWButton
|
||||||
|
type="purple"
|
||||||
|
isLoading={deleteAccountMutation.isPending}
|
||||||
|
>
|
||||||
|
I am sure
|
||||||
|
</MWButton>
|
||||||
</AlertDialog.Action>
|
</AlertDialog.Action>
|
||||||
</XStack>
|
</XStack>
|
||||||
</YStack>
|
</YStack>
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { Button, styled } from "tamagui";
|
import { Button, Spinner, styled, withStaticProperties } from "tamagui";
|
||||||
|
|
||||||
export const MWButton = styled(Button, {
|
const MWButtonFrame = styled(Button, {
|
||||||
variants: {
|
variants: {
|
||||||
type: {
|
type: {
|
||||||
primary: {
|
primary: {
|
||||||
@@ -71,3 +71,22 @@ export const MWButton = styled(Button, {
|
|||||||
},
|
},
|
||||||
} as const,
|
} as const,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const ButtonComponent = MWButtonFrame.styleable<{
|
||||||
|
isLoading?: boolean;
|
||||||
|
}>(function Button(props, ref) {
|
||||||
|
const spinnerColor =
|
||||||
|
// @ts-expect-error this is a hack to get the color from the variant
|
||||||
|
MWButtonFrame.staticConfig.variants?.type?.[props.type!]?.color as string;
|
||||||
|
return (
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||||
|
<MWButtonFrame {...props} ref={ref}>
|
||||||
|
{props.isLoading && (
|
||||||
|
<Spinner size="small" color={spinnerColor ?? "white"} />
|
||||||
|
)}
|
||||||
|
{props.children}
|
||||||
|
</MWButtonFrame>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
export const MWButton = withStaticProperties(ButtonComponent, {});
|
||||||
|
Reference in New Issue
Block a user