Skip to content

feat: gyroscope test#127

Merged
hmbanan666 merged 1 commit intomainfrom
gyroscope
Sep 3, 2025
Merged

feat: gyroscope test#127
hmbanan666 merged 1 commit intomainfrom
gyroscope

Conversation

@hmbanan666
Copy link
Copy Markdown
Collaborator

@hmbanan666 hmbanan666 commented Sep 3, 2025

Summary by CodeRabbit

  • New Features

    • Enabled device gyroscope to power real-time motion effects on the User Points card.
  • Style

    • Added an inverted text utility for improved contrast; applied to the cashback label.
    • Adjusted heart image opacity and refreshed badge styling on the User Points card.
    • Refined category chips in the catalog slider: smaller text, fully rounded shape, reduced padding.
    • Updated User page buttons to a lighter “ghost” appearance for a cleaner look.

@hmbanan666 hmbanan666 self-assigned this Sep 3, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Sep 3, 2025

Walkthrough

Introduces gyroscope-driven UI behavior by starting the sensor during app init and subscribing in UserPointsCard to update transforms. Adjusts styles in multiple components, including button variants, category pill sizing, and a new CSS utility (.tg-text-inverted). Minor visual tweaks to the card’s elements and badges.

Changes

Cohort / File(s) Summary of changes
Gyroscope integration
apps/storefront-telegram/app/utils/init.ts, apps/storefront-telegram/app/components/UserPointsCard.vue
Starts gyroscope via postEvent with refresh_rate: 50. UserPointsCard subscribes to gyroscope_changed, maintains x/y/z refs, updates transforms, shows debug values, and cleans up on unmount. Removes parallax usage and switches to SDK on/off event handlers.
UI styling updates
apps/storefront-telegram/app/components/catalog/CategoriesSliderMenu.vue, apps/storefront-telegram/app/pages/user.vue, apps/storefront-telegram/app/assets/css/styles.css
Category pills become text-sm and rounded-full; button variants change to ghost; adds .tg-text-inverted utility (color: var(--tg-theme-bg-color)); minor card style tweaks (opacity, badge shape, text class usage).

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant UA as User Agent (WebApp)
    participant App as App Init
    participant TG as Telegram SDK
    participant Comp as UserPointsCard

    UA->>App: load/init()
    App->>TG: postEvent(start_gyroscope, {refresh_rate:50})
    note right of TG: Gyroscope activated

    UA->>Comp: mount()
    Comp->>TG: on('gyroscope_changed', handler)
    TG-->>Comp: gyroscope_changed {x,y,z} (stream)
    Comp->>Comp: update refs x,y,z
    Comp->>Comp: apply transforms (translate/rotate)

    UA->>Comp: unmount()
    Comp->>TG: off('gyroscope_changed', handler)
    note over Comp,TG: Subscription cleaned up
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I twitch my ears at rolling skies,
A gyro hum beneath my eyes—
I hop, I tilt, the UI glides,
New rounded pills for smoother rides.
Inverted text, a midnight grin—
Buttons ghostly, sleek and thin.
Thump-thump: ship it. Let’s begin! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch gyroscope

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Sep 3, 2025

@hmbanan666 hmbanan666 merged commit a12ee4e into main Sep 3, 2025
7 of 8 checks passed
@hmbanan666 hmbanan666 deleted the gyroscope branch September 3, 2025 12:45
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (7)
apps/storefront-telegram/app/components/catalog/CategoriesSliderMenu.vue (1)

9-13: Keep touch targets accessible after shrinking padding

The reduced padding risks dropping below the recommended 44×44 px touch area. Consider enforcing a minimum height/width on the button for a11y.

Example tweak:

-          <button class="px-2.5 py-1" @click="scrollToCategory(category.slug)">
+          <button class="h-11 min-w-[44px] px-3 py-1" @click="scrollToCategory(category.slug)">
apps/storefront-telegram/app/assets/css/styles.css (1)

70-72: Clarify “inverted” semantics and verify contrast across themes

.tg-text-inverted maps text to --tg-theme-bg-color. Depending on the surrounding bg (e.g., section vs primary), this can reduce contrast (e.g., white on white in light themes). Consider more semantic tokens (e.g., tg-text-on-primary, tg-text-on-section) or ensure usage only where contrast is guaranteed.

Please verify in both light/dark Telegram themes that elements using tg-text-inverted meet acceptable contrast.

apps/storefront-telegram/app/components/UserPointsCard.vue (5)

2-3: Hide debug telemetry in production

Render the x/y/z readout only in dev, or remove it.

-  {{ x }} / {{ y }} / {{ z }}
+  <div v-if="import.meta.env.DEV" class="text-xs opacity-60">{{ x }} / {{ y }} / {{ z }}</div>

5-11: Add will-change and clamp/smooth rotations to reduce jitter

At 50 Hz updates, transforms can look jittery. Add will-change for GPU hint and clamp rotation to a safe range.

-    <div
-      class="absolute inset-0 bg-primary rounded-lg"
+    <div
+      class="absolute inset-0 bg-primary rounded-lg will-change-transform"
       :style="{
-        transform: `rotateX(${x * 6}deg) rotateY(${y * 6}deg)`,
+        transform: `rotateX(${fx}deg) rotateY(${fy}deg)`,
       }"
     />

Additions outside this hunk (script):

