Skip to content

Commit 3e2f121

Browse files
committed
feat: add LoadingSnipper component and integrate into pages
- Created reusable LoadingSnipper component in src/components - Updated TemplatesPage, EditorPage, and SnippetsPage to use the new spinner - Improved loading state consistency across the app
1 parent ab2c773 commit 3e2f121

File tree

4 files changed

+35
-23
lines changed

4 files changed

+35
-23
lines changed

src/components/LoadingSnipper.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { FiLoader } from "react-icons/fi";
2+
3+
const LoadingSnipper = ({ children }: React.PropsWithChildren) => {
4+
return (
5+
<div className="flex justify-center items-center h-screen">
6+
<div className="text-center">
7+
<FiLoader className="size-8 animate-spin mx-auto" />
8+
<p className="text-lg">{children}</p>
9+
</div>
10+
</div>
11+
);
12+
};
13+
14+
export default LoadingSnipper;

src/pages/TemplatesPage.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AlertDialogHeader } from "@/components/ui/alert-dialog";
1+
import LoadingSnipper from "@/components/LoadingSnipper";
22
import { Badge } from "@/components/ui/badge";
33
import { Button } from "@/components/ui/button";
44
import {
@@ -197,9 +197,7 @@ const TemplatesPage = () => {
197197
</div>
198198

199199
{isLoading ? (
200-
<div className="text-center py-12">
201-
<p className="text-muted-foreground">Loading templates...</p>
202-
</div>
200+
<LoadingSnipper>{"Loading Templates..."}</LoadingSnipper>
203201
) : templates.length > 0 ? (
204202
<>
205203
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">

src/pages/editor/EditorPage.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import { useDispatch, useSelector } from "react-redux";
6666
import { useNavigate, useSearchParams } from "react-router-dom";
6767
import OutputConsole from "../../components/editor/OutputConsole";
6868
import { createSnippet } from "@/store/slices/snippetSlice";
69+
import LoadingSnipper from "@/components/LoadingSnipper";
6970

7071
const EditorPage = () => {
7172
const navigate = useNavigate();
@@ -367,15 +368,12 @@ const EditorPage = () => {
367368
}
368369
};
369370

370-
if (authLoading || (projectLoading && !currentProject)) {
371-
return (
372-
<div className="flex items-center justify-center h-screen">
373-
<div className="text-center">
374-
<FiLoader className="size-8 animate-spin mx-auto mb-4" />
375-
<p className="text-lg">Loading project...</p>
376-
</div>
377-
</div>
378-
);
371+
if (authLoading) {
372+
return <LoadingSnipper>{"Loading Project..."}</LoadingSnipper>;
373+
}
374+
375+
if (projectLoading && !currentProject) {
376+
return <LoadingSnipper>{"Loading Project..."}</LoadingSnipper>;
379377
}
380378

381379
if (projectError) {

src/pages/snippets/SnippetsPage.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import LoadingSnipper from "@/components/LoadingSnipper";
12
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
23
import { Badge } from "@/components/ui/badge";
34
import { Button } from "@/components/ui/button";
@@ -27,6 +28,7 @@ import { FaCode, FaFileCode } from "react-icons/fa";
2728
import { FiMessageSquare } from "react-icons/fi";
2829
import { useDispatch, useSelector } from "react-redux";
2930
import { useNavigate } from "react-router-dom";
31+
import { supportedLanguages } from "@/constants";
3032

3133
const SnippetsPage = () => {
3234
const { snippets, isLoading, error, totalPages, currentPage } = useSelector(
@@ -82,6 +84,7 @@ const SnippetsPage = () => {
8284
placeholder="Search Templates..."
8385
/>
8486
</div>
87+
8588
<div className="flex flex-col sm:flex-row gap-2">
8689
<Select
8790
value={languageFilter || "all"}
@@ -94,15 +97,12 @@ const SnippetsPage = () => {
9497
</SelectTrigger>
9598
<SelectContent>
9699
<SelectGroup>
97-
<SelectItem value="all">All Language</SelectItem>
98-
<SelectItem value="Javascript">Javascript</SelectItem>
99-
<SelectItem value="Python">Python</SelectItem>
100-
<SelectItem value="C++">C++</SelectItem>
101-
<SelectItem value="Typescript">Typescript</SelectItem>
102-
<SelectItem value="Java">Java</SelectItem>
103-
<SelectItem value="SQL">SQL</SelectItem>
104-
<SelectItem value="PHP">PHP</SelectItem>
105-
<SelectItem value="CSS">CSS</SelectItem>
100+
<SelectItem value="all">All Languages</SelectItem>
101+
{supportedLanguages.map((language) => (
102+
<SelectItem key={language} value={language}>
103+
{language}
104+
</SelectItem>
105+
))}
106106
</SelectGroup>
107107
</SelectContent>
108108
</Select>
@@ -140,7 +140,9 @@ const SnippetsPage = () => {
140140
</div>
141141
</div>
142142

143-
{snippets.length > 0 ? (
143+
{isLoading ? (
144+
<LoadingSnipper>{"Loading Snippet..."}</LoadingSnipper>
145+
) : snippets.length > 0 ? (
144146
<div className="grid gap-6 md:grid-cols-2 ">
145147
{snippets.map((snippet) => (
146148
<Card key={snippet._id} className="overflow-hidden">

0 commit comments

Comments
 (0)