Skip to content

Commit 620bf5c

Browse files
committed
chore: implement copilot suggestions
1 parent e92c50a commit 620bf5c

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/components/ui/offline-logo.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import type React from 'react';
22

3-
export const OfflineLogo: React.FC = () => (
3+
import { cn } from '@/utils/tailwindcss-override';
4+
5+
export const OfflineLogo: React.FC<{ className?: string }> = ({ className }) => (
46
<svg
5-
className="mx-auto h-24 w-24 text-gray-400"
7+
className={cn('mx-auto h-24 w-24 text-gray-400', className)}
68
fill="none"
79
stroke="currentColor"
810
viewBox="0 0 24 24"

src/components/ui/pull-to-refresh.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { Loader2 } from 'lucide-react';
77
import type React from 'react';
88
import { useCallback, useState } from 'react';
99

10+
import { useOnlineStatus } from '@/hooks/use-online-status';
11+
1012
interface PullToRefreshProperties {
1113
onRefresh: () => Promise<void>;
1214
children: React.ReactNode;
@@ -20,6 +22,7 @@ export const PullToRefresh: React.FC<PullToRefreshProperties> = ({
2022
className,
2123
pullThreshold = 80,
2224
}) => {
25+
const isOnline = useOnlineStatus();
2326
const [isRefreshing, setIsRefreshing] = useState(false);
2427
const y = useMotionValue(0);
2528

@@ -32,34 +35,34 @@ export const PullToRefresh: React.FC<PullToRefreshProperties> = ({
3235
// Keep it at a fixed position while refreshing
3336
animate(y, 60, { type: 'spring', stiffness: 300, damping: 30 });
3437

35-
if (navigator.onLine === false) {
38+
if (isOnline) {
39+
void onRefresh().finally(() => {
40+
setIsRefreshing(false);
41+
animate(y, 0, { type: 'spring', stiffness: 300, damping: 30 });
42+
});
43+
} else {
3644
// we are offline, show the offline logo and
3745
// hide the icon after a second
3846
setTimeout(() => {
3947
setIsRefreshing(false);
4048
animate(y, 0, { type: 'spring', stiffness: 300, damping: 30 });
4149
}, 1000);
42-
} else {
43-
void onRefresh().finally(() => {
44-
setIsRefreshing(false);
45-
animate(y, 0, { type: 'spring', stiffness: 300, damping: 30 });
46-
});
4750
}
4851
} else {
4952
animate(y, 0, { type: 'spring', stiffness: 500, damping: 30 });
5053
}
51-
}, [y, pullThreshold, isRefreshing, onRefresh]);
54+
}, [y, pullThreshold, isRefreshing, onRefresh, isOnline]);
5255

5356
return (
5457
<div className={cn('relative', className)}>
5558
{/* Spinner shown only while refreshing */}
5659
{isRefreshing && (
5760
<div className="absolute top-4 left-0 z-20 flex w-full justify-center">
5861
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-white shadow-md">
59-
{navigator.onLine ? (
62+
{isOnline ? (
6063
<Loader2 className="text-conveniat-green h-6 w-6 animate-spin" />
6164
) : (
62-
<OfflineLogo />
65+
<OfflineLogo className="h-6 w-6 text-gray-400" />
6366
)}
6467
</div>
6568
</div>

0 commit comments

Comments
 (0)