refactor(scanner): added toasts in to make it look better
All checks were successful
Build and Push LST Docker Image / docker (push) Successful in 1m25s
All checks were successful
Build and Push LST Docker Image / docker (push) Successful in 1m25s
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import axios from "axios";
|
||||
import { format } from "date-fns-tz";
|
||||
import { useFocusEffect } from "expo-router";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { Alert, Button, Text, View } from "react-native";
|
||||
import { useAppStore } from "../hooks/useAppStore";
|
||||
@@ -90,7 +91,9 @@ export default function LSTScanner() {
|
||||
user: user?.name ?? "prodScan",
|
||||
runningNumber: scan.data.startsWith("000")
|
||||
? parseInt(scan.data.slice(10, -1) || "000", 10).toString()
|
||||
: "0",
|
||||
: scan.data.startsWith("loc")
|
||||
? scan.data
|
||||
: "0",
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
@@ -153,20 +156,21 @@ export default function LSTScanner() {
|
||||
|
||||
//console.log(lastScan);
|
||||
|
||||
useEffect(() => {
|
||||
zebraScanner.ensureProfile();
|
||||
zebraScanner.startListening();
|
||||
useFocusEffect(
|
||||
useCallback(() => {
|
||||
zebraScanner.startListening();
|
||||
|
||||
const sub = zebraScanner.addScanListener((scan) => {
|
||||
//console.log("SCAN:", scan);
|
||||
handleScan(scan);
|
||||
});
|
||||
const sub = zebraScanner.addScanListener((scan) => {
|
||||
//console.log("SCAN:", scan);
|
||||
handleScan(scan);
|
||||
});
|
||||
|
||||
return () => {
|
||||
sub.remove();
|
||||
zebraScanner.stopListening();
|
||||
};
|
||||
}, [handleScan]);
|
||||
return () => {
|
||||
sub.remove();
|
||||
zebraScanner.stopListening();
|
||||
};
|
||||
}, [handleScan]),
|
||||
);
|
||||
return (
|
||||
<View className={`${bgColor ?? ""} flex-1 w-screen`}>
|
||||
<View style={{ alignItems: "center", margin: 5 }}>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import axios from "axios";
|
||||
import { format } from "date-fns-tz";
|
||||
import { useFocusEffect } from "expo-router";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { Text, View } from "react-native";
|
||||
import { useAppStore } from "../hooks/useAppStore";
|
||||
@@ -58,7 +59,9 @@ export default function ProdScanner() {
|
||||
...scanned.data,
|
||||
runningNumber: scan.data.startsWith("000")
|
||||
? parseInt(scan.data.slice(10, -1) || "000", 10).toString()
|
||||
: "0",
|
||||
: scan.data.startsWith("loc")
|
||||
? scan.data
|
||||
: "0",
|
||||
};
|
||||
try {
|
||||
await axios.post(
|
||||
@@ -118,20 +121,21 @@ export default function ProdScanner() {
|
||||
|
||||
//console.log(lastScan);
|
||||
|
||||
useEffect(() => {
|
||||
zebraScanner.ensureProfile();
|
||||
zebraScanner.startListening();
|
||||
useFocusEffect(
|
||||
useCallback(() => {
|
||||
zebraScanner.startListening();
|
||||
|
||||
const sub = zebraScanner.addScanListener((scan) => {
|
||||
//console.log("SCAN:", scan);
|
||||
handleScan(scan);
|
||||
});
|
||||
const sub = zebraScanner.addScanListener((scan) => {
|
||||
//console.log("SCAN:", scan);
|
||||
handleScan(scan);
|
||||
});
|
||||
|
||||
return () => {
|
||||
sub.remove();
|
||||
zebraScanner.stopListening();
|
||||
};
|
||||
}, [handleScan]);
|
||||
return () => {
|
||||
sub.remove();
|
||||
zebraScanner.stopListening();
|
||||
};
|
||||
}, [handleScan]),
|
||||
);
|
||||
return (
|
||||
<View className={`${bgColor ?? ""} flex-1 w-screen`}>
|
||||
<View>
|
||||
|
||||
140
lstMobile/src/components/ui/dialog.tsx
Normal file
140
lstMobile/src/components/ui/dialog.tsx
Normal file
@@ -0,0 +1,140 @@
|
||||
import { Icon } from '@/components/ui/icon';
|
||||
import { NativeOnlyAnimatedView } from '@/components/ui/native-only-animated-view';
|
||||
import { cn } from '@/lib/utils';
|
||||
import * as DialogPrimitive from '@rn-primitives/dialog';
|
||||
import { X } from 'lucide-react-native';
|
||||
import * as React from 'react';
|
||||
import { Platform, Text, View, type ViewProps } from 'react-native';
|
||||
import { FadeIn, FadeOut } from 'react-native-reanimated';
|
||||
import { FullWindowOverlay as RNFullWindowOverlay } from 'react-native-screens';
|
||||
|
||||
const Dialog = DialogPrimitive.Root;
|
||||
|
||||
const DialogTrigger = DialogPrimitive.Trigger;
|
||||
|
||||
const DialogPortal = DialogPrimitive.Portal;
|
||||
|
||||
const DialogClose = DialogPrimitive.Close;
|
||||
|
||||
const FullWindowOverlay = Platform.OS === 'ios' ? RNFullWindowOverlay : React.Fragment;
|
||||
|
||||
function DialogOverlay({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: Omit<React.ComponentProps<typeof DialogPrimitive.Overlay>, 'asChild'> & {
|
||||
children?: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<FullWindowOverlay>
|
||||
<DialogPrimitive.Overlay
|
||||
className={cn(
|
||||
'absolute bottom-0 left-0 right-0 top-0 flex items-center justify-center bg-black/50 p-2',
|
||||
Platform.select({
|
||||
web: 'animate-in fade-in-0 fixed cursor-default [&>*]:cursor-auto',
|
||||
}),
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
asChild={Platform.OS !== 'web'}>
|
||||
<NativeOnlyAnimatedView entering={FadeIn.duration(200)} exiting={FadeOut.duration(150)}>
|
||||
<NativeOnlyAnimatedView entering={FadeIn.delay(50)} exiting={FadeOut.duration(150)}>
|
||||
<>{children}</>
|
||||
</NativeOnlyAnimatedView>
|
||||
</NativeOnlyAnimatedView>
|
||||
</DialogPrimitive.Overlay>
|
||||
</FullWindowOverlay>
|
||||
);
|
||||
}
|
||||
function DialogContent({
|
||||
className,
|
||||
portalHost,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Content> & {
|
||||
portalHost?: string;
|
||||
}) {
|
||||
return (
|
||||
<DialogPortal hostName={portalHost}>
|
||||
<DialogOverlay>
|
||||
<DialogPrimitive.Content
|
||||
className={cn(
|
||||
'bg-background border-border z-50 mx-auto flex w-full max-w-[calc(100%-2rem)] flex-col gap-4 rounded-lg border p-6 shadow-lg shadow-black/5 sm:max-w-lg',
|
||||
Platform.select({
|
||||
web: 'animate-in fade-in-0 zoom-in-95 duration-200',
|
||||
}),
|
||||
className
|
||||
)}
|
||||
{...props}>
|
||||
<>{children}</>
|
||||
<DialogPrimitive.Close
|
||||
className={cn(
|
||||
'absolute right-4 top-4 rounded opacity-70 active:opacity-100',
|
||||
Platform.select({
|
||||
web: 'ring-offset-background focus:ring-ring data-[state=open]:bg-accent transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-offset-2',
|
||||
})
|
||||
)}
|
||||
hitSlop={12}>
|
||||
<Icon
|
||||
as={X}
|
||||
className={cn('text-accent-foreground web:pointer-events-none size-4 shrink-0')}
|
||||
/>
|
||||
<Text className="sr-only">Close</Text>
|
||||
</DialogPrimitive.Close>
|
||||
</DialogPrimitive.Content>
|
||||
</DialogOverlay>
|
||||
</DialogPortal>
|
||||
);
|
||||
}
|
||||
|
||||
function DialogHeader({ className, ...props }: ViewProps) {
|
||||
return (
|
||||
<View className={cn('flex flex-col gap-2 text-center sm:text-left', className)} {...props} />
|
||||
);
|
||||
}
|
||||
|
||||
function DialogFooter({ className, ...props }: ViewProps) {
|
||||
return (
|
||||
<View
|
||||
className={cn('flex flex-col-reverse gap-2 sm:flex-row sm:justify-end', className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DialogTitle({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Title>) {
|
||||
return (
|
||||
<DialogPrimitive.Title
|
||||
className={cn('text-foreground text-lg font-semibold leading-none', className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DialogDescription({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Description>) {
|
||||
return (
|
||||
<DialogPrimitive.Description
|
||||
className={cn('text-muted-foreground text-sm', className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogOverlay,
|
||||
DialogPortal,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
};
|
||||
57
lstMobile/src/components/ui/icon.tsx
Normal file
57
lstMobile/src/components/ui/icon.tsx
Normal file
@@ -0,0 +1,57 @@
|
||||
import { TextClassContext } from '@/components/ui/text';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { LucideIcon, LucideProps } from 'lucide-react-native';
|
||||
import { cssInterop } from 'nativewind';
|
||||
import * as React from 'react';
|
||||
|
||||
type IconProps = LucideProps & {
|
||||
as: LucideIcon;
|
||||
} & React.RefAttributes<LucideIcon>;
|
||||
|
||||
function IconImpl({ as: IconComponent, ...props }: IconProps) {
|
||||
return <IconComponent {...props} />;
|
||||
}
|
||||
|
||||
cssInterop(IconImpl, {
|
||||
className: {
|
||||
target: 'style',
|
||||
nativeStyleToProp: {
|
||||
height: 'size',
|
||||
width: 'size',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* A wrapper component for Lucide icons with Nativewind `className` support via `cssInterop`.
|
||||
*
|
||||
* This component allows you to render any Lucide icon while applying utility classes
|
||||
* using `nativewind`. It avoids the need to wrap or configure each icon individually.
|
||||
*
|
||||
* @component
|
||||
* @example
|
||||
* ```tsx
|
||||
* import { ArrowRight } from 'lucide-react-native';
|
||||
* import { Icon } from '@/registry/components/ui/icon';
|
||||
*
|
||||
* <Icon as={ArrowRight} className="text-red-500" size={16} />
|
||||
* ```
|
||||
*
|
||||
* @param {LucideIcon} as - The Lucide icon component to render.
|
||||
* @param {string} className - Utility classes to style the icon using Nativewind.
|
||||
* @param {number} size - Icon size (defaults to 14).
|
||||
* @param {...LucideProps} ...props - Additional Lucide icon props passed to the "as" icon.
|
||||
*/
|
||||
function Icon({ as: IconComponent, className, size = 14, ...props }: IconProps) {
|
||||
const textClass = React.useContext(TextClassContext);
|
||||
return (
|
||||
<IconImpl
|
||||
as={IconComponent}
|
||||
className={cn('text-foreground', textClass, className)}
|
||||
size={size}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Icon };
|
||||
23
lstMobile/src/components/ui/native-only-animated-view.tsx
Normal file
23
lstMobile/src/components/ui/native-only-animated-view.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import { Platform } from 'react-native';
|
||||
import Animated from 'react-native-reanimated';
|
||||
|
||||
/**
|
||||
* This component is used to wrap animated views that should only be animated on native.
|
||||
* @param props - The props for the animated view.
|
||||
* @returns The animated view if the platform is native, otherwise the children.
|
||||
* @example
|
||||
* <NativeOnlyAnimatedView entering={FadeIn} exiting={FadeOut}>
|
||||
* <Text>I am only animated on native</Text>
|
||||
* </NativeOnlyAnimatedView>
|
||||
*/
|
||||
function NativeOnlyAnimatedView(
|
||||
props: React.ComponentProps<typeof Animated.View> & React.RefAttributes<typeof Animated.View>
|
||||
) {
|
||||
if (Platform.OS === 'web') {
|
||||
return <>{props.children as React.ReactNode}</>;
|
||||
} else {
|
||||
return <Animated.View {...props} />;
|
||||
}
|
||||
}
|
||||
|
||||
export { NativeOnlyAnimatedView };
|
||||
@@ -1,5 +1,5 @@
|
||||
import { cn } from '@/lib/utils';
|
||||
import * as Slot from '@rn-primitives/slot';
|
||||
import { Slot } from '@rn-primitives/slot';
|
||||
import { cva, type VariantProps } from 'class-variance-authority';
|
||||
import * as React from 'react';
|
||||
import { Platform, Text as RNText, type Role } from 'react-native';
|
||||
@@ -70,11 +70,12 @@ function Text({
|
||||
variant = 'default',
|
||||
...props
|
||||
}: React.ComponentProps<typeof RNText> &
|
||||
React.RefAttributes<typeof RNText> &
|
||||
TextVariantProps & {
|
||||
asChild?: boolean;
|
||||
}) {
|
||||
const textClass = React.useContext(TextClassContext);
|
||||
const Component = asChild ? Slot.Text : RNText;
|
||||
const Component = asChild ? Slot : RNText;
|
||||
return (
|
||||
<Component
|
||||
className={cn(textVariants({ variant }), textClass, className)}
|
||||
|
||||
Reference in New Issue
Block a user