Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

Add loaders

Khuram Niaz8f89e45a1686
diff --git a/src/components/CompaniesContainer.tsx b/src/components/CompaniesContainer.tsx
index d6866e8..b790674 100644
--- a/src/components/CompaniesContainer.tsx
+++ b/src/components/CompaniesContainer.tsx
@@ -6,12 +6,14 @@ import { Card, CardContent, CardHeader, CardTitle } from "./ui/card";
import { Company } from "@/models/job.model";
import { getCompanyById, getCompanyList } from "@/actions/company.actions";
import { APP_CONSTANTS } from "@/lib/constants";
+import Loading from "./Loading";
function CompaniesContainer() {
const [companies, setCompanies] = useState<Company[]>([]);
const [totalCompanies, setTotalCompanies] = useState(0);
const [currentPage, setCurrentPage] = useState(1);
const [editCompany, setEditCompany] = useState(null);
+ const [loading, setLoading] = useState(false);
const recordsPerPage = APP_CONSTANTS.RECORDS_PER_PAGE;
@@ -19,6 +21,7 @@ function CompaniesContainer() {
const loadCompanies = useCallback(
async (page: number) => {
+ setLoading(true);
const { data, total } = await getCompanyList(
page,
recordsPerPage,
@@ -26,6 +29,9 @@ function CompaniesContainer() {
);
setCompanies(data);
setTotalCompanies(total);
+ if (data) {
+ setLoading(false);
+ }
},
[recordsPerPage]
);
@@ -64,15 +70,19 @@ function CompaniesContainer() {
</div>
</CardHeader>
<CardContent>
- <CompaniesTable
- companies={companies}
- currentPage={currentPage}
- totalPages={totalPages}
- recordsPerPage={recordsPerPage}
- totalCompanies={totalCompanies}
- onPageChange={setCurrentPage}
- editCompany={onEditCompany}
- />
+ {!loading ? (
+ <CompaniesTable
+ companies={companies}
+ currentPage={currentPage}
+ totalPages={totalPages}
+ recordsPerPage={recordsPerPage}
+ totalCompanies={totalCompanies}
+ onPageChange={setCurrentPage}
+ editCompany={onEditCompany}
+ />
+ ) : (
+ <Loading />
+ )}
</CardContent>
</Card>
</div>
diff --git a/src/components/JobsContainer.tsx b/src/components/JobsContainer.tsx
index d5f26ff..62c289e 100644
--- a/src/components/JobsContainer.tsx
+++ b/src/components/JobsContainer.tsx
@@ -1,5 +1,5 @@
"use client";
-import { useEffect, useState } from "react";
+import { useCallback, useEffect, useState } from "react";
import {
Card,
CardContent,
@@ -36,6 +36,7 @@ import {
SelectValue,
} from "./ui/select";
import { APP_CONSTANTS } from "@/lib/constants";
+import Loading from "./Loading";
type MyJobsProps = {
statuses: JobStatus[];
@@ -56,16 +57,24 @@ function JobsContainer({
const [currentPage, setCurrentPage] = useState(1);
const [totalJobs, setTotalJobs] = useState(0);
const [editJob, setEditJob] = useState(null);
+ const [loading, setLoading] = useState(false);
const jobsPerPage = APP_CONSTANTS.RECORDS_PER_PAGE;
const totalPages = Math.ceil(totalJobs / jobsPerPage);
- const loadJobs = async (page: number, filter?: string) => {
- const { data, total } = await getJobsList(page, jobsPerPage, filter);
- setJobs(data);
- setTotalJobs(total);
- };
+ const loadJobs = useCallback(
+ async (page: number, filter?: string) => {
+ setLoading(true);
+ const { data, total } = await getJobsList(page, jobsPerPage, filter);
+ setJobs(data);
+ setTotalJobs(total);
+ if (data) {
+ setLoading(false);
+ }
+ },
+ [jobsPerPage]
+ );
const reloadJobs = () => {
loadJobs(1);
@@ -92,7 +101,7 @@ function JobsContainer({
useEffect(() => {
loadJobs(currentPage);
- }, [currentPage]);
+ }, [currentPage, loadJobs]);
const onFilterChange = (filterBy: string) => {
filterBy === "none" ? reloadJobs() : loadJobs(1, filterBy);
@@ -142,16 +151,20 @@ function JobsContainer({
</div>
</CardHeader>
<CardContent>
- <MyJobsTable
- jobs={jobs}
- currentPage={currentPage}
- totalPages={totalPages}
- jobsPerPage={jobsPerPage}
- totalJobs={totalJobs}
- onPageChange={setCurrentPage}
- deleteJob={onDeleteJob}
- editJob={onEditJob}
- />
+ {!loading ? (
+ <MyJobsTable
+ jobs={jobs}
+ currentPage={currentPage}
+ totalPages={totalPages}
+ jobsPerPage={jobsPerPage}
+ totalJobs={totalJobs}
+ onPageChange={setCurrentPage}
+ deleteJob={onDeleteJob}
+ editJob={onEditJob}
+ />
+ ) : (
+ <Loading />
+ )}
</CardContent>
<CardFooter></CardFooter>
</Card>
diff --git a/src/components/Loading.tsx b/src/components/Loading.tsx
new file mode 100644
index 0000000..4fa3fcb
--- /dev/null
+++ b/src/components/Loading.tsx
@@ -0,0 +1,11 @@
+import { Loader } from "lucide-react";
+
+const Loading = () => {
+ return (
+ <div className="flex items-center justify-center">
+ <Loader className="animate-spin text-blue-500" size={48} />
+ </div>
+ );
+};
+
+export default Loading;