Skip to content

Commit

Permalink
LoadingButtonSpinner component
Browse files Browse the repository at this point in the history
  • Loading branch information
fjsj committed Feb 4, 2025
1 parent 7f9e511 commit 28a31b4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
5 changes: 3 additions & 2 deletions components/ChatHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { ChevronLeftIcon, TrashIcon, UserRound, XIcon } from "lucide-react-nativ
import { useMemo } from "react";
import { View } from "react-native";

import { LoadingButtonSpinner } from "@/components/LoadingButtonSpinner";
import { Avatar, AvatarImage } from "@/components/ui/avatar";
import { Button, ButtonIcon, ButtonSpinner, ButtonText } from "@/components/ui/button";
import { Button, ButtonIcon, ButtonText } from "@/components/ui/button";
import { Icon } from "@/components/ui/icon";
import { Pressable } from "@/components/ui/pressable";
import { Text } from "@/components/ui/text";
Expand Down Expand Up @@ -118,7 +119,7 @@ export function ChatHeader({
className="mr-2"
>
{isDeleting ? (
<ButtonSpinner />
<LoadingButtonSpinner />
) : (
<>
<ButtonIcon as={TrashIcon} size="sm" />
Expand Down
7 changes: 3 additions & 4 deletions components/ChatMessageBubble.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { useMedplumProfile } from "@medplum/react-hooks";
import { useVideoPlayer } from "expo-video";
import { VideoView } from "expo-video";
import { CirclePlay, FileDown, UserRound } from "lucide-react-native";
import { useColorScheme } from "nativewind";
import { memo, useCallback, useRef, useState } from "react";
import { Pressable, StyleSheet, View } from "react-native";
import { Alert } from "react-native";

import { FullscreenImage } from "@/components/FullscreenImage";
import { LoadingButtonSpinner } from "@/components/LoadingButtonSpinner";
import { Avatar, AvatarImage } from "@/components/ui/avatar";
import { Button, ButtonIcon, ButtonSpinner, ButtonText } from "@/components/ui/button";
import { Button, ButtonIcon, ButtonText } from "@/components/ui/button";
import { Icon } from "@/components/ui/icon";
import { Text } from "@/components/ui/text";
import type { ChatMessage } from "@/models/chat";
Expand Down Expand Up @@ -85,7 +85,6 @@ VideoAttachment.displayName = "VideoAttachment";

function FileAttachment({ attachment }: { attachment: AttachmentWithUrl }) {
const [isDownloading, setIsDownloading] = useState(false);
const { colorScheme } = useColorScheme();

const handleShare = useCallback(async () => {
setIsDownloading(true);
Expand All @@ -106,7 +105,7 @@ function FileAttachment({ attachment }: { attachment: AttachmentWithUrl }) {
disabled={isDownloading}
>
{isDownloading ? (
<ButtonSpinner color={colorScheme === "dark" ? "black" : "white"} />
<LoadingButtonSpinner />
) : (
<ButtonIcon as={FileDown} className="text-typography-100" />
)}
Expand Down
11 changes: 3 additions & 8 deletions components/CreateThreadModal.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useRouter } from "expo-router";
import { useColorScheme } from "nativewind";
import { useState } from "react";

import { LoadingButtonSpinner } from "@/components/LoadingButtonSpinner";
import { Modal, ModalBody, ModalFooter, ModalHeader } from "@/components/Modal";
import { Button, ButtonSpinner, ButtonText } from "@/components/ui/button";
import { Button, ButtonText } from "@/components/ui/button";
import { Input, InputField } from "@/components/ui/input";
import { View } from "@/components/ui/view";

Expand All @@ -16,7 +16,6 @@ interface CreateThreadModalProps {
export function CreateThreadModal({ isOpen, onClose, onCreateThread }: CreateThreadModalProps) {
const [topic, setTopic] = useState("");
const [isCreating, setIsCreating] = useState(false);
const { colorScheme } = useColorScheme();
const router = useRouter();

const handleCreate = async () => {
Expand Down Expand Up @@ -55,11 +54,7 @@ export function CreateThreadModal({ isOpen, onClose, onCreateThread }: CreateThr
<ButtonText>Cancel</ButtonText>
</Button>
<Button className="min-w-[100px]" disabled={!isValid || isCreating} onPress={handleCreate}>
{isCreating ? (
<ButtonSpinner color={colorScheme === "dark" ? "black" : "white"} />
) : (
<ButtonText>Create</ButtonText>
)}
{isCreating ? <LoadingButtonSpinner /> : <ButtonText>Create</ButtonText>}
</Button>
</ModalFooter>
</Modal>
Expand Down
17 changes: 17 additions & 0 deletions components/LoadingButtonSpinner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useColorScheme } from "nativewind";

import { ButtonSpinner } from "@/components/ui/button";

interface LoadingButtonSpinnerProps {
/**
* Optional override for spinner color. If not provided, will use white for light mode and black for dark mode
*/
color?: string;
}

export function LoadingButtonSpinner({ color }: LoadingButtonSpinnerProps) {
const { colorScheme } = useColorScheme();
const spinnerColor = color ?? (colorScheme === "dark" ? "black" : "white");

return <ButtonSpinner color={spinnerColor} />;
}

0 comments on commit 28a31b4

Please sign in to comment.