Skip to content

Commit ce22f5a

Browse files
goaltracker updated
1 parent 1ae890b commit ce22f5a

1 file changed

Lines changed: 18 additions & 62 deletions

File tree

components/dashboard/GoalTracker.tsx

Lines changed: 18 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,6 @@ export default function GoalTracker({ username, activity = [] }: GoalTrackerProp
3333
DEFAULT_GOALS
3434
);
3535

36-
// Detect synchronously at mount whether localStorage had a real stored value
37-
// for this user. If it did, there's no "loading" state — we show values right
38-
// away. The skeleton only appears for brand-new visitors with no local data.
39-
const hadLocalStorageValue = useRef<() => boolean>(() => {
40-
try {
41-
const raw = localStorage.getItem(`commitpulse:goals:${username.toLowerCase()}`);
42-
return raw !== null;
43-
} catch {
44-
return false;
45-
}
46-
});
47-
48-
// serverSynced tracks whether the background fetch has returned yet.
49-
// Only relevant when there was no localStorage hit (hadLocalStorageValue = false).
50-
const [serverSynced, setServerSynced] = useState(false);
5136
const saveControllerRef = useRef<AbortController | null>(null);
5237

5338
// On mount, fetch goals from the server. The server value is authoritative
@@ -73,8 +58,6 @@ export default function GoalTracker({ username, activity = [] }: GoalTrackerProp
7358
}
7459
} catch {
7560
// Network failure — silently keep local value
76-
} finally {
77-
if (!cancelled) setServerSynced(true);
7861
}
7962
}
8063

@@ -152,13 +135,6 @@ export default function GoalTracker({ username, activity = [] }: GoalTrackerProp
152135
setIsEditing(false);
153136
};
154137

155-
// Show a subtle loading state only when: (a) no localStorage value existed
156-
// AND (b) the server hasn't responded yet. This avoids any flash for returning users.
157-
const isInitialLoad =
158-
!serverSynced &&
159-
goals.monthly === DEFAULT_GOALS.monthly &&
160-
goals.yearly === DEFAULT_GOALS.yearly;
161-
162138
return (
163139
<motion.div
164140
initial={{ opacity: 0, y: 12 }}
@@ -269,38 +245,28 @@ export default function GoalTracker({ username, activity = [] }: GoalTrackerProp
269245
{t('dashboard.goals.monthly') || 'Monthly Target'}
270246
</span>
271247
<span className="text-xs font-bold text-zinc-900 dark:text-white">
272-
{isInitialLoad ? (
273-
<span className="inline-block w-14 h-3 rounded bg-zinc-200 dark:bg-zinc-800 animate-pulse" />
274-
) : (
275-
<>
276-
{monthlyContributions} / {goals.monthly}
277-
</>
278-
)}
248+
{monthlyContributions} / {goals.monthly}
279249
</span>
280250
</div>
281251
<div className="w-full h-2 rounded-full bg-gray-100 dark:bg-zinc-900 overflow-hidden relative border border-black/5 dark:border-[rgba(255,255,255,0.03)]">
282252
<motion.div
283253
initial={{ width: 0 }}
284-
animate={{ width: isInitialLoad ? '0%' : `${monthlyPercent}%` }}
254+
animate={{ width: `${monthlyPercent}%` }}
285255
transition={{ duration: 0.8, ease: 'easeOut' }}
286256
className="h-full bg-gradient-to-r from-emerald-400 to-teal-500 rounded-full"
287257
/>
288258
</div>
289259
<div className="flex justify-between items-center text-[10px]">
290260
<span className="text-zinc-400 dark:text-[#777]">
291-
{isInitialLoad ? (
292-
<span className="inline-block w-24 h-2.5 rounded bg-zinc-200 dark:bg-zinc-800 animate-pulse" />
293-
) : monthlyRemaining > 0 ? (
294-
(t('dashboard.goals.remaining') || '{{count}} commits remaining').replace(
295-
'{{count}}',
296-
monthlyRemaining.toString()
297-
)
298-
) : (
299-
t('dashboard.goals.completed') || 'Goal Achieved! 🎉'
300-
)}
261+
{monthlyRemaining > 0
262+
? (t('dashboard.goals.remaining') || '{{count}} commits remaining').replace(
263+
'{{count}}',
264+
monthlyRemaining.toString()
265+
)
266+
: t('dashboard.goals.completed') || 'Goal Achieved! 🎉'}
301267
</span>
302268
<span className="font-semibold text-emerald-500 dark:text-emerald-400">
303-
{isInitialLoad ? '—' : `${monthlyPercent}%`}
269+
{monthlyPercent}%
304270
</span>
305271
</div>
306272
</div>
@@ -312,38 +278,28 @@ export default function GoalTracker({ username, activity = [] }: GoalTrackerProp
312278
{t('dashboard.goals.yearly') || 'Yearly Target'}
313279
</span>
314280
<span className="text-xs font-bold text-zinc-900 dark:text-white">
315-
{isInitialLoad ? (
316-
<span className="inline-block w-14 h-3 rounded bg-zinc-200 dark:bg-zinc-800 animate-pulse" />
317-
) : (
318-
<>
319-
{yearlyContributions} / {goals.yearly}
320-
</>
321-
)}
281+
{yearlyContributions} / {goals.yearly}
322282
</span>
323283
</div>
324284
<div className="w-full h-2 rounded-full bg-gray-100 dark:bg-zinc-900 overflow-hidden relative border border-black/5 dark:border-[rgba(255,255,255,0.03)]">
325285
<motion.div
326286
initial={{ width: 0 }}
327-
animate={{ width: isInitialLoad ? '0%' : `${yearlyPercent}%` }}
287+
animate={{ width: `${yearlyPercent}%` }}
328288
transition={{ duration: 0.8, ease: 'easeOut' }}
329289
className="h-full bg-gradient-to-r from-emerald-400 to-teal-500 rounded-full"
330290
/>
331291
</div>
332292
<div className="flex justify-between items-center text-[10px]">
333293
<span className="text-zinc-400 dark:text-[#777]">
334-
{isInitialLoad ? (
335-
<span className="inline-block w-24 h-2.5 rounded bg-zinc-200 dark:bg-zinc-800 animate-pulse" />
336-
) : yearlyRemaining > 0 ? (
337-
(t('dashboard.goals.remaining') || '{{count}} commits remaining').replace(
338-
'{{count}}',
339-
yearlyRemaining.toString()
340-
)
341-
) : (
342-
t('dashboard.goals.completed') || 'Goal Achieved! 🎉'
343-
)}
294+
{yearlyRemaining > 0
295+
? (t('dashboard.goals.remaining') || '{{count}} commits remaining').replace(
296+
'{{count}}',
297+
yearlyRemaining.toString()
298+
)
299+
: t('dashboard.goals.completed') || 'Goal Achieved! 🎉'}
344300
</span>
345301
<span className="font-semibold text-emerald-500 dark:text-emerald-400">
346-
{isInitialLoad ? '—' : `${yearlyPercent}%`}
302+
{yearlyPercent}%
347303
</span>
348304
</div>
349305
</div>

0 commit comments

Comments
 (0)