Skip to content

Commit 23adf01

Browse files
authored
Replace react-loading-skeleton with custom tailwind component (#898)
1 parent 00ca5ad commit 23adf01

File tree

6 files changed

+57
-25
lines changed

6 files changed

+57
-25
lines changed

client/src/app.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'react-loading-skeleton/dist/skeleton.css';
21
import { Route, Routes } from 'react-router-dom';
32

43
import { PrivateRoute } from './components/private-route';
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { render } from '@testing-library/react';
2+
3+
import { Skeleton } from './skeleton';
4+
5+
describe('Skeleton', () => {
6+
it('renders a single skeleton by default', () => {
7+
const { container } = render(<Skeleton />);
8+
9+
expect(container.querySelectorAll('.animate-pulse')).toHaveLength(1);
10+
});
11+
12+
it('renders multiple skeletons when count is specified', () => {
13+
const { container } = render(<Skeleton count={5} />);
14+
15+
expect(container.querySelectorAll('.animate-pulse')).toHaveLength(5);
16+
});
17+
18+
it('applies custom className', () => {
19+
const { container } = render(<Skeleton className='mb-2 rounded-lg' />);
20+
21+
expect(container.querySelector('.animate-pulse')).toHaveClass(
22+
'rounded-lg',
23+
'mb-2'
24+
);
25+
});
26+
27+
it('applies width and height styles', () => {
28+
const { container } = render(<Skeleton width={200} height={100} />);
29+
30+
expect(container.querySelector('.animate-pulse')).toHaveStyle({
31+
width: '200px',
32+
height: '100px',
33+
});
34+
});
35+
});

client/src/components/skeleton.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
type SkeletonProps = {
2+
width?: number | string;
3+
height?: number | string;
4+
className?: string;
5+
count?: number;
6+
};
7+
8+
export const Skeleton = ({
9+
width,
10+
height,
11+
className = '',
12+
count = 1,
13+
}: SkeletonProps) => {
14+
return Array.from({ length: count }, (_, i) => (
15+
<div
16+
key={i}
17+
className={`animate-pulse bg-slate-50 dark:bg-neutral-800 ${className}`}
18+
style={{ width, height }}
19+
/>
20+
));
21+
};

client/src/pages/explore.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Fragment, useEffect, useState } from 'react';
22
import { Helmet } from 'react-helmet-async';
33
import InfiniteScroll from 'react-infinite-scroll-component';
4-
import Skeleton from 'react-loading-skeleton';
54
import { toast } from 'sonner';
65

76
import { CourseCard } from '../components/course-card';
@@ -10,8 +9,8 @@ import { FilterToggle } from '../components/filter-toggle';
109
import { JumpToTopButton } from '../components/jump-to-top-button';
1110
import { Layout } from '../components/layout';
1211
import { SearchBar } from '../components/search-bar';
12+
import { Skeleton } from '../components/skeleton';
1313
import { Spinner } from '../components/spinner';
14-
import { useDarkMode } from '../hooks/use-dark-mode';
1514
import { useExploreFilterState } from '../hooks/use-explore-filter-state';
1615
import { api } from '../lib/api';
1716
import type { Course } from '../lib/types';
@@ -66,8 +65,6 @@ export const Explore = () => {
6665
const [query, setQuery] = useState<string>('');
6766
const [searchSelected, setSearchSelected] = useState<boolean>(false);
6867

69-
const [darkMode] = useDarkMode();
70-
7168
const { selectedSubjects, selectedLevels, selectedTerms, sortBy } =
7269
useExploreFilterState();
7370

@@ -196,16 +193,9 @@ export const Explore = () => {
196193
) : (
197194
<div className='mx-2'>
198195
<Skeleton
199-
baseColor={
200-
darkMode ? 'rgb(38 38 38)' : 'rgb(248 250 252)'
201-
}
202196
className='mb-2 rounded-lg first:mt-2'
203197
count={10}
204-
duration={2}
205198
height={256}
206-
highlightColor={
207-
darkMode ? 'rgb(64 64 64)' : 'rgb(226 232 240)'
208-
}
209199
/>
210200
</div>
211201
)}

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
"react-error-boundary": "^6.0.3",
3535
"react-helmet-async": "^2.0.5",
3636
"react-infinite-scroll-component": "^6.1.0",
37-
"react-loading-skeleton": "^3.5.0",
3837
"react-router-dom": "^6.30.1",
3938
"react-vis-graph-wrapper": "^0.1.3",
4039
"recharts": "^3.6.0",

pnpm-lock.yaml

Lines changed: 0 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)