Skip to content

Commit e0d9d89

Browse files
Fix: Resolve type errors in Pagination
The PaginationPrevious and PaginationNext components were incorrectly passing the disabled prop to the PaginationLink component, which is an anchor tag and does not support the disabled prop. This commit removes the disabled prop from these components.
1 parent 890d311 commit e0d9d89

File tree

2 files changed

+41
-30
lines changed

2 files changed

+41
-30
lines changed

src/components/ui/pagination.tsx

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import * as React from "react"
23
import { ChevronLeft, ChevronRight, MoreHorizontal } from "lucide-react"
34

@@ -59,14 +60,32 @@ const PaginationLink = ({
5960
)
6061
PaginationLink.displayName = "PaginationLink"
6162

63+
// Extended interface with isDisabled property
64+
type PaginationNavigationProps = React.ComponentProps<typeof PaginationLink> & {
65+
isDisabled?: boolean
66+
}
67+
6268
const PaginationPrevious = ({
6369
className,
70+
isDisabled,
71+
onClick,
6472
...props
65-
}: React.ComponentProps<typeof PaginationLink>) => (
73+
}: PaginationNavigationProps) => (
6674
<PaginationLink
6775
aria-label="Go to previous page"
6876
size="default"
69-
className={cn("gap-1 pl-2.5", className)}
77+
className={cn(
78+
"gap-1 pl-2.5",
79+
className,
80+
isDisabled && "pointer-events-none opacity-50"
81+
)}
82+
onClick={(e) => {
83+
if (isDisabled) {
84+
e.preventDefault();
85+
return;
86+
}
87+
onClick?.(e);
88+
}}
7089
{...props}
7190
>
7291
<ChevronLeft className="h-4 w-4" />
@@ -77,12 +96,25 @@ PaginationPrevious.displayName = "PaginationPrevious"
7796

7897
const PaginationNext = ({
7998
className,
99+
isDisabled,
100+
onClick,
80101
...props
81-
}: React.ComponentProps<typeof PaginationLink>) => (
102+
}: PaginationNavigationProps) => (
82103
<PaginationLink
83104
aria-label="Go to next page"
84105
size="default"
85-
className={cn("gap-1 pr-2.5", className)}
106+
className={cn(
107+
"gap-1 pr-2.5",
108+
className,
109+
isDisabled && "pointer-events-none opacity-50"
110+
)}
111+
onClick={(e) => {
112+
if (isDisabled) {
113+
e.preventDefault();
114+
return;
115+
}
116+
onClick?.(e);
117+
}}
86118
{...props}
87119
>
88120
<span>Next</span>

src/pages/JournalEntries.tsx

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import React, { useState, useEffect } from 'react';
32
import { useNavigate } from 'react-router-dom';
43
import { format } from 'date-fns';
@@ -46,7 +45,6 @@ import { useAuth } from '../utils/auth';
4645
import { getJournalEntries, JournalEntry } from '../utils/firebase';
4746
import { toast } from 'sonner';
4847

49-
// Get mood label based on score
5048
const getMoodLabel = (score: number): string => {
5149
if (score <= 2) return "Very Unpleasant";
5250
if (score <= 4) return "Slightly Unpleasant";
@@ -55,7 +53,6 @@ const getMoodLabel = (score: number): string => {
5553
return "Very Pleasant";
5654
};
5755

58-
// Get mood color based on score
5956
const getMoodColor = (score: number): string => {
6057
if (score <= 4) return "text-blue-400";
6158
if (score <= 6) return "text-slate-200";
@@ -93,9 +90,8 @@ const JournalEntries: React.FC = () => {
9390
setEntries(fetchedEntries);
9491
setFilteredEntries(fetchedEntries);
9592

96-
// Set default selected month to the most recent entry's month if entries exist
9793
if (fetchedEntries.length > 0) {
98-
const latestEntry = fetchedEntries[0]; // Already sorted in getJournalEntries
94+
const latestEntry = fetchedEntries[0];
9995
const latestMonth = format(latestEntry.timestamp, 'MMMM yyyy');
10096
setSelectedMonth(latestMonth);
10197
}
@@ -110,11 +106,9 @@ const JournalEntries: React.FC = () => {
110106
fetchEntries();
111107
}, [currentUser, navigate]);
112108

113-
// Filter entries based on search query and selected month
114109
useEffect(() => {
115110
let filtered = entries;
116111

117-
// Filter by search query
118112
if (searchQuery) {
119113
filtered = filtered.filter(
120114
entry =>
@@ -124,18 +118,16 @@ const JournalEntries: React.FC = () => {
124118
);
125119
}
126120

127-
// Filter by selected month
128121
if (selectedMonth) {
129122
filtered = filtered.filter(entry =>
130123
format(entry.timestamp, 'MMMM yyyy') === selectedMonth
131124
);
132125
}
133126

134127
setFilteredEntries(filtered);
135-
setCurrentPage(1); // Reset to first page when filters change
128+
setCurrentPage(1);
136129
}, [searchQuery, selectedMonth, entries]);
137130

138-
// Get unique months from entries
139131
const months = React.useMemo(() => {
140132
const uniqueMonths = new Set<string>();
141133
entries.forEach(entry => {
@@ -145,25 +137,21 @@ const JournalEntries: React.FC = () => {
145137
return Array.from(uniqueMonths).sort((a, b) => {
146138
const dateA = new Date(a);
147139
const dateB = new Date(b);
148-
return dateB.getTime() - dateA.getTime(); // Sort in descending order
140+
return dateB.getTime() - dateA.getTime();
149141
});
150142
}, [entries]);
151143

152-
// Calculate statistics
153144
const stats = React.useMemo(() => {
154-
// Get entries for the current year
155145
const currentYear = new Date().getFullYear();
156146
const entriesThisYear = entries.filter(
157147
entry => entry.timestamp.getFullYear() === currentYear
158148
);
159149

160-
// Count total words written
161150
const totalWords = entriesThisYear.reduce((sum, entry) => {
162151
const wordCount = entry.notes.split(/\s+/).filter(Boolean).length;
163152
return sum + wordCount;
164153
}, 0);
165154

166-
// Count unique days journaled
167155
const uniqueDays = new Set(
168156
entriesThisYear.map(entry => format(entry.timestamp, 'yyyy-MM-dd'))
169157
).size;
@@ -175,16 +163,13 @@ const JournalEntries: React.FC = () => {
175163
};
176164
}, [entries]);
177165

178-
// Pagination
179166
const indexOfLastEntry = currentPage * entriesPerPage;
180167
const indexOfFirstEntry = indexOfLastEntry - entriesPerPage;
181168
const currentEntries = filteredEntries.slice(indexOfFirstEntry, indexOfLastEntry);
182169
const totalPages = Math.ceil(filteredEntries.length / entriesPerPage);
183170

184-
// Change page
185171
const paginate = (pageNumber: number) => setCurrentPage(pageNumber);
186172

187-
// Grouped entries by date
188173
const groupedEntries = React.useMemo(() => {
189174
const groups: Record<string, JournalEntry[]> = {};
190175

@@ -225,7 +210,6 @@ const JournalEntries: React.FC = () => {
225210
</div>
226211
</div>
227212

228-
{/* Stats */}
229213
<div className="grid grid-cols-3 gap-4 mb-8">
230214
<Card className="bg-slate-800 border-none">
231215
<CardContent className="flex items-center p-4">
@@ -264,7 +248,6 @@ const JournalEntries: React.FC = () => {
264248
</Card>
265249
</div>
266250

267-
{/* Search and filter */}
268251
<div className="flex gap-4 mb-6">
269252
<div className="relative flex-1">
270253
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-slate-400" />
@@ -277,7 +260,6 @@ const JournalEntries: React.FC = () => {
277260
</div>
278261
</div>
279262

280-
{/* Month tabs */}
281263
<Tabs defaultValue={selectedMonth || months[0]} className="mb-6">
282264
<TabsList className="bg-slate-800 w-full h-auto flex overflow-x-auto p-1">
283265
{months.map(month => (
@@ -314,7 +296,6 @@ const JournalEntries: React.FC = () => {
314296
</div>
315297
) : (
316298
<>
317-
{/* Journal entries */}
318299
<div className="space-y-6">
319300
{Object.entries(groupedEntries).map(([date, entriesForDate]) => (
320301
<div key={date} className="space-y-4">
@@ -359,14 +340,13 @@ const JournalEntries: React.FC = () => {
359340
))}
360341
</div>
361342

362-
{/* Pagination */}
363343
{totalPages > 1 && (
364344
<Pagination className="mt-8">
365345
<PaginationContent>
366346
<PaginationItem>
367347
<PaginationPrevious
368348
onClick={() => paginate(Math.max(1, currentPage - 1))}
369-
disabled={currentPage === 1}
349+
isDisabled={currentPage === 1}
370350
className={currentPage === 1 ? "pointer-events-none opacity-50" : ""}
371351
/>
372352
</PaginationItem>
@@ -378,7 +358,6 @@ const JournalEntries: React.FC = () => {
378358
(page >= currentPage - 1 && page <= currentPage + 1)
379359
)
380360
.map((page, index, array) => {
381-
// Add ellipsis
382361
if (index > 0 && page > array[index - 1] + 1) {
383362
return (
384363
<React.Fragment key={`ellipsis-${page}`}>
@@ -412,7 +391,7 @@ const JournalEntries: React.FC = () => {
412391
<PaginationItem>
413392
<PaginationNext
414393
onClick={() => paginate(Math.min(totalPages, currentPage + 1))}
415-
disabled={currentPage === totalPages}
394+
isDisabled={currentPage === totalPages}
416395
className={currentPage === totalPages ? "pointer-events-none opacity-50" : ""}
417396
/>
418397
</PaginationItem>

0 commit comments

Comments
 (0)