// simple clamp + low-pass
const clamp = (v: number, min: number, max: number) => Math.min(max, Math.max(min, v))
const fx = ref(0), fy = ref(0)
let raf = 0
watchEffect(() => {
  cancelAnimationFrame(raf)
  raf = requestAnimationFrame(() => {
    // low-pass filter toward target with damping
    fx.value = clamp(fx.value + (x.value * 6 - fx.value) * 0.15, -20, 20)
    fy.value = clamp(fy.value + (y.value * 6 - fy.value) * 0.15, -20, 20)
  })
})
onUnmounted(() => cancelAnimationFrame(raf))

12-17: Mirror the perf tweaks on the foreground layer

Apply the same will-change + filtered rotations here for consistency.

-    <div
-      class="z-10 w-full h-full p-4 flex flex-col justify-between tg-text-button"
+    <div
+      class="z-10 w-full h-full p-4 flex flex-col justify-between tg-text-button will-change-transform"
       :style="{
-        transform: `rotateX(${x * 4}deg) rotateY(${y * 4}deg)`,
+        transform: `rotateX(${(fx/6)*4}deg) rotateY(${(fy/6)*4}deg)`,
       }"

40-47: Check text color choice relative to background

The label uses tg-text-inverted while the container text is already tg-text-button (likely white). Make sure the intent is to override, not duplicate, and that contrast stays OK on all themes.


59-61: Remove unused parallax ref

target isn’t used anymore; drop the ref and the commented parallax. Also remove ref="target" from the template root div.

-const target = useTemplateRef<HTMLElement>('target')
-// const parallax = reactive(useParallax(target))
+// removed unused parallax/target
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 6ddf549 and 254daa2.

📒 Files selected for processing (5)
  • apps/storefront-telegram/app/assets/css/styles.css (1 hunks)
  • apps/storefront-telegram/app/components/UserPointsCard.vue (3 hunks)
  • apps/storefront-telegram/app/components/catalog/CategoriesSliderMenu.vue (1 hunks)
  • apps/storefront-telegram/app/pages/user.vue (1 hunks)
  • apps/storefront-telegram/app/utils/init.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (3)
apps/storefront-telegram/app/pages/user.vue (1)

16-27: LGTM on visual tweak

Both actions use the same “ghost” variant now; consistent and simpler.

apps/storefront-telegram/app/components/UserPointsCard.vue (2)

34-35: Verify non-standard utility classes

opacity-35 and invert-100 aren’t default Tailwind utilities. If they rely on custom config, all good—otherwise they won’t render.

You can confirm via your tailwind.config.* utilities list. If not present, switch to supported values (e.g., opacity-30/40 and invert).


72-78: Start/stop gyroscope on mount/unmount

Confine sensor usage to when UserPointsCard is present (and remove global start in init.ts).

 onMounted(() => {
-  on('gyroscope_changed', listener)
+  postEvent('web_app_start_gyroscope', { refresh_rate: 50 })
+  on('gyroscope_changed', listener)
 })

 onUnmounted(() => {
   off('gyroscope_changed', listener)
+  postEvent('web_app_stop_gyroscope')
 })

Comment on lines +56 to 58
import type { EventListener } from '@telegram-apps/sdk-vue'
import { off, on } from '@telegram-apps/sdk-vue'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Import postEvent to lifecycle-manage the gyroscope here

Bring postEvent into this component so it can start/stop the sensor with its own lifecycle.

-import { off, on } from '@telegram-apps/sdk-vue'
+import { off, on, postEvent } from '@telegram-apps/sdk-vue'
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import type { EventListener } from '@telegram-apps/sdk-vue'
import { off, on } from '@telegram-apps/sdk-vue'
import type { EventListener } from '@telegram-apps/sdk-vue'
import { off, on, postEvent } from '@telegram-apps/sdk-vue'
🤖 Prompt for AI Agents
In apps/storefront-telegram/app/components/UserPointsCard.vue around lines 56 to
58, import postEvent from '@telegram-apps/sdk-vue' alongside EventListener and
on/off, and use it in this component's lifecycle to start and stop the
gyroscope: call postEvent('gyroscope', { action: 'start' }) when the component
mounts (or becomes active) and postEvent('gyroscope', { action: 'stop' }) when
it unmounts (or becomes inactive), ensuring the sensor is started/stopped by
this component's lifecycle.

Comment on lines +93 to +97
// Gyroscope
postEvent('web_app_start_gyroscope', {
refresh_rate: 50,
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Start/stop gyroscope where it’s actually used; avoid app-wide always-on sensor

Starting the gyroscope at init keeps the sensor running for the entire session, even when no component needs it. This is a battery/CPU hit and complicates future conditional usage. Start it in the component that consumes it (UserPointsCard) on mount and stop it on unmount; remove the global start here.

Apply this diff to remove the global start:

-  // Gyroscope
-  postEvent('web_app_start_gyroscope', {
-    refresh_rate: 50,
-  })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Gyroscope
postEvent('web_app_start_gyroscope', {
refresh_rate: 50,
})
🤖 Prompt for AI Agents
In apps/storefront-telegram/app/utils/init.ts around lines 93–97, remove the
global postEvent call that starts the gyroscope so the sensor isn't kept running
app-wide; instead, start the gyroscope in the consuming component
(UserPointsCard) on mount by calling postEvent('web_app_start_gyroscope', {
refresh_rate: 50 }) and stop it on unmount by calling
postEvent('web_app_stop_gyroscope') (or equivalent), ensuring the start/stop
calls use the same payload/semantics and that the init.ts no longer contains the
global gyroscope start.

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