Skip to content

Commit 50d0265

Browse files
committed
fix: cleanup
1 parent 2c7c77d commit 50d0265

File tree

5 files changed

+216
-212
lines changed

5 files changed

+216
-212
lines changed

src/components/Themes/DesktopThemePreview.tsx

Lines changed: 0 additions & 147 deletions
This file was deleted.

src/components/Themes/ThemeCard.tsx

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
import React, { useState } from 'react';
1+
import React, { useState } from "react";
22

3-
import { Theme } from '../../interfaces/Theme';
3+
import Skeleton from "react-loading-skeleton";
44

5-
import '../../styles/theme_card.css';
6-
import ThemeModal from './ThemeModal';
5+
import { Theme } from "../../interfaces/Theme";
6+
7+
import "../../styles/theme_card.css";
8+
import ThemeModal from "./ThemeModal";
79

810
type Props = {
911
theme: Theme;
1012
isPreviewed: boolean;
1113
onPreview: (name: string) => void;
14+
isLoading: boolean;
1215
};
1316

1417
/**
1518
* Theme card component to hold the details of each theme in the themes page.
1619
*/
17-
const ThemeCard: React.FC<Props> = ({ theme, isPreviewed, onPreview }) => {
20+
const ThemeCard: React.FC<Props> = ({ theme, isPreviewed, onPreview, isLoading }) => {
1821
const [viewDetails, setViewDetails] = useState(false);
1922

2023
const onViewDetails = () => {
@@ -29,45 +32,47 @@ const ThemeCard: React.FC<Props> = ({ theme, isPreviewed, onPreview }) => {
2932
onClickPreview();
3033
};
3134

35+
if (isLoading) {
36+
return (
37+
<div>
38+
<div className="my-4 mx-2 hidden md:block">
39+
<Skeleton height={452} />
40+
</div>
41+
<div className="my-4 mx-2 block md:hidden">
42+
<Skeleton height={148} />
43+
</div>
44+
</div>
45+
);
46+
}
47+
3248
return (
3349
<>
3450
<div
35-
className={`flex flex-row items-center md:items-start md:flex-col md:w-64 p-4 my-4 mx-2 border-2 border-solid rounded-xl ${isPreviewed ? 'border-blue-700' : 'border-accent-600'}`}
51+
className={`flex flex-row items-center md:items-start md:flex-col
52+
md:w-64 p-4 my-4 mx-2 border-2 border-solid rounded-xl
53+
${isPreviewed ? "border-blue-700" : "border-accent-600"}`}
3654
>
37-
<div className="flex-1 basis-1/3 md:basis-1/2 mr-3 flex flex-row overflow-hidden w-32 h-20 md:w-56 md:h-56 rounded-xl">
38-
<img
39-
src={theme.themeImg}
40-
alt={theme.name}
41-
className="w-60 h-60 object-cover object-left-top"
42-
/>
55+
<div
56+
className="flex-1 basis-1/3 md:basis-1/2 mr-3 flex flex-row
57+
overflow-hidden w-32 h-20 md:w-56 md:h-56 rounded-xl"
58+
>
59+
<img src={theme.themeImg} alt={theme.name} className="w-60 h-60 object-cover object-left-top" />
4360
</div>
4461
<div className="flex-1 mr-4 basis-1/2 md:basis-1/3 flex flex-col md:pt-4">
4562
<h2 className="text-accent-50 text-lg font-medium mt-[-4px]">{theme.name}</h2>
4663
<span className="text-accent-300 text-sm">{theme.description}</span>
4764
</div>
4865
<div className="flex-1 basis-1/6 md:basis-1/6 flex flex-col">
49-
<button
50-
onClick={onViewDetails}
51-
className="text-blue-500 text-sm my-4 w-20"
52-
>
66+
<button onClick={onViewDetails} className="text-blue-500 text-sm my-4 w-20">
5367
More Info (i)
5468
</button>
5569
<label className=" ml-[2px] text-accent-50 text-sm md:text-base">
5670
Select
57-
<input
58-
type="checkbox"
59-
checked={isPreviewed}
60-
onChange={handleCheckboxChange}
61-
className="ml-2"
62-
/>
71+
<input type="checkbox" checked={isPreviewed} onChange={handleCheckboxChange} className="ml-2" />
6372
</label>
6473
</div>
6574
</div>
66-
<ThemeModal
67-
isOpen={viewDetails}
68-
theme={theme}
69-
onClose={() => setViewDetails(false)}
70-
/>
75+
<ThemeModal isOpen={viewDetails} theme={theme} onClose={() => setViewDetails(false)} />
7176
</>
7277
);
7378
};

src/components/Themes/ThemeModal.tsx

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,53 +6,54 @@ import { downloadThemeContent } from '../../utils';
66
import { Theme } from '../../interfaces/Theme';
77

88
type ThemeModalProps = {
9-
isOpen: boolean
10-
onClose: () => void
11-
theme: Theme
12-
}
9+
isOpen: boolean;
10+
onClose: () => void;
11+
theme: Theme;
12+
};
1313

1414
/**
1515
* Modal to popup for showing theme details.
1616
*/
1717
const ThemeModal: React.FC<ThemeModalProps> = ({ isOpen, onClose, theme }) => {
18-
const modalRef = useRef<HTMLDivElement>(null)
18+
const modalRef = useRef<HTMLDivElement>(null);
1919

2020
useEffect(() => {
2121
const handleClickOutside = (event: MouseEvent) => {
2222
if (
2323
modalRef.current &&
2424
!modalRef.current.contains(event.target as Node)
2525
) {
26-
onClose()
26+
onClose();
2727
}
28-
}
28+
};
2929

3030
if (isOpen) {
31-
document.addEventListener('mousedown', handleClickOutside)
32-
document.body.style.overflow = 'hidden'
31+
document.addEventListener('mousedown', handleClickOutside);
32+
document.body.style.overflow = 'hidden';
3333
}
3434

3535
return () => {
36-
document.removeEventListener('mousedown', handleClickOutside)
37-
document.body.style.overflow = 'unset'
38-
}
39-
}, [isOpen, onClose])
36+
document.removeEventListener('mousedown', handleClickOutside);
37+
document.body.style.overflow = 'unset';
38+
};
39+
}, [isOpen, onClose]);
4040

41-
if (!isOpen) return null
41+
if (!isOpen) return null;
4242

4343
const onDownload = () => {
4444
downloadThemeContent(
4545
theme.content.settings,
4646
theme.content.inlineStyles,
4747
theme.content.cssStyles,
4848
theme.name
49-
)
50-
}
49+
);
50+
};
5151

5252
const modalContent = (
5353
<div
5454
className="fixed inset-0 z-50 overflow-y-auto bg-black bg-opacity-50
55-
flex items-center justify-center pointer-events-auto">
55+
flex items-center justify-center pointer-events-auto"
56+
>
5657
<div
5758
ref={modalRef}
5859
className="relative bg-white p-6 rounded-lg shadow-lg max-w-screen-lg w-full m-4"
@@ -126,12 +127,12 @@ const ThemeModal: React.FC<ThemeModalProps> = ({ isOpen, onClose, theme }) => {
126127
</div>
127128
</div>
128129
</div>
129-
)
130+
);
130131

131132
return ReactDOM.createPortal(
132133
modalContent,
133134
document.getElementById('modal-container') || document.body
134-
)
135-
}
135+
);
136+
};
136137

137-
export default ThemeModal
138+
export default ThemeModal;

0 commit comments

Comments
 (0)