Skip to content

Commit eb9c2de

Browse files
authored
fix: add loader animation for busy loading (#104)
1 parent 00183f0 commit eb9c2de

23 files changed

Lines changed: 81 additions & 99 deletions

‎app/src/components/CommentBox.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Clock, Pencil, Trash2 } from 'lucide-react';
2+
import { Loader } from './Loader';
23

34
interface CommentBoxProps {
45
comment: {
@@ -171,7 +172,7 @@ export function CommentBox({
171172
disabled={isBusy || !editingText.trim()}
172173
className="bg-zinc-900 text-white hover:bg-zinc-800 font-semibold text-xs px-4.5 py-1.5 rounded-lg transition disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer flex items-center gap-1.5"
173174
>
174-
{isBusy && <span className="w-3 h-3 border-2 border-white border-t-transparent rounded-full animate-spin" />}
175+
{isBusy && <Loader size="xs" color="white" />}
175176
Save
176177
</button>
177178
</div>

‎app/src/components/Loader.tsx‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
interface LoaderProps {
2+
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
3+
color?: 'white' | 'dark' | 'orange' | 'rose';
4+
className?: string;
5+
}
6+
7+
export function Loader({ size = 'md', color = 'dark', className = '' }: LoaderProps) {
8+
const sizeClasses = {
9+
xs: 'w-3 h-3 border-2',
10+
sm: 'w-4 h-4 border-2',
11+
md: 'w-8 h-8 border-[3px]',
12+
lg: 'w-12 h-12 border-4',
13+
xl: 'w-16 h-16 border-4',
14+
};
15+
16+
const colorClasses = {
17+
white: 'border-white/20 border-t-white',
18+
dark: 'border-zinc-200 border-t-zinc-800',
19+
orange: 'border-amber-100 border-t-amber-500',
20+
rose: 'border-rose-100 border-t-rose-500',
21+
};
22+
23+
return (
24+
<div
25+
className={`rounded-full animate-spin ${sizeClasses[size]} ${colorClasses[color]} ${className}`}
26+
role="status"
27+
aria-label="loading"
28+
/>
29+
);
30+
}

‎app/src/pages/admin/AEPostView.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useEffect, useMemo, useState } from 'react';
22
import { useNavigate, Link } from 'react-router-dom';
33
import { AlertCircle, ServerCrash, ClipboardList, GraduationCap, BedDouble, Building2, Zap, Hammer } from 'lucide-react';
44
import { MainLayout } from '../../components/layout/MainLayout';
5+
import { Loader } from '../../components/Loader';
56

67
// ── Types ─────────────────────────────────────────────────────────────────────
78

@@ -200,7 +201,7 @@ export function AEPostView() {
200201
<MainLayout>
201202
<div className="flex-grow flex items-center justify-center bg-gray-50 py-20">
202203
<div className="text-center">
203-
<div className="w-12 h-12 border-4 border-[#ff9900] border-t-transparent rounded-full animate-spin mx-auto mb-4" />
204+
<Loader size="lg" color="orange" className="mx-auto mb-4" />
204205
<p className="text-gray-600 font-semibold">Fetching posts…</p>
205206
</div>
206207
</div>

‎app/src/pages/admin/AdminPostView.tsx‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
} from 'lucide-react';
2424
import { MainLayout } from '../../components/layout/MainLayout';
2525
import { CommentBox } from '../../components/CommentBox';
26+
import { Loader } from '../../components/Loader';
2627

2728
// ── Types ──────────────────────────────────────────────────────────────────────
2829

@@ -603,7 +604,7 @@ export function AdminPostView() {
603604
<MainLayout>
604605
<div className="flex-grow flex items-center justify-center bg-white py-20">
605606
<div className="text-center">
606-
<div className="w-12 h-12 border-4 border-[#ff9900] border-t-transparent rounded-full animate-spin mx-auto mb-4" />
607+
<Loader size="lg" color="orange" className="mx-auto mb-4" />
607608
<p className="text-gray-600 font-semibold">Loading post…</p>
608609
</div>
609610
</div>
@@ -921,7 +922,7 @@ export function AdminPostView() {
921922
className="inline-flex items-center gap-2 text-xs font-semibold text-white bg-zinc-900 hover:bg-zinc-800 px-4 py-2 rounded-lg transition-all duration-200 disabled:opacity-40 disabled:cursor-not-allowed disabled:pointer-events-none cursor-pointer"
922923
>
923924
{acting ? (
924-
<span className="w-3.5 h-3.5 border-2 border-white border-t-transparent rounded-full animate-spin" />
925+
<Loader size="xs" color="white" />
925926
) : <MessageSquare className="w-3.5 h-3.5" />}
926927
Post Comment
927928
</button>
@@ -950,7 +951,7 @@ export function AdminPostView() {
950951
className="inline-flex items-center gap-2 text-xs font-semibold text-white bg-amber-500 hover:bg-amber-600 px-4 py-2 rounded-lg transition-all duration-200 disabled:opacity-40 disabled:cursor-not-allowed disabled:pointer-events-none cursor-pointer"
951952
>
952953
{acting ? (
953-
<span className="w-3.5 h-3.5 border-2 border-white border-t-transparent rounded-full animate-spin" />
954+
<Loader size="xs" color="white" />
954955
) : btn.icon}
955956
{btn.label}
956957
</button>
@@ -1000,7 +1001,7 @@ export function AdminPostView() {
10001001
className={`inline-flex items-center gap-2 text-xs font-semibold text-white ${buttonColorClass} px-4 py-2 rounded-lg transition-all duration-200 disabled:opacity-40 disabled:cursor-not-allowed disabled:pointer-events-none cursor-pointer`}
10011002
>
10021003
{acting ? (
1003-
<span className="w-3.5 h-3.5 border-2 border-white border-t-transparent rounded-full animate-spin" />
1004+
<Loader size="xs" color="white" />
10041005
) : btn.icon}
10051006
{btn.label}
10061007
</button>

‎app/src/pages/admin/JEPostView.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useEffect, useState } from 'react';
22
import { useNavigate, Link } from 'react-router-dom';
33
import { AlertCircle, ServerCrash, ClipboardList, GraduationCap, BedDouble, Building2, Zap, Hammer } from 'lucide-react';
44
import { MainLayout } from '../../components/layout/MainLayout';
5+
import { Loader } from '../../components/Loader';
56

67
// ── Types ─────────────────────────────────────────────────────────────────────
78

@@ -185,7 +186,7 @@ export function JEPostView() {
185186
<MainLayout>
186187
<div className="flex-grow flex items-center justify-center bg-gray-50 py-20">
187188
<div className="text-center">
188-
<div className="w-12 h-12 border-4 border-[#ff9900] border-t-transparent rounded-full animate-spin mx-auto mb-4" />
189+
<Loader size="lg" color="orange" className="mx-auto mb-4" />
189190
<p className="text-gray-600 font-semibold">Fetching posts…</p>
190191
</div>
191192
</div>

‎app/src/pages/admin/XENPostView.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useEffect, useState } from 'react';
22
import { useNavigate, Link } from 'react-router-dom';
33
import { AlertCircle, ServerCrash, ClipboardList, GraduationCap, BedDouble, Building2, Zap, Hammer } from 'lucide-react';
44
import { MainLayout } from '../../components/layout/MainLayout';
5+
import { Loader } from '../../components/Loader';
56

67
// ── Types ─────────────────────────────────────────────────────────────────────
78

@@ -187,7 +188,7 @@ export function XENPostView() {
187188
<MainLayout>
188189
<div className="flex-grow flex items-center justify-center bg-gray-50 py-20">
189190
<div className="text-center">
190-
<div className="w-12 h-12 border-4 border-[#ff9900] border-t-transparent rounded-full animate-spin mx-auto mb-4" />
191+
<Loader size="lg" color="orange" className="mx-auto mb-4" />
191192
<p className="text-gray-600 font-semibold">Fetching posts…</p>
192193
</div>
193194
</div>

‎app/src/pages/auth/AccountResetPass.tsx‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useState } from 'react';
22
import { Link, useSearchParams, useNavigate } from 'react-router-dom';
33
import { Eye, EyeOff } from 'lucide-react';
44
import { MainLayout } from '../../components/layout/MainLayout';
5+
import { Loader } from '../../components/Loader';
56

67
const roleToApi: Record<string, string> = {
78
faculty: '/api/auth/faculty/reset-password',
@@ -203,12 +204,7 @@ export function AccountResetPass() {
203204
disabled={loading}
204205
className={`inline-flex items-center gap-2 bg-[#16a34a] hover:bg-[#15803d] text-white font-semibold py-2.5 px-8 rounded-lg transition-colors duration-200 text-sm active:scale-[0.98] ${loading ? 'opacity-70 cursor-not-allowed' : 'cursor-pointer'}`}
205206
>
206-
{loading && (
207-
<svg className="animate-spin w-4 h-4 shrink-0" fill="none" viewBox="0 0 24 24">
208-
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
209-
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z" />
210-
</svg>
211-
)}
207+
{loading && <Loader size="sm" color="white" />}
212208
{loading ? 'Resetting…' : 'Reset Password'}
213209
</button>
214210
{loginPath && (

‎app/src/pages/auth/CentreHeadForgotPassword.tsx‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useState } from 'react';
22
import { Link } from 'react-router-dom';
33
import { MainLayout } from '../../components/layout/MainLayout';
4+
import { Loader } from '../../components/Loader';
45

56
export function CentreHeadForgotPassword() {
67
const [email, setEmail] = useState('');
@@ -94,12 +95,7 @@ export function CentreHeadForgotPassword() {
9495
disabled={loading || submitted}
9596
className={`inline-flex items-center gap-2 bg-[#16a34a] hover:bg-[#15803d] text-white font-semibold py-2.5 px-8 rounded-lg transition-colors duration-200 text-sm active:scale-[0.98] ${(loading || submitted) ? 'opacity-70 cursor-not-allowed' : 'cursor-pointer'}`}
9697
>
97-
{loading && (
98-
<svg className="animate-spin w-4 h-4 shrink-0" fill="none" viewBox="0 0 24 24">
99-
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
100-
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z" />
101-
</svg>
102-
)}
98+
{loading && <Loader size="sm" color="white" />}
10399
{loading ? 'Sending…' : submitted ? 'Link Sent' : 'Send Reset Link'}
104100
</button>
105101
<Link to="/centre-head/login" className="text-sm text-[#666666] hover:text-[#111111] transition-colors cursor-pointer">

‎app/src/pages/auth/CentreHeadLogin.tsx‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useState } from 'react';
22
import { Link, useNavigate } from 'react-router-dom';
33
import { Eye, EyeOff } from 'lucide-react';
44
import { MainLayout } from '../../components/layout/MainLayout';
5+
import { Loader } from '../../components/Loader';
56

67
export function CentreHeadLogin() {
78
const [email, setEmail] = useState('');
@@ -134,12 +135,7 @@ export function CentreHeadLogin() {
134135
disabled={loading}
135136
className={`inline-flex items-center gap-2 bg-[#16a34a] hover:bg-[#15803d] text-white font-semibold py-2.5 px-8 rounded-lg transition-colors duration-200 text-sm active:scale-[0.98] ${loading ? 'opacity-70 cursor-not-allowed' : 'cursor-pointer'}`}
136137
>
137-
{loading && (
138-
<svg className="animate-spin w-4 h-4 shrink-0" fill="none" viewBox="0 0 24 24">
139-
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
140-
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z" />
141-
</svg>
142-
)}
138+
{loading && <Loader size="sm" color="white" />}
143139
{loading ? 'Logging in…' : 'Login'}
144140
</button>
145141
<Link to="/centre-head/signup" className="text-sm text-[#666666] hover:text-[#111111] transition-colors cursor-pointer">

‎app/src/pages/auth/CentreHeadSignup.tsx‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useState } from 'react';
22
import { Link } from 'react-router-dom';
33
import { Eye, EyeOff } from 'lucide-react';
44
import { MainLayout } from '../../components/layout/MainLayout';
5+
import { Loader } from '../../components/Loader';
56
import { BUILDINGS } from '../../constants/models';
67

78
export function CentreHeadSignup() {
@@ -191,12 +192,7 @@ export function CentreHeadSignup() {
191192
disabled={loading}
192193
className={`inline-flex items-center gap-2 bg-[#16a34a] hover:bg-[#15803d] text-white font-semibold py-2.5 px-8 rounded-lg transition-colors duration-200 text-sm active:scale-[0.98] ${loading ? 'opacity-70 cursor-not-allowed' : 'cursor-pointer'}`}
193194
>
194-
{loading && (
195-
<svg className="animate-spin w-4 h-4 shrink-0" fill="none" viewBox="0 0 24 24">
196-
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
197-
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z" />
198-
</svg>
199-
)}
195+
{loading && <Loader size="sm" color="white" />}
200196
{loading ? 'Registering…' : 'Register as Centre Head'}
201197
</button>
202198
<Link

0 commit comments

Comments
 (0)