Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore:history rewrite to use conventional commits and misc fixups #24

Closed
wants to merge 0 commits into from

Conversation

0xbrayo
Copy link
Member

@0xbrayo 0xbrayo commented Feb 7, 2025

Important

This pull request implements a leaderboard feature for ActivityWatch using Firebase, including backend functions, Firestore rules, and Vue components for user interface and state management.

  • Firebase Functions:
    • Added onUserCreated and onUserDeleted functions in index.ts to manage user lifecycle events.
    • Implemented getApiKey and rotateApiKey callable functions for API key management.
    • Added updateLeaderboardData scheduled function to update leaderboard daily.
    • Implemented uploadData and onUploadData functions for data storage and processing.
  • Firestore Rules and Indexes:
    • Updated Firestore rules in firestore.rules to manage access to screentime, leaderboard, and users collections.
    • Added Firestore indexes in firestore.indexes.json for optimized queries.
  • Vue Components:
    • Added Apikey.vue, Dashboard.vue, Leaderboard.vue, and PieChart.vue for UI enhancements.
    • Updated Header.vue and Footer.vue for improved navigation and layout.
  • State Management:
    • Introduced Pinia stores in apikey.ts, auth.ts, leaderboard.ts, and screentime.ts for state management.
  • Configuration and Setup:
    • Updated .eslintrc.cjs, .prettierrc.json, and package.json for linting and formatting.
    • Configured GitHub Actions in test.yml for CI/CD.
    • Updated firebase.json for Firebase hosting and emulators.

This description was created by Ellipsis for 9a90a16. It will automatically update as commits are pushed.

Copy link

github-actions bot commented Feb 7, 2025

Visit the preview URL for this PR (updated for commit 9a90a16):

https://aw-leaderboard--pr24-dev-history-cleanup-7jlen7i1.web.app

(expires Fri, 14 Feb 2025 08:44:40 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: c41748b80c8db8604c9c431c363ccab703d858c1

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Changes requested. Reviewed everything up to 9a90a16 in 2 minutes and 45 seconds

More details
  • Looked at 2272 lines of code in 55 files
  • Skipped 4 files when reviewing.
  • Skipped posting 7 drafted comments based on config settings.
1. src/firebase/data.ts:36
  • Draft comment:
    This function is identical to the existing implementation. Consider importing and reusing the existing function instead of duplicating the code.

  • function dataToSummary (index.ts)

  • Reason this comment was not posted:
    Marked as duplicate.

2. src/stores/screentime.ts:15
  • Draft comment:
    Potential runtime risk: Directly using 'useAuthStore().user!.uid' assumes the user is not null. In a scenario where the user is not yet authenticated, this could lead to an error. Consider adding null checks.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50%
    The ! operator is an explicit developer choice indicating they're certain user won't be null. The store is likely only used in authenticated contexts. The watch handler suggests this is handled intentionally. Without seeing the auth store implementation or usage patterns, we can't be certain this is actually a problem.
    I might be missing authentication initialization patterns that could lead to this store being accessed before auth is ready. The ! operator doesn't guarantee runtime safety.
    However, this appears to be a deliberate design choice with logout handling in place. Without strong evidence of an actual issue, this comment is too speculative.
    Delete the comment as it's speculative without strong evidence of an actual issue, and the code shows intentional handling of the auth state.
3. functions/src/index.ts:73
  • Draft comment:
    In the rotateApiKey function, the else branch sets a new API key but then returns doc.data()?.apiKey, which is still the old (or undefined) value. This likely does not return the newly generated key.
  • Reason this comment was not posted:
    Marked as duplicate.
4. functions/src/index.ts:216
  • Draft comment:
    Variable shadowing in the onUploadData function: the 'events' variable from the outer scope is re-declared inside the then-callback, causing an in-place push on itself. This appears unintended and should use a different name for the fetched events (e.g. 'existingEvents').
  • Reason this comment was not posted:
    Marked as duplicate.
5. functions/firebase/data.ts:54
  • Draft comment:
    The addScreenTimeData function has its userId parameter typed as a number, whereas elsewhere (and in the ScreenTimeData interface) the userId is a string. This inconsistency could lead to subtle bugs. Consider changing the type to string.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
6. functions/firebase/data.ts:129
  • Draft comment:
    The getLeaderboard function uses 'startAfter(offset)' with an offset calculated as a number. Firestore queries typically require a document snapshot or field value matching the orderBy clause. Verify that this pagination approach works as intended or consider using the proper offset method.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
7. src/stores/screentime.ts:15
  • Draft comment:
    The store immediately accesses 'useAuthStore().user!.uid' to obtain the userId. This assumes a logged-in user is always present, which may not hold true (e.g. during logout). Consider adding a check or making userId reactive.
  • Reason this comment was not posted:
    Marked as duplicate.

Workflow ID: wflow_E7GPVLSfKxCOkjsV


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

info("Data processed successfully")
})

function dataToSummary(data: ScreenTimeData): ScreenTimeSummary {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is an exact duplicate of the existing implementation.

} else {
await docref.set({apiKey: genKey.generateApiKey()})
info("ApiKey set and sent to client")
return {apiKey: doc.data()?.apiKey}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential issue in the else branch of rotateApiKey: after calling set() to create a new API key, the function returns doc.data()?.apiKey which may be undefined. It should fetch the newly set data (or directly return the generated key).

.get()
.then((doc) => {
if (doc.exists) {
const events = doc.data()?.events as Event[]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable shadowing issue: The local variable 'events' is re-declared inside the promise chain when updating documents. This may lead to unintended behavior when merging event arrays.

collection(db, "leaderboard"),
orderBy('rank'),
limit(50),
startAfter(offset)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Firestore pagination concern: Using 'startAfter(offset)' with a numeric offset is not standard, as startAfter expects a document snapshot or field values. Consider using cursor-based pagination.

const { fetchLeaderboardData, leaderboardData } = useLeaderboardStore()
fetchLeaderboardData()
const leaderboardDataRef: ComputedRef = computed(() => leaderboardData)
leaderboardDataRef.value.sort((a: { total: number }, b: { total: number }) => b.total - a.total)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorting the reactive computed value in place may mutate state unexpectedly. It is safer to sort a copy of the array (e.g. using slice()) before assigning it to entries.

@0xbrayo 0xbrayo closed this Feb 7, 2025
@0xbrayo 0xbrayo force-pushed the dev/history-cleanup branch from 9a90a16 to 666de93 Compare February 7, 2025 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant