Skip to content

Commit 2d2b9af

Browse files
committed
final commit
1 parent 67be97a commit 2d2b9af

5 files changed

Lines changed: 69 additions & 22 deletions

File tree

ACTIVITY_REMINDER_FEATURE.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,26 @@ Use the motivational reminders as guidance to:
9494

9595
## Token Requirements
9696

97-
To use this feature, you need a Personal Access Token with the following permissions:
97+
**Authentication with a Personal Access Token (PAT) is required** to view and use the ActivityReminder UI. The component is only displayed when you have successfully authenticated with both a GitHub username and a valid PAT.
98+
99+
Your PAT should have the following permissions:
98100
- `public_repo` (access to public repositories)
99101
- `repo` (access to private repositories - if tracking private repos)
100102

101-
**Note**: The feature works with or without a token, but with a token you get higher API rate limits.
103+
Without valid authentication, the Daily Activity Status reminder widget will not be accessible.
102104

103105
## Technical Details
104106

105107
### Components
106108
- **`useGitHubActivity` Hook**: Analyzes activity data and returns activity status
107109
- **`ActivityReminder` Component**: Displays the reminder UI with all statistics
108-
- **`activityReminders` Utilities**: Helper functions for generating messages and calculations
110+
- **Utility Functions** (`activityReminders.ts`):
111+
- `generateReminders()` - Creates motivational alert messages
112+
- `generateStreakData()` - Calculates streak and generates streak messages
113+
- `getActivitySummary()` - Generates text summary of daily activities
114+
- `getActivityColor()` - Returns color coding based on activity level
115+
- `calculateProductivityScore()` - Computes dynamic productivity score (0-100%)
116+
- `getMotivationLevel()` - Determines motivation tier based on streak
109117

110118
### API Integration
111119
The feature leverages the existing GitHub API integration through:

src/components/ActivityReminder.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ import {
2727

2828
interface ActivityReminderProps {
2929
activity: ActivityStatus;
30-
username: string;
3130
}
3231

3332
const ActivityReminder: React.FC<ActivityReminderProps> = ({
3433
activity,
35-
username,
3634
}) => {
3735
const theme = useTheme();
3836
const reminders = useMemo(() => generateReminders(activity), [activity]);

src/hooks/useGitHubActivity.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,15 @@ export const useGitHubActivity = (
4747

4848
// Separate PR types for today
4949
const todaysOpenPRs = todaysPRs.filter((pr) => pr.state === 'open');
50-
const todaysMergedPRs = todaysPRs.filter(
51-
(pr) => pr.pull_request?.merged_at
52-
);
50+
51+
// Compute merged PRs from all PRs by checking merged_at date (not created_at)
52+
// This captures PRs created earlier but merged today
53+
const todaysMergedPRs = prs.filter((pr) => {
54+
if (!pr.pull_request?.merged_at) return false;
55+
const mergedDate = new Date(pr.pull_request.merged_at);
56+
mergedDate.setHours(0, 0, 0, 0);
57+
return mergedDate.getTime() === today.getTime();
58+
});
5359

5460
// Calculate activity flags
5561
const hasOpenedPRToday = todaysOpenPRs.length > 0;
@@ -82,19 +88,22 @@ export const useGitHubActivity = (
8288
return itemDate.getTime() === currentDate.getTime();
8389
});
8490

91+
// Initialize streak based on activity today
92+
// If active today, start at 1 and move to yesterday for iteration
93+
// If inactive today, start at 0 and keep currentDate at today
8594
if (hasActivityToday) {
8695
contributionStreak = 1;
8796
currentDate.setDate(currentDate.getDate() - 1);
97+
}
8898

89-
// Count consecutive days backwards
90-
for (const item of allActivity) {
91-
const itemDate = new Date(item.created_at);
92-
itemDate.setHours(0, 0, 0, 0);
99+
// Count consecutive days backwards (regardless of activity today)
100+
for (const item of allActivity) {
101+
const itemDate = new Date(item.created_at);
102+
itemDate.setHours(0, 0, 0, 0);
93103

94-
if (itemDate.getTime() === currentDate.getTime()) {
95-
contributionStreak++;
96-
currentDate.setDate(currentDate.getDate() - 1);
97-
}
104+
if (itemDate.getTime() === currentDate.getTime()) {
105+
contributionStreak++;
106+
currentDate.setDate(currentDate.getDate() - 1);
98107
}
99108
}
100109
}

src/pages/Tracker/Tracker.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { useGitHubAuth } from "../../hooks/useGitHubAuth";
3434
import { useGitHubData } from "../../hooks/useGitHubData";
3535
import { useGitHubActivity } from "../../hooks/useGitHubActivity";
3636
import ActivityReminder from "../../components/ActivityReminder";
37+
import { get30DayWindow } from "../../utils/dateUtils";
3738
import { KeyIcon } from "lucide-react";
3839

3940
const ROWS_PER_PAGE = 10;
@@ -86,14 +87,24 @@ const Home: React.FC = () => {
8687
// Fetch data when username, tab, or page changes
8788
useEffect(() => {
8889
if (username) {
89-
fetchData(username, page + 1, ROWS_PER_PAGE);
90+
const { startDate, endDate } = get30DayWindow();
91+
const apiFilters = {
92+
startDate: startDate,
93+
endDate: endDate,
94+
};
95+
fetchData(username, page + 1, ROWS_PER_PAGE, 'both', apiFilters);
9096
}
91-
}, [tab, page]);
97+
}, [tab, page, username]);
9298

9399
const handleSubmit = (e: React.FormEvent<HTMLFormElement>): void => {
94100
e.preventDefault();
95101
setPage(0);
96-
fetchData(username, 1, ROWS_PER_PAGE);
102+
const { startDate, endDate } = get30DayWindow();
103+
const apiFilters = {
104+
startDate: startDate,
105+
endDate: endDate,
106+
};
107+
fetchData(username, 1, ROWS_PER_PAGE, 'both', apiFilters);
97108
};
98109

99110
const handlePageChange = (_: unknown, newPage: number) => {
@@ -334,9 +345,9 @@ const Home: React.FC = () => {
334345
</Alert>
335346
)}
336347

337-
{/* Activity Reminder - Show when data is loaded and user is authenticated */}
338-
{username && !loading && (issues.length > 0 || prs.length > 0) && (
339-
<ActivityReminder activity={activity} username={username} />
348+
{/* Activity Reminder - Show when user is authenticated and data is loaded */}
349+
{username && !loading && (
350+
<ActivityReminder activity={activity} />
340351
)}
341352

342353
{loading ? (

src/utils/dateUtils.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Get the date range for the last 30 days
3+
* Returns dates in YYYY-MM-DD format suitable for GitHub API queries
4+
*/
5+
export const get30DayWindow = (): { startDate: string; endDate: string } => {
6+
const today = new Date();
7+
const thirtyDaysAgo = new Date(today);
8+
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
9+
10+
const formatDate = (date: Date): string => {
11+
const year = date.getFullYear();
12+
const month = String(date.getMonth() + 1).padStart(2, '0');
13+
const day = String(date.getDate()).padStart(2, '0');
14+
return `${year}-${month}-${day}`;
15+
};
16+
17+
return {
18+
startDate: formatDate(thirtyDaysAgo),
19+
endDate: formatDate(today),
20+
};
21+
};

0 commit comments

Comments
 (0)