-
Notifications
You must be signed in to change notification settings - Fork 0
test vibrate 1 #34
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
base: main
Are you sure you want to change the base?
test vibrate 1 #34
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,9 +25,22 @@ export const useCampanadasTimer = ({ offsetTime }: UseCampanadasTimerProps) => { | |
| const [chimeCount, setChimeCount] = useState(0); | ||
| const [timeDiff, setTimeDiff] = useState(0); | ||
|
|
||
| const vibrarTelefono = (pattern) => { | ||
| console.log("Vibrando", pattern); | ||
| if ("vibrate" in navigator) { | ||
| // Intentar vibrar 500ms | ||
| const exito = navigator.vibrate(pattern); | ||
| if (!exito) { | ||
| console.log("La vibración fue bloqueada o no es compatible."); | ||
| } | ||
| } else { | ||
| console.log("Tu navegador no soporta la API de vibración."); | ||
| } | ||
| }; | ||
|
|
||
|
Comment on lines
+28
to
+40
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major 🧩 Analysis chain🏁 Script executed: # First, let's locate and examine the file
find . -type f -name "useCampanadasTimer.ts" | head -5Repository: emaza/campanadas Length of output: 89 🏁 Script executed: # Let's also search for VibratePattern type in the codebase
rg "VibratePattern" --type tsRepository: emaza/campanadas Length of output: 42 🏁 Script executed: # Check how vibrarTelefono is used/called in the file
rg "vibrarTelefono" --type ts -B 2 -A 2Repository: emaza/campanadas Length of output: 2646 🌐 Web query:
💡 Result: Summary — navigator.vibrate() (MDN)
Sources
🏁 Script executed: # Get the full context of useCampanadasTimer.ts
wc -l ./hooks/useCampanadasTimer.tsRepository: emaza/campanadas Length of output: 92 🏁 Script executed: # Read the file to see the complete implementation
cat -n ./hooks/useCampanadasTimer.ts | head -50Repository: emaza/campanadas Length of output: 1810 🏁 Script executed: # Check if there are any lint configs or console rules
find . -type f -name ".eslintrc*" -o -name "eslint.config.*" -o -name "lint.config.*" | head -5Repository: emaza/campanadas Length of output: 42 🏁 Script executed: # Check if console is being used elsewhere and how it's handled
rg "console\.(log|warn|error)" --type ts --stats | head -20Repository: emaza/campanadas Length of output: 1013 Extract to a shared utility, add proper types and browser/environment guards, and remove console logs. This function is duplicated identically in three files (App.tsx, useCampanadasTimer.ts, useAudioController.ts) and should be consolidated into a shared hook or utility. Additionally, the Suggested improvementsCreate a shared hook (e.g., +export const useVibration = () => {
+ const vibrate = (pattern: number | number[] = [200, 200]): boolean => {
+ if (typeof navigator === 'undefined' || typeof navigator.vibrate !== 'function') {
+ return false;
+ }
+ return navigator.vibrate(pattern);
+ };
+
+ return { vibrate };
+};Then import and use in all three files: - const vibrarTelefono = (pattern) => {
- console.log("Vibrando", pattern);
- if ("vibrate" in navigator) {
- const exito = navigator.vibrate(pattern);
- if (!exito) {
- console.log("La vibración fue bloqueada o no es compatible.");
- }
- } else {
- console.log("Tu navegador no soporta la API de vibración.");
- }
- };
+ const { vibrate } = useVibration();Note:
|
||
| useEffect(() => { | ||
| let animationFrameId: number; | ||
|
|
||
| vibrarTelefono([300, 300]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: Short answer
Key points / security rationale
Browser behaviour notes
References
If you want, I can fetch exact browser-version behavior (which versions enforce the rule, iframe specifics, and example detection code). 🏁 Script executed: # Find and read the useCampanadasTimer.ts file to understand context
fd -t f "useCampanadasTimer.ts" --exec cat -n {}Repository: emaza/campanadas Length of output: 3688 Move vibration calls outside of useEffect initialization to user-initiated events. The Vibration API requires user activation (a sticky gesture like click or tap) to function in modern browsers (Chrome, Firefox, Opera, Samsung). Calling The current defensive logging catches this silently, but the vibration won't work. Move vibration triggers to event handlers or other user-initiated actions instead. 🤖 Prompt for AI Agents |
||
| const updateTime = () => { | ||
| const now = Date.now() + offsetTime; | ||
| const visualDate = new Date(now); | ||
|
|
@@ -68,7 +81,7 @@ export const useCampanadasTimer = ({ offsetTime }: UseCampanadasTimerProps) => { | |
| const currentChimeIndex = Math.floor(msSinceMidnight / CHIME_INTERVAL); | ||
| setChimeCount(currentChimeIndex + 1); | ||
| } else if (currentPhase !== AppPhase.CELEBRATION) { | ||
| if (currentPhase === AppPhase.COUNTDOWN) { | ||
| if (currentPhase === AppPhase.COUNTDOWN) { | ||
| setChimeCount(0); | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Extract duplicated function to a shared utility module and add TypeScript types.
This function is duplicated across at least three files (App.tsx, useCampanadasTimer.ts, and useAudioController.ts per the AI summary). Consider extracting it to a shared utility module (e.g.,
utils/vibration.ts) with proper TypeScript typing:Then import and use it across all three files.
🤖 Prompt for AI Agents