linter issues
All checks were successful
Lint / Lint and Check (push) Successful in 40s

This commit is contained in:
2025-11-15 16:08:05 +01:00
parent 2089e5d01d
commit b630a0ca33
2 changed files with 16 additions and 11 deletions

View File

@@ -73,11 +73,11 @@ interface HabitResponse {
export default function Dashboard() {
const router = useRouter();
const queryClient = useQueryClient();
const [userToken, setUserToken] = useState<string | null>(null);
const [showNewHabitDialog, setShowNewHabitDialog] = useState(false);
const [newHabitName, setNewHabitName] = useState('');
const [newHabitType, setNewHabitType] = useState<'positive' | 'neutral' | 'negative'>('neutral');
const [copiedToken, setCopiedToken] = useState(false);
const [currentTime, setCurrentTime] = useState(() => Date.now());
// Check authentication
const { data: authData, isLoading: authLoading } = useQuery<AuthData>({
@@ -92,11 +92,15 @@ export default function Dashboard() {
},
});
// Update current time periodically to avoid impure Date.now() calls during render
useEffect(() => {
if (authData?.token) {
setUserToken(authData.token);
}
}, [authData]);
const interval = setInterval(() => {
setCurrentTime(Date.now());
}, 60000); // Update every minute
return () => {
clearInterval(interval);
};
}, []);
// Fetch habits
const { data: habitsData, isLoading: habitsLoading } = useQuery<HabitsResponse>({
@@ -154,8 +158,8 @@ export default function Dashboard() {
};
const copyToken = () => {
if (userToken) {
void navigator.clipboard.writeText(userToken);
if (authData?.token) {
void navigator.clipboard.writeText(authData.token);
setCopiedToken(true);
setTimeout(() => {
setCopiedToken(false);
@@ -199,7 +203,7 @@ export default function Dashboard() {
const getAverageFrequency = (habit: Habit) => {
const daysSinceCreation = Math.max(
1,
Math.floor((Date.now() - new Date(habit.createdAt).getTime()) / (1000 * 60 * 60 * 24)),
Math.floor((currentTime - new Date(habit.createdAt).getTime()) / (1000 * 60 * 60 * 24)),
);
if (daysSinceCreation <= 7) {
@@ -320,13 +324,13 @@ export default function Dashboard() {
</div>
{/* Token Alert */}
{userToken && (
{authData?.token && (
<Alert className="border-zinc-800 bg-zinc-950">
<AlertDescription className="flex items-center justify-between">
<div className="space-y-1">
<p className="text-sm text-zinc-400">Your access token:</p>
<code className="rounded bg-zinc-900 px-2 py-1 font-mono text-sm text-white">
{userToken}
{authData.token}
</code>
</div>
<TooltipProvider>

View File

@@ -1,7 +1,8 @@
'use client';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactNode, useState } from 'react';
import { useState } from 'react';
import type { ReactNode } from 'react';
export function Providers({ children }: { children: ReactNode }) {
const [queryClient] = useState(